@databricks/sdk-genie 0.0.0-dev → 0.1.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1319 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import type {Call} from '@databricks/sdk-core/api';
5
+ import {retryOn} from '@databricks/sdk-core/api';
6
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
7
+ import type {Logger} from '@databricks/sdk-core/logger';
8
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
9
+ import type {CallOptions} from '@databricks/sdk-options/call';
10
+ import type {ClientOptions} from '@databricks/sdk-options/client';
11
+ import type {HttpClient} from '@databricks/sdk-core/http';
12
+ import {newHttpClient} from './transport';
13
+ import {
14
+ buildHttpRequest,
15
+ executeCall,
16
+ executeHttpCall,
17
+ marshalRequest,
18
+ parseResponse,
19
+ } from './utils';
20
+ import pkgJson from '../../package.json' with {type: 'json'};
21
+ import type {
22
+ GenieCreateConversationMessageRequest,
23
+ GenieCreateEvalRunRequest,
24
+ GenieCreateMessageCommentRequest,
25
+ GenieCreateSpaceRequest,
26
+ GenieDeleteConversationMessageRequest,
27
+ GenieDeleteConversationRequest,
28
+ GenieEvalResultDetails,
29
+ GenieEvalRunResponse,
30
+ GenieExecuteMessageAttachmentQueryRequest,
31
+ GenieExecuteMessageQueryRequest,
32
+ GenieGenerateDownloadFullQueryResultRequest,
33
+ GenieGenerateDownloadFullQueryResultResponse,
34
+ GenieGetConversationMessageRequest,
35
+ GenieGetDownloadFullQueryResultRequest,
36
+ GenieGetDownloadFullQueryResultResponse,
37
+ GenieGetEvalResultDetailsRequest,
38
+ GenieGetEvalRunRequest,
39
+ GenieGetMessageAttachmentQueryResultRequest,
40
+ GenieGetMessageQueryResultRequest,
41
+ GenieGetMessageQueryResultResponse,
42
+ GenieGetQueryResultByAttachmentRequest,
43
+ GenieGetSpaceRequest,
44
+ GenieListConversationCommentsRequest,
45
+ GenieListConversationCommentsResponse,
46
+ GenieListConversationMessagesRequest,
47
+ GenieListConversationMessagesResponse,
48
+ GenieListConversationsRequest,
49
+ GenieListConversationsResponse,
50
+ GenieListEvalResultsRequest,
51
+ GenieListEvalResultsResponse,
52
+ GenieListEvalRunsRequest,
53
+ GenieListEvalRunsResponse,
54
+ GenieListMessageCommentsRequest,
55
+ GenieListMessageCommentsResponse,
56
+ GenieListSpacesRequest,
57
+ GenieListSpacesResponse,
58
+ GenieMessage,
59
+ GenieMessageComment,
60
+ GenieSendMessageFeedbackRequest,
61
+ GenieSpace,
62
+ GenieStartConversationMessageRequest,
63
+ GenieStartConversationResponse,
64
+ GenieTrashSpaceRequest,
65
+ GenieUpdateSpaceRequest,
66
+ } from './model';
67
+ import {
68
+ MessageStatus_MessageStatus,
69
+ marshalGenieCreateConversationMessageRequestSchema,
70
+ marshalGenieCreateEvalRunRequestSchema,
71
+ marshalGenieCreateMessageCommentRequestSchema,
72
+ marshalGenieCreateSpaceRequestSchema,
73
+ marshalGenieExecuteMessageAttachmentQueryRequestSchema,
74
+ marshalGenieExecuteMessageQueryRequestSchema,
75
+ marshalGenieGenerateDownloadFullQueryResultRequestSchema,
76
+ marshalGenieSendMessageFeedbackRequestSchema,
77
+ marshalGenieStartConversationMessageRequestSchema,
78
+ marshalGenieUpdateSpaceRequestSchema,
79
+ unmarshalGenieEvalResultDetailsSchema,
80
+ unmarshalGenieEvalRunResponseSchema,
81
+ unmarshalGenieGenerateDownloadFullQueryResultResponseSchema,
82
+ unmarshalGenieGetDownloadFullQueryResultResponseSchema,
83
+ unmarshalGenieGetMessageQueryResultResponseSchema,
84
+ unmarshalGenieListConversationCommentsResponseSchema,
85
+ unmarshalGenieListConversationMessagesResponseSchema,
86
+ unmarshalGenieListConversationsResponseSchema,
87
+ unmarshalGenieListEvalResultsResponseSchema,
88
+ unmarshalGenieListEvalRunsResponseSchema,
89
+ unmarshalGenieListMessageCommentsResponseSchema,
90
+ unmarshalGenieListSpacesResponseSchema,
91
+ unmarshalGenieMessageCommentSchema,
92
+ unmarshalGenieMessageSchema,
93
+ unmarshalGenieSpaceSchema,
94
+ unmarshalGenieStartConversationResponseSchema,
95
+ } from './model';
96
+
97
+ // Package identity segment for this client to be used in the User-Agent header.
98
+ const PACKAGE_SEGMENT = {
99
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
100
+ value: pkgJson.version,
101
+ };
102
+
103
+ class StillRunningError extends Error {}
104
+
105
+ export class Client {
106
+ private readonly host: string;
107
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
108
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
109
+ // request.
110
+ private readonly workspaceId: string | undefined;
111
+ private readonly httpClient: HttpClient;
112
+ private readonly logger: Logger;
113
+ // User-Agent header value. Composed once at construction from
114
+ // createDefault() merged with this package's identity and the active
115
+ // credential's name.
116
+ private readonly userAgent: string;
117
+
118
+ constructor(options: ClientOptions) {
119
+ if (options.host === undefined) {
120
+ throw new Error('Host is required.');
121
+ }
122
+ this.host = options.host.replace(/\/$/, '');
123
+ this.workspaceId = options.workspaceId;
124
+ this.logger = options.logger ?? new NoOpLogger();
125
+ let info = createDefault().with(PACKAGE_SEGMENT);
126
+ if (options.credentials !== undefined) {
127
+ info = info
128
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
129
+ .with({key: 'auth', value: options.credentials.name()});
130
+ }
131
+ this.userAgent = info.toString();
132
+ this.httpClient = newHttpClient(options);
133
+ }
134
+
135
+ /** Creates a Genie space from a serialized payload. */
136
+ async createSpace(
137
+ req: GenieCreateSpaceRequest,
138
+ options?: CallOptions
139
+ ): Promise<GenieSpace> {
140
+ const url = `${this.host}/api/2.0/genie/spaces`;
141
+ const body = marshalRequest(req, marshalGenieCreateSpaceRequestSchema);
142
+ let resp: GenieSpace | undefined;
143
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
144
+ const headers = new Headers({'Content-Type': 'application/json'});
145
+ if (this.workspaceId !== undefined) {
146
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
147
+ }
148
+ headers.set('User-Agent', this.userAgent);
149
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
150
+ const respBody = await executeHttpCall({
151
+ request: httpReq,
152
+ httpClient: this.httpClient,
153
+ logger: this.logger,
154
+ });
155
+ resp = parseResponse(respBody, unmarshalGenieSpaceSchema);
156
+ };
157
+ await executeCall(call, options);
158
+ if (resp === undefined) {
159
+ throw new Error('API call completed without a result.');
160
+ }
161
+ return resp;
162
+ }
163
+
164
+ /**
165
+ * Create new message in a [conversation](:method:genie/startconversation).
166
+ * The AI response uses all previously created messages in the conversation to respond.
167
+ */
168
+ async genieCreateConversationMessage(
169
+ req: GenieCreateConversationMessageRequest,
170
+ options?: CallOptions
171
+ ): Promise<GenieMessage> {
172
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages`;
173
+ const body = marshalRequest(
174
+ req,
175
+ marshalGenieCreateConversationMessageRequestSchema
176
+ );
177
+ let resp: GenieMessage | undefined;
178
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
179
+ const headers = new Headers({'Content-Type': 'application/json'});
180
+ if (this.workspaceId !== undefined) {
181
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
182
+ }
183
+ headers.set('User-Agent', this.userAgent);
184
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
185
+ const respBody = await executeHttpCall({
186
+ request: httpReq,
187
+ httpClient: this.httpClient,
188
+ logger: this.logger,
189
+ });
190
+ resp = parseResponse(respBody, unmarshalGenieMessageSchema);
191
+ };
192
+ await executeCall(call, options);
193
+ if (resp === undefined) {
194
+ throw new Error('API call completed without a result.');
195
+ }
196
+ return resp;
197
+ }
198
+
199
+ async genieCreateConversationMessageWaiter(
200
+ req: GenieCreateConversationMessageRequest,
201
+ options?: CallOptions
202
+ ): Promise<GenieCreateConversationMessageWaiter> {
203
+ const resp = await this.genieCreateConversationMessage(req, options);
204
+ if (resp.messageId === undefined) {
205
+ throw new Error(
206
+ 'response field messageId required for polling is missing'
207
+ );
208
+ }
209
+ if (req.conversationId === undefined) {
210
+ throw new Error(
211
+ 'request field conversationId required for polling is missing'
212
+ );
213
+ }
214
+ if (req.spaceId === undefined) {
215
+ throw new Error('request field spaceId required for polling is missing');
216
+ }
217
+ return new GenieCreateConversationMessageWaiter(
218
+ this,
219
+ resp.messageId,
220
+ req.conversationId,
221
+ req.spaceId
222
+ );
223
+ }
224
+
225
+ /** Create and run evaluations for multiple benchmark questions in a Genie space. */
226
+ async genieCreateEvalRun(
227
+ req: GenieCreateEvalRunRequest,
228
+ options?: CallOptions
229
+ ): Promise<GenieEvalRunResponse> {
230
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs`;
231
+ const body = marshalRequest(req, marshalGenieCreateEvalRunRequestSchema);
232
+ let resp: GenieEvalRunResponse | undefined;
233
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
234
+ const headers = new Headers({'Content-Type': 'application/json'});
235
+ if (this.workspaceId !== undefined) {
236
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
237
+ }
238
+ headers.set('User-Agent', this.userAgent);
239
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
240
+ const respBody = await executeHttpCall({
241
+ request: httpReq,
242
+ httpClient: this.httpClient,
243
+ logger: this.logger,
244
+ });
245
+ resp = parseResponse(respBody, unmarshalGenieEvalRunResponseSchema);
246
+ };
247
+ await executeCall(call, options);
248
+ if (resp === undefined) {
249
+ throw new Error('API call completed without a result.');
250
+ }
251
+ return resp;
252
+ }
253
+
254
+ /** Create a comment on a conversation message. */
255
+ async genieCreateMessageComment(
256
+ req: GenieCreateMessageCommentRequest,
257
+ options?: CallOptions
258
+ ): Promise<GenieMessageComment> {
259
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/comments`;
260
+ const body = marshalRequest(
261
+ req,
262
+ marshalGenieCreateMessageCommentRequestSchema
263
+ );
264
+ let resp: GenieMessageComment | undefined;
265
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
266
+ const headers = new Headers({'Content-Type': 'application/json'});
267
+ if (this.workspaceId !== undefined) {
268
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
269
+ }
270
+ headers.set('User-Agent', this.userAgent);
271
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
272
+ const respBody = await executeHttpCall({
273
+ request: httpReq,
274
+ httpClient: this.httpClient,
275
+ logger: this.logger,
276
+ });
277
+ resp = parseResponse(respBody, unmarshalGenieMessageCommentSchema);
278
+ };
279
+ await executeCall(call, options);
280
+ if (resp === undefined) {
281
+ throw new Error('API call completed without a result.');
282
+ }
283
+ return resp;
284
+ }
285
+
286
+ /** Delete a conversation. */
287
+ async genieDeleteConversation(
288
+ req: GenieDeleteConversationRequest,
289
+ options?: CallOptions
290
+ ): Promise<void> {
291
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}`;
292
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
293
+ const headers = new Headers();
294
+ if (this.workspaceId !== undefined) {
295
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
296
+ }
297
+ headers.set('User-Agent', this.userAgent);
298
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
299
+ await executeHttpCall({
300
+ request: httpReq,
301
+ httpClient: this.httpClient,
302
+ logger: this.logger,
303
+ });
304
+ };
305
+ await executeCall(call, options);
306
+ }
307
+
308
+ /** Delete a conversation message. */
309
+ async genieDeleteConversationMessage(
310
+ req: GenieDeleteConversationMessageRequest,
311
+ options?: CallOptions
312
+ ): Promise<void> {
313
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}`;
314
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
315
+ const headers = new Headers();
316
+ if (this.workspaceId !== undefined) {
317
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
318
+ }
319
+ headers.set('User-Agent', this.userAgent);
320
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
321
+ await executeHttpCall({
322
+ request: httpReq,
323
+ httpClient: this.httpClient,
324
+ logger: this.logger,
325
+ });
326
+ };
327
+ await executeCall(call, options);
328
+ }
329
+
330
+ /** Execute the SQL for a message query attachment. Use this API when the query attachment has expired and needs to be re-executed. */
331
+ async genieExecuteMessageAttachmentQuery(
332
+ req: GenieExecuteMessageAttachmentQueryRequest,
333
+ options?: CallOptions
334
+ ): Promise<GenieGetMessageQueryResultResponse> {
335
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/execute-query`;
336
+ const body = marshalRequest(
337
+ req,
338
+ marshalGenieExecuteMessageAttachmentQueryRequestSchema
339
+ );
340
+ let resp: GenieGetMessageQueryResultResponse | undefined;
341
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
342
+ const headers = new Headers({'Content-Type': 'application/json'});
343
+ if (this.workspaceId !== undefined) {
344
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
345
+ }
346
+ headers.set('User-Agent', this.userAgent);
347
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
348
+ const respBody = await executeHttpCall({
349
+ request: httpReq,
350
+ httpClient: this.httpClient,
351
+ logger: this.logger,
352
+ });
353
+ resp = parseResponse(
354
+ respBody,
355
+ unmarshalGenieGetMessageQueryResultResponseSchema
356
+ );
357
+ };
358
+ await executeCall(call, options);
359
+ if (resp === undefined) {
360
+ throw new Error('API call completed without a result.');
361
+ }
362
+ return resp;
363
+ }
364
+
365
+ /** DEPRECATED: Use [Execute Message Attachment Query](:method:genie/executemessageattachmentquery) instead. */
366
+ async genieExecuteMessageQuery(
367
+ req: GenieExecuteMessageQueryRequest,
368
+ options?: CallOptions
369
+ ): Promise<GenieGetMessageQueryResultResponse> {
370
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/execute-query`;
371
+ const body = marshalRequest(
372
+ req,
373
+ marshalGenieExecuteMessageQueryRequestSchema
374
+ );
375
+ let resp: GenieGetMessageQueryResultResponse | undefined;
376
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
377
+ const headers = new Headers({'Content-Type': 'application/json'});
378
+ if (this.workspaceId !== undefined) {
379
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
380
+ }
381
+ headers.set('User-Agent', this.userAgent);
382
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
383
+ const respBody = await executeHttpCall({
384
+ request: httpReq,
385
+ httpClient: this.httpClient,
386
+ logger: this.logger,
387
+ });
388
+ resp = parseResponse(
389
+ respBody,
390
+ unmarshalGenieGetMessageQueryResultResponseSchema
391
+ );
392
+ };
393
+ await executeCall(call, options);
394
+ if (resp === undefined) {
395
+ throw new Error('API call completed without a result.');
396
+ }
397
+ return resp;
398
+ }
399
+
400
+ /**
401
+ * Initiates a new SQL execution and returns a `download_id` and `download_id_signature` that you can use to track the progress of the download.
402
+ * The query result is stored in an external link and can be retrieved using the [Get Download Full Query Result](:method:genie/getdownloadfullqueryresult) API.
403
+ * Both `download_id` and `download_id_signature` must be provided when calling the Get endpoint.
404
+ *
405
+ * ----
406
+ *
407
+ * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
408
+ *
409
+ * When you use the `EXTERNAL_LINKS` disposition, a
410
+ * short-lived, URL is generated, which can be
411
+ * used to download the results directly
412
+ * from . As a
413
+ * short-lived is
414
+ * embedded in this URL, you should protect
415
+ * the URL.
416
+ *
417
+ * Because URLs are already generated with
418
+ * embedded temporary s,
419
+ * you must not set an `Authorization` header in the download requests.
420
+ *
421
+ * See [Execute Statement](:method:statementexecution/executestatement) for more details.
422
+ *
423
+ * ----
424
+ */
425
+ async genieGenerateDownloadFullQueryResult(
426
+ req: GenieGenerateDownloadFullQueryResultRequest,
427
+ options?: CallOptions
428
+ ): Promise<GenieGenerateDownloadFullQueryResultResponse> {
429
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/downloads`;
430
+ const body = marshalRequest(
431
+ req,
432
+ marshalGenieGenerateDownloadFullQueryResultRequestSchema
433
+ );
434
+ let resp: GenieGenerateDownloadFullQueryResultResponse | undefined;
435
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
436
+ const headers = new Headers({'Content-Type': 'application/json'});
437
+ if (this.workspaceId !== undefined) {
438
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
439
+ }
440
+ headers.set('User-Agent', this.userAgent);
441
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
442
+ const respBody = await executeHttpCall({
443
+ request: httpReq,
444
+ httpClient: this.httpClient,
445
+ logger: this.logger,
446
+ });
447
+ resp = parseResponse(
448
+ respBody,
449
+ unmarshalGenieGenerateDownloadFullQueryResultResponseSchema
450
+ );
451
+ };
452
+ await executeCall(call, options);
453
+ if (resp === undefined) {
454
+ throw new Error('API call completed without a result.');
455
+ }
456
+ return resp;
457
+ }
458
+
459
+ /** Get message from conversation. */
460
+ async genieGetConversationMessage(
461
+ req: GenieGetConversationMessageRequest,
462
+ options?: CallOptions
463
+ ): Promise<GenieMessage> {
464
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}`;
465
+ let resp: GenieMessage | undefined;
466
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
467
+ const headers = new Headers();
468
+ if (this.workspaceId !== undefined) {
469
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
470
+ }
471
+ headers.set('User-Agent', this.userAgent);
472
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
473
+ const respBody = await executeHttpCall({
474
+ request: httpReq,
475
+ httpClient: this.httpClient,
476
+ logger: this.logger,
477
+ });
478
+ resp = parseResponse(respBody, unmarshalGenieMessageSchema);
479
+ };
480
+ await executeCall(call, options);
481
+ if (resp === undefined) {
482
+ throw new Error('API call completed without a result.');
483
+ }
484
+ return resp;
485
+ }
486
+
487
+ /**
488
+ * After [Generating a Full Query Result Download](:method:genie/generatedownloadfullqueryresult) and successfully receiving a `download_id` and `download_id_signature`, use this API to poll the download progress.
489
+ * Both `download_id` and `download_id_signature` are required to call this endpoint.
490
+ * When the download is complete, the API returns the result in the `EXTERNAL_LINKS` disposition, containing one or more external links to the query result files.
491
+ *
492
+ * ----
493
+ *
494
+ * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
495
+ *
496
+ * When you use the `EXTERNAL_LINKS` disposition, a
497
+ * short-lived, URL is generated, which can be
498
+ * used to download the results directly
499
+ * from . As a
500
+ * short-lived is
501
+ * embedded in this URL, you should protect
502
+ * the URL.
503
+ *
504
+ * Because URLs are already generated with
505
+ * embedded temporary s,
506
+ * you must not set an `Authorization` header in the download requests.
507
+ *
508
+ * See [Execute Statement](:method:statementexecution/executestatement) for more details.
509
+ *
510
+ * ----
511
+ */
512
+ async genieGetDownloadFullQueryResult(
513
+ req: GenieGetDownloadFullQueryResultRequest,
514
+ options?: CallOptions
515
+ ): Promise<GenieGetDownloadFullQueryResultResponse> {
516
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/downloads/${req.downloadId ?? ''}`;
517
+ const params = new URLSearchParams();
518
+ if (req.downloadIdSignature !== undefined) {
519
+ params.append('download_id_signature', req.downloadIdSignature);
520
+ }
521
+ const query = params.toString();
522
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
523
+ let resp: GenieGetDownloadFullQueryResultResponse | undefined;
524
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
525
+ const headers = new Headers();
526
+ if (this.workspaceId !== undefined) {
527
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
528
+ }
529
+ headers.set('User-Agent', this.userAgent);
530
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
531
+ const respBody = await executeHttpCall({
532
+ request: httpReq,
533
+ httpClient: this.httpClient,
534
+ logger: this.logger,
535
+ });
536
+ resp = parseResponse(
537
+ respBody,
538
+ unmarshalGenieGetDownloadFullQueryResultResponseSchema
539
+ );
540
+ };
541
+ await executeCall(call, options);
542
+ if (resp === undefined) {
543
+ throw new Error('API call completed without a result.');
544
+ }
545
+ return resp;
546
+ }
547
+
548
+ /** Get details for evaluation results. */
549
+ async genieGetEvalResultDetails(
550
+ req: GenieGetEvalResultDetailsRequest,
551
+ options?: CallOptions
552
+ ): Promise<GenieEvalResultDetails> {
553
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs/${req.evalRunId ?? ''}/results/${req.resultId ?? ''}`;
554
+ let resp: GenieEvalResultDetails | undefined;
555
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
556
+ const headers = new Headers();
557
+ if (this.workspaceId !== undefined) {
558
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
559
+ }
560
+ headers.set('User-Agent', this.userAgent);
561
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
562
+ const respBody = await executeHttpCall({
563
+ request: httpReq,
564
+ httpClient: this.httpClient,
565
+ logger: this.logger,
566
+ });
567
+ resp = parseResponse(respBody, unmarshalGenieEvalResultDetailsSchema);
568
+ };
569
+ await executeCall(call, options);
570
+ if (resp === undefined) {
571
+ throw new Error('API call completed without a result.');
572
+ }
573
+ return resp;
574
+ }
575
+
576
+ /** Get evaluation run details. */
577
+ async genieGetEvalRun(
578
+ req: GenieGetEvalRunRequest,
579
+ options?: CallOptions
580
+ ): Promise<GenieEvalRunResponse> {
581
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs/${req.evalRunId ?? ''}`;
582
+ let resp: GenieEvalRunResponse | undefined;
583
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
584
+ const headers = new Headers();
585
+ if (this.workspaceId !== undefined) {
586
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
587
+ }
588
+ headers.set('User-Agent', this.userAgent);
589
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
590
+ const respBody = await executeHttpCall({
591
+ request: httpReq,
592
+ httpClient: this.httpClient,
593
+ logger: this.logger,
594
+ });
595
+ resp = parseResponse(respBody, unmarshalGenieEvalRunResponseSchema);
596
+ };
597
+ await executeCall(call, options);
598
+ if (resp === undefined) {
599
+ throw new Error('API call completed without a result.');
600
+ }
601
+ return resp;
602
+ }
603
+
604
+ /**
605
+ * Get the result of SQL query if the message has a query attachment.
606
+ * This is only available if a message has a query attachment and the message status is `EXECUTING_QUERY` OR `COMPLETED`.
607
+ */
608
+ async genieGetMessageAttachmentQueryResult(
609
+ req: GenieGetMessageAttachmentQueryResultRequest,
610
+ options?: CallOptions
611
+ ): Promise<GenieGetMessageQueryResultResponse> {
612
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/query-result`;
613
+ let resp: GenieGetMessageQueryResultResponse | undefined;
614
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
615
+ const headers = new Headers();
616
+ if (this.workspaceId !== undefined) {
617
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
618
+ }
619
+ headers.set('User-Agent', this.userAgent);
620
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
621
+ const respBody = await executeHttpCall({
622
+ request: httpReq,
623
+ httpClient: this.httpClient,
624
+ logger: this.logger,
625
+ });
626
+ resp = parseResponse(
627
+ respBody,
628
+ unmarshalGenieGetMessageQueryResultResponseSchema
629
+ );
630
+ };
631
+ await executeCall(call, options);
632
+ if (resp === undefined) {
633
+ throw new Error('API call completed without a result.');
634
+ }
635
+ return resp;
636
+ }
637
+
638
+ /** DEPRECATED: Use [Get Message Attachment Query Result](:method:genie/getmessageattachmentqueryresult) instead. */
639
+ async genieGetMessageQueryResult(
640
+ req: GenieGetMessageQueryResultRequest,
641
+ options?: CallOptions
642
+ ): Promise<GenieGetMessageQueryResultResponse> {
643
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/query-result`;
644
+ let resp: GenieGetMessageQueryResultResponse | undefined;
645
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
646
+ const headers = new Headers();
647
+ if (this.workspaceId !== undefined) {
648
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
649
+ }
650
+ headers.set('User-Agent', this.userAgent);
651
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
652
+ const respBody = await executeHttpCall({
653
+ request: httpReq,
654
+ httpClient: this.httpClient,
655
+ logger: this.logger,
656
+ });
657
+ resp = parseResponse(
658
+ respBody,
659
+ unmarshalGenieGetMessageQueryResultResponseSchema
660
+ );
661
+ };
662
+ await executeCall(call, options);
663
+ if (resp === undefined) {
664
+ throw new Error('API call completed without a result.');
665
+ }
666
+ return resp;
667
+ }
668
+
669
+ /** DEPRECATED: Use [Get Message Attachment Query Result](:method:genie/getmessageattachmentqueryresult) instead. */
670
+ async genieGetQueryResultByAttachment(
671
+ req: GenieGetQueryResultByAttachmentRequest,
672
+ options?: CallOptions
673
+ ): Promise<GenieGetMessageQueryResultResponse> {
674
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/query-result/${req.attachmentId ?? ''}`;
675
+ let resp: GenieGetMessageQueryResultResponse | undefined;
676
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
677
+ const headers = new Headers();
678
+ if (this.workspaceId !== undefined) {
679
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
680
+ }
681
+ headers.set('User-Agent', this.userAgent);
682
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
683
+ const respBody = await executeHttpCall({
684
+ request: httpReq,
685
+ httpClient: this.httpClient,
686
+ logger: this.logger,
687
+ });
688
+ resp = parseResponse(
689
+ respBody,
690
+ unmarshalGenieGetMessageQueryResultResponseSchema
691
+ );
692
+ };
693
+ await executeCall(call, options);
694
+ if (resp === undefined) {
695
+ throw new Error('API call completed without a result.');
696
+ }
697
+ return resp;
698
+ }
699
+
700
+ /** Get details of a Genie Space. */
701
+ async genieGetSpace(
702
+ req: GenieGetSpaceRequest,
703
+ options?: CallOptions
704
+ ): Promise<GenieSpace> {
705
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}`;
706
+ const params = new URLSearchParams();
707
+ if (req.includeSerializedSpace !== undefined) {
708
+ params.append(
709
+ 'include_serialized_space',
710
+ String(req.includeSerializedSpace)
711
+ );
712
+ }
713
+ const query = params.toString();
714
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
715
+ let resp: GenieSpace | undefined;
716
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
717
+ const headers = new Headers();
718
+ if (this.workspaceId !== undefined) {
719
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
720
+ }
721
+ headers.set('User-Agent', this.userAgent);
722
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
723
+ const respBody = await executeHttpCall({
724
+ request: httpReq,
725
+ httpClient: this.httpClient,
726
+ logger: this.logger,
727
+ });
728
+ resp = parseResponse(respBody, unmarshalGenieSpaceSchema);
729
+ };
730
+ await executeCall(call, options);
731
+ if (resp === undefined) {
732
+ throw new Error('API call completed without a result.');
733
+ }
734
+ return resp;
735
+ }
736
+
737
+ /** List all comments across all messages in a conversation. */
738
+ async genieListConversationComments(
739
+ req: GenieListConversationCommentsRequest,
740
+ options?: CallOptions
741
+ ): Promise<GenieListConversationCommentsResponse> {
742
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/list-comments`;
743
+ const params = new URLSearchParams();
744
+ if (req.pageSize !== undefined) {
745
+ params.append('page_size', String(req.pageSize));
746
+ }
747
+ if (req.pageToken !== undefined) {
748
+ params.append('page_token', req.pageToken);
749
+ }
750
+ const query = params.toString();
751
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
752
+ let resp: GenieListConversationCommentsResponse | undefined;
753
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
754
+ const headers = new Headers();
755
+ if (this.workspaceId !== undefined) {
756
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
757
+ }
758
+ headers.set('User-Agent', this.userAgent);
759
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
760
+ const respBody = await executeHttpCall({
761
+ request: httpReq,
762
+ httpClient: this.httpClient,
763
+ logger: this.logger,
764
+ });
765
+ resp = parseResponse(
766
+ respBody,
767
+ unmarshalGenieListConversationCommentsResponseSchema
768
+ );
769
+ };
770
+ await executeCall(call, options);
771
+ if (resp === undefined) {
772
+ throw new Error('API call completed without a result.');
773
+ }
774
+ return resp;
775
+ }
776
+
777
+ /** List messages in a conversation */
778
+ async genieListConversationMessages(
779
+ req: GenieListConversationMessagesRequest,
780
+ options?: CallOptions
781
+ ): Promise<GenieListConversationMessagesResponse> {
782
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages`;
783
+ const params = new URLSearchParams();
784
+ if (req.pageSize !== undefined) {
785
+ params.append('page_size', String(req.pageSize));
786
+ }
787
+ if (req.pageToken !== undefined) {
788
+ params.append('page_token', req.pageToken);
789
+ }
790
+ const query = params.toString();
791
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
792
+ let resp: GenieListConversationMessagesResponse | undefined;
793
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
794
+ const headers = new Headers();
795
+ if (this.workspaceId !== undefined) {
796
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
797
+ }
798
+ headers.set('User-Agent', this.userAgent);
799
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
800
+ const respBody = await executeHttpCall({
801
+ request: httpReq,
802
+ httpClient: this.httpClient,
803
+ logger: this.logger,
804
+ });
805
+ resp = parseResponse(
806
+ respBody,
807
+ unmarshalGenieListConversationMessagesResponseSchema
808
+ );
809
+ };
810
+ await executeCall(call, options);
811
+ if (resp === undefined) {
812
+ throw new Error('API call completed without a result.');
813
+ }
814
+ return resp;
815
+ }
816
+
817
+ /** Get a list of conversations in a Genie Space. */
818
+ async genieListConversations(
819
+ req: GenieListConversationsRequest,
820
+ options?: CallOptions
821
+ ): Promise<GenieListConversationsResponse> {
822
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations`;
823
+ const params = new URLSearchParams();
824
+ if (req.pageSize !== undefined) {
825
+ params.append('page_size', String(req.pageSize));
826
+ }
827
+ if (req.pageToken !== undefined) {
828
+ params.append('page_token', req.pageToken);
829
+ }
830
+ if (req.includeAll !== undefined) {
831
+ params.append('include_all', String(req.includeAll));
832
+ }
833
+ const query = params.toString();
834
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
835
+ let resp: GenieListConversationsResponse | undefined;
836
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
837
+ const headers = new Headers();
838
+ if (this.workspaceId !== undefined) {
839
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
840
+ }
841
+ headers.set('User-Agent', this.userAgent);
842
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
843
+ const respBody = await executeHttpCall({
844
+ request: httpReq,
845
+ httpClient: this.httpClient,
846
+ logger: this.logger,
847
+ });
848
+ resp = parseResponse(
849
+ respBody,
850
+ unmarshalGenieListConversationsResponseSchema
851
+ );
852
+ };
853
+ await executeCall(call, options);
854
+ if (resp === undefined) {
855
+ throw new Error('API call completed without a result.');
856
+ }
857
+ return resp;
858
+ }
859
+
860
+ /** List evaluation results for a specific evaluation run. */
861
+ async genieListEvalResults(
862
+ req: GenieListEvalResultsRequest,
863
+ options?: CallOptions
864
+ ): Promise<GenieListEvalResultsResponse> {
865
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs/${req.evalRunId ?? ''}/results`;
866
+ const params = new URLSearchParams();
867
+ if (req.pageSize !== undefined) {
868
+ params.append('page_size', String(req.pageSize));
869
+ }
870
+ if (req.pageToken !== undefined) {
871
+ params.append('page_token', req.pageToken);
872
+ }
873
+ const query = params.toString();
874
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
875
+ let resp: GenieListEvalResultsResponse | undefined;
876
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
877
+ const headers = new Headers();
878
+ if (this.workspaceId !== undefined) {
879
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
880
+ }
881
+ headers.set('User-Agent', this.userAgent);
882
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
883
+ const respBody = await executeHttpCall({
884
+ request: httpReq,
885
+ httpClient: this.httpClient,
886
+ logger: this.logger,
887
+ });
888
+ resp = parseResponse(
889
+ respBody,
890
+ unmarshalGenieListEvalResultsResponseSchema
891
+ );
892
+ };
893
+ await executeCall(call, options);
894
+ if (resp === undefined) {
895
+ throw new Error('API call completed without a result.');
896
+ }
897
+ return resp;
898
+ }
899
+
900
+ /** Lists all evaluation runs in a space. */
901
+ async genieListEvalRuns(
902
+ req: GenieListEvalRunsRequest,
903
+ options?: CallOptions
904
+ ): Promise<GenieListEvalRunsResponse> {
905
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs`;
906
+ const params = new URLSearchParams();
907
+ if (req.pageSize !== undefined) {
908
+ params.append('page_size', String(req.pageSize));
909
+ }
910
+ if (req.pageToken !== undefined) {
911
+ params.append('page_token', req.pageToken);
912
+ }
913
+ const query = params.toString();
914
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
915
+ let resp: GenieListEvalRunsResponse | undefined;
916
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
917
+ const headers = new Headers();
918
+ if (this.workspaceId !== undefined) {
919
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
920
+ }
921
+ headers.set('User-Agent', this.userAgent);
922
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
923
+ const respBody = await executeHttpCall({
924
+ request: httpReq,
925
+ httpClient: this.httpClient,
926
+ logger: this.logger,
927
+ });
928
+ resp = parseResponse(respBody, unmarshalGenieListEvalRunsResponseSchema);
929
+ };
930
+ await executeCall(call, options);
931
+ if (resp === undefined) {
932
+ throw new Error('API call completed without a result.');
933
+ }
934
+ return resp;
935
+ }
936
+
937
+ /** List comments on a specific conversation message. */
938
+ async genieListMessageComments(
939
+ req: GenieListMessageCommentsRequest,
940
+ options?: CallOptions
941
+ ): Promise<GenieListMessageCommentsResponse> {
942
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/comments`;
943
+ const params = new URLSearchParams();
944
+ if (req.pageSize !== undefined) {
945
+ params.append('page_size', String(req.pageSize));
946
+ }
947
+ if (req.pageToken !== undefined) {
948
+ params.append('page_token', req.pageToken);
949
+ }
950
+ const query = params.toString();
951
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
952
+ let resp: GenieListMessageCommentsResponse | undefined;
953
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
954
+ const headers = new Headers();
955
+ if (this.workspaceId !== undefined) {
956
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
957
+ }
958
+ headers.set('User-Agent', this.userAgent);
959
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
960
+ const respBody = await executeHttpCall({
961
+ request: httpReq,
962
+ httpClient: this.httpClient,
963
+ logger: this.logger,
964
+ });
965
+ resp = parseResponse(
966
+ respBody,
967
+ unmarshalGenieListMessageCommentsResponseSchema
968
+ );
969
+ };
970
+ await executeCall(call, options);
971
+ if (resp === undefined) {
972
+ throw new Error('API call completed without a result.');
973
+ }
974
+ return resp;
975
+ }
976
+
977
+ /** Get list of Genie Spaces. */
978
+ async genieListSpaces(
979
+ req: GenieListSpacesRequest,
980
+ options?: CallOptions
981
+ ): Promise<GenieListSpacesResponse> {
982
+ const url = `${this.host}/api/2.0/genie/spaces`;
983
+ const params = new URLSearchParams();
984
+ if (req.pageSize !== undefined) {
985
+ params.append('page_size', String(req.pageSize));
986
+ }
987
+ if (req.pageToken !== undefined) {
988
+ params.append('page_token', req.pageToken);
989
+ }
990
+ const query = params.toString();
991
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
992
+ let resp: GenieListSpacesResponse | undefined;
993
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
994
+ const headers = new Headers();
995
+ if (this.workspaceId !== undefined) {
996
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
997
+ }
998
+ headers.set('User-Agent', this.userAgent);
999
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
1000
+ const respBody = await executeHttpCall({
1001
+ request: httpReq,
1002
+ httpClient: this.httpClient,
1003
+ logger: this.logger,
1004
+ });
1005
+ resp = parseResponse(respBody, unmarshalGenieListSpacesResponseSchema);
1006
+ };
1007
+ await executeCall(call, options);
1008
+ if (resp === undefined) {
1009
+ throw new Error('API call completed without a result.');
1010
+ }
1011
+ return resp;
1012
+ }
1013
+
1014
+ /** Send feedback for a message. */
1015
+ async genieSendMessageFeedback(
1016
+ req: GenieSendMessageFeedbackRequest,
1017
+ options?: CallOptions
1018
+ ): Promise<void> {
1019
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/feedback`;
1020
+ const body = marshalRequest(
1021
+ req,
1022
+ marshalGenieSendMessageFeedbackRequestSchema
1023
+ );
1024
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1025
+ const headers = new Headers({'Content-Type': 'application/json'});
1026
+ if (this.workspaceId !== undefined) {
1027
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1028
+ }
1029
+ headers.set('User-Agent', this.userAgent);
1030
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
1031
+ await executeHttpCall({
1032
+ request: httpReq,
1033
+ httpClient: this.httpClient,
1034
+ logger: this.logger,
1035
+ });
1036
+ };
1037
+ await executeCall(call, options);
1038
+ }
1039
+
1040
+ /** Start a new conversation. */
1041
+ async genieStartConversation(
1042
+ req: GenieStartConversationMessageRequest,
1043
+ options?: CallOptions
1044
+ ): Promise<GenieStartConversationResponse> {
1045
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/start-conversation`;
1046
+ const body = marshalRequest(
1047
+ req,
1048
+ marshalGenieStartConversationMessageRequestSchema
1049
+ );
1050
+ let resp: GenieStartConversationResponse | undefined;
1051
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1052
+ const headers = new Headers({'Content-Type': 'application/json'});
1053
+ if (this.workspaceId !== undefined) {
1054
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1055
+ }
1056
+ headers.set('User-Agent', this.userAgent);
1057
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
1058
+ const respBody = await executeHttpCall({
1059
+ request: httpReq,
1060
+ httpClient: this.httpClient,
1061
+ logger: this.logger,
1062
+ });
1063
+ resp = parseResponse(
1064
+ respBody,
1065
+ unmarshalGenieStartConversationResponseSchema
1066
+ );
1067
+ };
1068
+ await executeCall(call, options);
1069
+ if (resp === undefined) {
1070
+ throw new Error('API call completed without a result.');
1071
+ }
1072
+ return resp;
1073
+ }
1074
+
1075
+ async genieStartConversationWaiter(
1076
+ req: GenieStartConversationMessageRequest,
1077
+ options?: CallOptions
1078
+ ): Promise<GenieStartConversationWaiter> {
1079
+ const resp = await this.genieStartConversation(req, options);
1080
+ if (resp.messageId === undefined) {
1081
+ throw new Error(
1082
+ 'response field messageId required for polling is missing'
1083
+ );
1084
+ }
1085
+ if (resp.conversationId === undefined) {
1086
+ throw new Error(
1087
+ 'response field conversationId required for polling is missing'
1088
+ );
1089
+ }
1090
+ if (req.spaceId === undefined) {
1091
+ throw new Error('request field spaceId required for polling is missing');
1092
+ }
1093
+ return new GenieStartConversationWaiter(
1094
+ this,
1095
+ resp.messageId,
1096
+ resp.conversationId,
1097
+ req.spaceId
1098
+ );
1099
+ }
1100
+
1101
+ /** Move a Genie Space to the trash. */
1102
+ async genieTrashSpace(
1103
+ req: GenieTrashSpaceRequest,
1104
+ options?: CallOptions
1105
+ ): Promise<void> {
1106
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}`;
1107
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1108
+ const headers = new Headers();
1109
+ if (this.workspaceId !== undefined) {
1110
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1111
+ }
1112
+ headers.set('User-Agent', this.userAgent);
1113
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
1114
+ await executeHttpCall({
1115
+ request: httpReq,
1116
+ httpClient: this.httpClient,
1117
+ logger: this.logger,
1118
+ });
1119
+ };
1120
+ await executeCall(call, options);
1121
+ }
1122
+
1123
+ /** Updates a Genie space with a serialized payload. */
1124
+ async updateSpace(
1125
+ req: GenieUpdateSpaceRequest,
1126
+ options?: CallOptions
1127
+ ): Promise<GenieSpace> {
1128
+ const url = `${this.host}/api/2.0/genie/spaces/${req.spaceId ?? ''}`;
1129
+ const body = marshalRequest(req, marshalGenieUpdateSpaceRequestSchema);
1130
+ let resp: GenieSpace | undefined;
1131
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1132
+ const headers = new Headers({'Content-Type': 'application/json'});
1133
+ if (this.workspaceId !== undefined) {
1134
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1135
+ }
1136
+ headers.set('User-Agent', this.userAgent);
1137
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
1138
+ const respBody = await executeHttpCall({
1139
+ request: httpReq,
1140
+ httpClient: this.httpClient,
1141
+ logger: this.logger,
1142
+ });
1143
+ resp = parseResponse(respBody, unmarshalGenieSpaceSchema);
1144
+ };
1145
+ await executeCall(call, options);
1146
+ if (resp === undefined) {
1147
+ throw new Error('API call completed without a result.');
1148
+ }
1149
+ return resp;
1150
+ }
1151
+ }
1152
+
1153
+ export class GenieCreateConversationMessageWaiter {
1154
+ constructor(
1155
+ private readonly client: Client,
1156
+ readonly messageId: string,
1157
+ readonly conversationId: string,
1158
+ readonly spaceId: string
1159
+ ) {}
1160
+
1161
+ /**
1162
+ * Polls until the operation reaches a terminal state.
1163
+ *
1164
+ * Throws if a failure state is reached.
1165
+ */
1166
+ async wait(options?: CallOptions): Promise<GenieMessage> {
1167
+ let result: GenieMessage | undefined;
1168
+
1169
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1170
+ const pollResp = await this.client.genieGetConversationMessage(
1171
+ {
1172
+ messageId: this.messageId,
1173
+ conversationId: this.conversationId,
1174
+ spaceId: this.spaceId,
1175
+ },
1176
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
1177
+ );
1178
+
1179
+ const status = pollResp.status;
1180
+ if (status === undefined) {
1181
+ throw new Error('response missing required status field');
1182
+ }
1183
+
1184
+ switch (status) {
1185
+ case MessageStatus_MessageStatus.COMPLETED:
1186
+ result = pollResp;
1187
+ return;
1188
+ case MessageStatus_MessageStatus.FAILED: {
1189
+ const msg = '(no message)';
1190
+ throw new Error(`terminal state ${status}: ${msg}`);
1191
+ }
1192
+ default:
1193
+ throw new StillRunningError();
1194
+ }
1195
+ };
1196
+
1197
+ const retryOptions: CallOptions = {
1198
+ ...(options?.signal !== undefined && {signal: options.signal}),
1199
+ retrier: () =>
1200
+ retryOn({}, (err: Error) => {
1201
+ return err instanceof StillRunningError;
1202
+ }),
1203
+ };
1204
+ await executeCall(call, retryOptions);
1205
+ if (result === undefined) {
1206
+ throw new Error('API call completed without a result.');
1207
+ }
1208
+ return result;
1209
+ }
1210
+
1211
+ /** Checks whether the operation has reached a terminal state. */
1212
+ async done(options?: CallOptions): Promise<boolean> {
1213
+ const pollResp = await this.client.genieGetConversationMessage(
1214
+ {
1215
+ messageId: this.messageId,
1216
+ conversationId: this.conversationId,
1217
+ spaceId: this.spaceId,
1218
+ },
1219
+ options
1220
+ );
1221
+
1222
+ const status = pollResp.status;
1223
+ if (status === undefined) {
1224
+ throw new Error('response missing required status field');
1225
+ }
1226
+
1227
+ switch (status) {
1228
+ case MessageStatus_MessageStatus.COMPLETED:
1229
+ case MessageStatus_MessageStatus.FAILED:
1230
+ return true;
1231
+ default:
1232
+ return false;
1233
+ }
1234
+ }
1235
+ }
1236
+
1237
+ export class GenieStartConversationWaiter {
1238
+ constructor(
1239
+ private readonly client: Client,
1240
+ readonly messageId: string,
1241
+ readonly conversationId: string,
1242
+ readonly spaceId: string
1243
+ ) {}
1244
+
1245
+ /**
1246
+ * Polls until the operation reaches a terminal state.
1247
+ *
1248
+ * Throws if a failure state is reached.
1249
+ */
1250
+ async wait(options?: CallOptions): Promise<GenieMessage> {
1251
+ let result: GenieMessage | undefined;
1252
+
1253
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1254
+ const pollResp = await this.client.genieGetConversationMessage(
1255
+ {
1256
+ messageId: this.messageId,
1257
+ conversationId: this.conversationId,
1258
+ spaceId: this.spaceId,
1259
+ },
1260
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
1261
+ );
1262
+
1263
+ const status = pollResp.status;
1264
+ if (status === undefined) {
1265
+ throw new Error('response missing required status field');
1266
+ }
1267
+
1268
+ switch (status) {
1269
+ case MessageStatus_MessageStatus.COMPLETED:
1270
+ result = pollResp;
1271
+ return;
1272
+ case MessageStatus_MessageStatus.FAILED: {
1273
+ const msg = '(no message)';
1274
+ throw new Error(`terminal state ${status}: ${msg}`);
1275
+ }
1276
+ default:
1277
+ throw new StillRunningError();
1278
+ }
1279
+ };
1280
+
1281
+ const retryOptions: CallOptions = {
1282
+ ...(options?.signal !== undefined && {signal: options.signal}),
1283
+ retrier: () =>
1284
+ retryOn({}, (err: Error) => {
1285
+ return err instanceof StillRunningError;
1286
+ }),
1287
+ };
1288
+ await executeCall(call, retryOptions);
1289
+ if (result === undefined) {
1290
+ throw new Error('API call completed without a result.');
1291
+ }
1292
+ return result;
1293
+ }
1294
+
1295
+ /** Checks whether the operation has reached a terminal state. */
1296
+ async done(options?: CallOptions): Promise<boolean> {
1297
+ const pollResp = await this.client.genieGetConversationMessage(
1298
+ {
1299
+ messageId: this.messageId,
1300
+ conversationId: this.conversationId,
1301
+ spaceId: this.spaceId,
1302
+ },
1303
+ options
1304
+ );
1305
+
1306
+ const status = pollResp.status;
1307
+ if (status === undefined) {
1308
+ throw new Error('response missing required status field');
1309
+ }
1310
+
1311
+ switch (status) {
1312
+ case MessageStatus_MessageStatus.COMPLETED:
1313
+ case MessageStatus_MessageStatus.FAILED:
1314
+ return true;
1315
+ default:
1316
+ return false;
1317
+ }
1318
+ }
1319
+ }