@databricks/sdk-genie 0.33.0 → 0.35.0

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.
package/dist/v1/client.js CHANGED
@@ -1,1052 +1,807 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
- import { VERSION as AUTH_VERSION } from '@databricks/sdk-auth';
3
- import { createDefault } from '@databricks/sdk-core/clientinfo';
4
- import { NoOpLogger } from '@databricks/sdk-core/logger';
5
- import { resolveClientConfig } from './transport';
6
- import { buildHttpRequest, executeCall, executeHttpCall, sendAndCheckError, marshalRequest, parseResponse, executeWait, StillRunningError, } from './utils';
7
- import pkgJson from '../../package.json' with { type: 'json' };
8
- import { MessageStatus_MessageStatus, marshalGenieCreateConversationMessageRequestSchema, marshalGenieCreateEvalRunRequestSchema, marshalGenieCreateMessageCommentRequestSchema, marshalGenieCreateSpaceRequestSchema, marshalGenieExecuteMessageAttachmentQueryRequestSchema, marshalGenieExecuteMessageQueryRequestSchema, marshalGenieGenerateDownloadFullQueryResultRequestSchema, marshalGenieSendMessageFeedbackRequestSchema, marshalGenieStartConversationRequestSchema, marshalGenieUpdateSpaceRequestSchema, unmarshalGenieEvalResultDetailsSchema, unmarshalGenieEvalRunResponseSchema, unmarshalGenieGenerateDownloadFullQueryResultResponseSchema, unmarshalGenieGetDownloadFullQueryResultResponseSchema, unmarshalGenieGetMessageQueryResultResponseSchema, unmarshalGenieListConversationCommentsResponseSchema, unmarshalGenieListConversationMessagesResponseSchema, unmarshalGenieListConversationsResponseSchema, unmarshalGenieListEvalResultsResponseSchema, unmarshalGenieListEvalRunsResponseSchema, unmarshalGenieListMessageCommentsResponseSchema, unmarshalGenieListSpacesResponseSchema, unmarshalGenieMessageCommentSchema, unmarshalGenieMessageSchema, unmarshalGenieSpaceSchema, unmarshalGenieStartConversationResponseSchema, } from './model';
9
- // Package identity segment for this client to be used in the User-Agent header.
1
+ import { resolveClientConfig } from "./transport.js";
2
+ import { StillRunningError, buildHttpRequest, executeCall, executeHttpCall, executeWait, marshalRequest, parseResponse, sendAndCheckError } from "./utils.js";
3
+ import { name, version } from "../package.js";
4
+ import { MessageStatus_MessageStatus, marshalGenieCreateConversationMessageRequestSchema, marshalGenieCreateEvalRunRequestSchema, marshalGenieCreateMessageCommentRequestSchema, marshalGenieCreateSpaceRequestSchema, marshalGenieExecuteMessageAttachmentQueryRequestSchema, marshalGenieExecuteMessageQueryRequestSchema, marshalGenieGenerateDownloadFullQueryResultRequestSchema, marshalGenieSendMessageFeedbackRequestSchema, marshalGenieStartConversationRequestSchema, marshalGenieUpdateSpaceRequestSchema, unmarshalGenieEvalResultDetailsSchema, unmarshalGenieEvalRunResponseSchema, unmarshalGenieGenerateDownloadFullQueryResultResponseSchema, unmarshalGenieGetDownloadFullQueryResultResponseSchema, unmarshalGenieGetMessageQueryResultResponseSchema, unmarshalGenieListConversationCommentsResponseSchema, unmarshalGenieListConversationMessagesResponseSchema, unmarshalGenieListConversationsResponseSchema, unmarshalGenieListEvalResultsResponseSchema, unmarshalGenieListEvalRunsResponseSchema, unmarshalGenieListMessageCommentsResponseSchema, unmarshalGenieListSpacesResponseSchema, unmarshalGenieMessageCommentSchema, unmarshalGenieMessageSchema, unmarshalGenieSpaceSchema, unmarshalGenieStartConversationResponseSchema } from "./model.js";
5
+ import { VERSION } from "@databricks/sdk-auth";
6
+ import { createDefault } from "@databricks/sdk-core/clientinfo";
7
+ import { NoOpLogger } from "@databricks/sdk-core/logger";
8
+
9
+ //#region src/v1/client.ts
10
10
  const PACKAGE_SEGMENT = {
11
- key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
12
- value: pkgJson.version,
11
+ key: "sdk-js-" + name.replace(/^@[^/]+\/sdk-/, ""),
12
+ value: version
13
13
  };
14
- export class GenieClient {
15
- options;
16
- logger;
17
- // User-Agent header value. Composed once at construction from
18
- // createDefault() merged with this package's identity and the active
19
- // credential's name.
20
- userAgent;
21
- // Memoized configuration. The profile is resolved once, lazily, on the first
22
- // request, then reused; host, workspaceId/accountId, and credentials are
23
- // filled from it when not set explicitly on the options.
24
- config;
25
- constructor(options) {
26
- this.options = options;
27
- this.logger = options.logger ?? new NoOpLogger();
28
- const info = createDefault()
29
- .with(PACKAGE_SEGMENT)
30
- .with({ key: 'sdk-js-auth', value: AUTH_VERSION })
31
- .with({ key: 'auth', value: options.credentials?.name() ?? 'default' });
32
- this.userAgent = info.toString();
33
- }
34
- resolveConfig() {
35
- this.config ??= resolveClientConfig(this.options);
36
- return this.config;
37
- }
38
- /** Creates a Genie space from a serialized payload. */
39
- async createSpace(req, options) {
40
- const { host, workspaceId, httpClient } = await this.resolveConfig();
41
- const url = `${host}/api/2.0/genie/spaces`;
42
- const body = marshalRequest(req, marshalGenieCreateSpaceRequestSchema);
43
- let resp;
44
- const call = async (callSignal) => {
45
- const headers = new Headers({ 'Content-Type': 'application/json' });
46
- if (workspaceId !== undefined) {
47
- headers.set('X-Databricks-Workspace-Id', workspaceId);
48
- }
49
- headers.set('User-Agent', this.userAgent);
50
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
51
- const respBody = await executeHttpCall({
52
- request: httpReq,
53
- httpClient,
54
- logger: this.logger,
55
- });
56
- resp = parseResponse(respBody, unmarshalGenieSpaceSchema);
57
- };
58
- await executeCall(call, options);
59
- if (resp === undefined) {
60
- throw new Error('operation completed without a result.');
61
- }
62
- return resp;
63
- }
64
- /**
65
- * Download a rendered image of a message visualization attachment.
66
- * The response body is the raw PNG image, not a JSON payload.
67
- * This is only available if the attachment is a visualization and the message status is `COMPLETED`.
68
- * This endpoint is not supported for Private Link workspaces.
69
- */
70
- async downloadMessageAttachmentVisualization(req, options) {
71
- const { host, workspaceId, httpClient } = await this.resolveConfig();
72
- const url = `${host}/api/2.0/genie/${req.name ?? ''}/download-visualization`;
73
- let resp;
74
- const call = async (callSignal) => {
75
- const headers = new Headers();
76
- if (workspaceId !== undefined) {
77
- headers.set('X-Databricks-Workspace-Id', workspaceId);
78
- }
79
- headers.set('User-Agent', this.userAgent);
80
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
81
- const httpResp = await sendAndCheckError({
82
- request: httpReq,
83
- httpClient,
84
- logger: this.logger,
85
- });
86
- resp = {
87
- contents: httpResp.body ?? undefined,
88
- };
89
- };
90
- await executeCall(call, options);
91
- if (resp === undefined) {
92
- throw new Error('operation completed without a result.');
93
- }
94
- return resp;
95
- }
96
- /**
97
- * Create new message in a [conversation](:method:genie/startconversation).
98
- * The AI response uses all previously created messages in the conversation to respond.
99
- */
100
- async genieCreateConversationMessageBase(req, options) {
101
- const { host, workspaceId, httpClient } = await this.resolveConfig();
102
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages`;
103
- const body = marshalRequest(req, marshalGenieCreateConversationMessageRequestSchema);
104
- let resp;
105
- const call = async (callSignal) => {
106
- const headers = new Headers({ 'Content-Type': 'application/json' });
107
- if (workspaceId !== undefined) {
108
- headers.set('X-Databricks-Workspace-Id', workspaceId);
109
- }
110
- headers.set('User-Agent', this.userAgent);
111
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
112
- const respBody = await executeHttpCall({
113
- request: httpReq,
114
- httpClient,
115
- logger: this.logger,
116
- });
117
- resp = parseResponse(respBody, unmarshalGenieMessageSchema);
118
- };
119
- await executeCall(call, options);
120
- if (resp === undefined) {
121
- throw new Error('operation completed without a result.');
122
- }
123
- return resp;
124
- }
125
- /**
126
- * Create new message in a [conversation](:method:genie/startconversation).
127
- * The AI response uses all previously created messages in the conversation to respond.
128
- */
129
- async genieCreateConversationMessage(req, options) {
130
- const resp = await this.genieCreateConversationMessageBase(req, options);
131
- if (resp.messageId === undefined) {
132
- throw new Error('response field messageId required for polling is missing');
133
- }
134
- if (req.conversationId === undefined) {
135
- throw new Error('request field conversationId required for polling is missing');
136
- }
137
- if (req.spaceId === undefined) {
138
- throw new Error('request field spaceId required for polling is missing');
139
- }
140
- return new GenieCreateConversationMessageWaiter(this, resp.messageId, req.conversationId, req.spaceId);
141
- }
142
- /** Create and run evaluations for multiple benchmark questions in a Genie space. */
143
- async genieCreateEvalRun(req, options) {
144
- const { host, workspaceId, httpClient } = await this.resolveConfig();
145
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs`;
146
- const body = marshalRequest(req, marshalGenieCreateEvalRunRequestSchema);
147
- let resp;
148
- const call = async (callSignal) => {
149
- const headers = new Headers({ 'Content-Type': 'application/json' });
150
- if (workspaceId !== undefined) {
151
- headers.set('X-Databricks-Workspace-Id', workspaceId);
152
- }
153
- headers.set('User-Agent', this.userAgent);
154
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
155
- const respBody = await executeHttpCall({
156
- request: httpReq,
157
- httpClient,
158
- logger: this.logger,
159
- });
160
- resp = parseResponse(respBody, unmarshalGenieEvalRunResponseSchema);
161
- };
162
- await executeCall(call, options);
163
- if (resp === undefined) {
164
- throw new Error('operation completed without a result.');
165
- }
166
- return resp;
167
- }
168
- /** Create a comment on a conversation message. */
169
- async genieCreateMessageComment(req, options) {
170
- const { host, workspaceId, httpClient } = await this.resolveConfig();
171
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/comments`;
172
- const body = marshalRequest(req, marshalGenieCreateMessageCommentRequestSchema);
173
- let resp;
174
- const call = async (callSignal) => {
175
- const headers = new Headers({ 'Content-Type': 'application/json' });
176
- if (workspaceId !== undefined) {
177
- headers.set('X-Databricks-Workspace-Id', workspaceId);
178
- }
179
- headers.set('User-Agent', this.userAgent);
180
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
181
- const respBody = await executeHttpCall({
182
- request: httpReq,
183
- httpClient,
184
- logger: this.logger,
185
- });
186
- resp = parseResponse(respBody, unmarshalGenieMessageCommentSchema);
187
- };
188
- await executeCall(call, options);
189
- if (resp === undefined) {
190
- throw new Error('operation completed without a result.');
191
- }
192
- return resp;
193
- }
194
- /** Delete a conversation. */
195
- async genieDeleteConversation(req, options) {
196
- const { host, workspaceId, httpClient } = await this.resolveConfig();
197
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}`;
198
- const call = async (callSignal) => {
199
- const headers = new Headers();
200
- if (workspaceId !== undefined) {
201
- headers.set('X-Databricks-Workspace-Id', workspaceId);
202
- }
203
- headers.set('User-Agent', this.userAgent);
204
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
205
- await executeHttpCall({
206
- request: httpReq,
207
- httpClient,
208
- logger: this.logger,
209
- });
210
- };
211
- await executeCall(call, options);
212
- }
213
- /** Delete a conversation message. */
214
- async genieDeleteConversationMessage(req, options) {
215
- const { host, workspaceId, httpClient } = await this.resolveConfig();
216
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}`;
217
- const call = async (callSignal) => {
218
- const headers = new Headers();
219
- if (workspaceId !== undefined) {
220
- headers.set('X-Databricks-Workspace-Id', workspaceId);
221
- }
222
- headers.set('User-Agent', this.userAgent);
223
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
224
- await executeHttpCall({
225
- request: httpReq,
226
- httpClient,
227
- logger: this.logger,
228
- });
229
- };
230
- await executeCall(call, options);
231
- }
232
- /** Execute the SQL for a message query attachment. Use this API when the query attachment has expired and needs to be re-executed. */
233
- async genieExecuteMessageAttachmentQuery(req, options) {
234
- const { host, workspaceId, httpClient } = await this.resolveConfig();
235
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/execute-query`;
236
- const body = marshalRequest(req, marshalGenieExecuteMessageAttachmentQueryRequestSchema);
237
- let resp;
238
- const call = async (callSignal) => {
239
- const headers = new Headers({ 'Content-Type': 'application/json' });
240
- if (workspaceId !== undefined) {
241
- headers.set('X-Databricks-Workspace-Id', workspaceId);
242
- }
243
- headers.set('User-Agent', this.userAgent);
244
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
245
- const respBody = await executeHttpCall({
246
- request: httpReq,
247
- httpClient,
248
- logger: this.logger,
249
- });
250
- resp = parseResponse(respBody, unmarshalGenieGetMessageQueryResultResponseSchema);
251
- };
252
- await executeCall(call, options);
253
- if (resp === undefined) {
254
- throw new Error('operation completed without a result.');
255
- }
256
- return resp;
257
- }
258
- /** DEPRECATED: Use [Execute Message Attachment Query](:method:genie/executemessageattachmentquery) instead. */
259
- async genieExecuteMessageQuery(req, options) {
260
- const { host, workspaceId, httpClient } = await this.resolveConfig();
261
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/execute-query`;
262
- const body = marshalRequest(req, marshalGenieExecuteMessageQueryRequestSchema);
263
- let resp;
264
- const call = async (callSignal) => {
265
- const headers = new Headers({ 'Content-Type': 'application/json' });
266
- if (workspaceId !== undefined) {
267
- headers.set('X-Databricks-Workspace-Id', workspaceId);
268
- }
269
- headers.set('User-Agent', this.userAgent);
270
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
271
- const respBody = await executeHttpCall({
272
- request: httpReq,
273
- httpClient,
274
- logger: this.logger,
275
- });
276
- resp = parseResponse(respBody, unmarshalGenieGetMessageQueryResultResponseSchema);
277
- };
278
- await executeCall(call, options);
279
- if (resp === undefined) {
280
- throw new Error('operation completed without a result.');
281
- }
282
- return resp;
283
- }
284
- /**
285
- * 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.
286
- * The query result is stored in an external link and can be retrieved using the [Get Download Full Query Result](:method:genie/getdownloadfullqueryresult) API.
287
- * Both `download_id` and `download_id_signature` must be provided when calling the Get endpoint.
288
- *
289
- * ----
290
- *
291
- * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
292
- *
293
- * When you use the `EXTERNAL_LINKS` disposition, a
294
- * short-lived, URL is generated, which can be
295
- * used to download the results directly
296
- * from . As a
297
- * short-lived is
298
- * embedded in this URL, you should protect
299
- * the URL.
300
- *
301
- * Because URLs are already generated with
302
- * embedded temporary s,
303
- * you must not set an `Authorization` header in the download requests.
304
- *
305
- * See [Execute Statement](:method:statementexecution/executestatement) for more details.
306
- *
307
- * ----
308
- */
309
- async genieGenerateDownloadFullQueryResult(req, options) {
310
- const { host, workspaceId, httpClient } = await this.resolveConfig();
311
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/downloads`;
312
- const body = marshalRequest(req, marshalGenieGenerateDownloadFullQueryResultRequestSchema);
313
- let resp;
314
- const call = async (callSignal) => {
315
- const headers = new Headers({ 'Content-Type': 'application/json' });
316
- if (workspaceId !== undefined) {
317
- headers.set('X-Databricks-Workspace-Id', workspaceId);
318
- }
319
- headers.set('User-Agent', this.userAgent);
320
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
321
- const respBody = await executeHttpCall({
322
- request: httpReq,
323
- httpClient,
324
- logger: this.logger,
325
- });
326
- resp = parseResponse(respBody, unmarshalGenieGenerateDownloadFullQueryResultResponseSchema);
327
- };
328
- await executeCall(call, options);
329
- if (resp === undefined) {
330
- throw new Error('operation completed without a result.');
331
- }
332
- return resp;
333
- }
334
- /** Get message from conversation. */
335
- async genieGetConversationMessage(req, options) {
336
- const { host, workspaceId, httpClient } = await this.resolveConfig();
337
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}`;
338
- let resp;
339
- const call = async (callSignal) => {
340
- const headers = new Headers();
341
- if (workspaceId !== undefined) {
342
- headers.set('X-Databricks-Workspace-Id', workspaceId);
343
- }
344
- headers.set('User-Agent', this.userAgent);
345
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
346
- const respBody = await executeHttpCall({
347
- request: httpReq,
348
- httpClient,
349
- logger: this.logger,
350
- });
351
- resp = parseResponse(respBody, unmarshalGenieMessageSchema);
352
- };
353
- await executeCall(call, options);
354
- if (resp === undefined) {
355
- throw new Error('operation completed without a result.');
356
- }
357
- return resp;
358
- }
359
- /**
360
- * 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.
361
- * Both `download_id` and `download_id_signature` are required to call this endpoint.
362
- * 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.
363
- *
364
- * ----
365
- *
366
- * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
367
- *
368
- * When you use the `EXTERNAL_LINKS` disposition, a
369
- * short-lived, URL is generated, which can be
370
- * used to download the results directly
371
- * from . As a
372
- * short-lived is
373
- * embedded in this URL, you should protect
374
- * the URL.
375
- *
376
- * Because URLs are already generated with
377
- * embedded temporary s,
378
- * you must not set an `Authorization` header in the download requests.
379
- *
380
- * See [Execute Statement](:method:statementexecution/executestatement) for more details.
381
- *
382
- * ----
383
- */
384
- async genieGetDownloadFullQueryResult(req, options) {
385
- const { host, workspaceId, httpClient } = await this.resolveConfig();
386
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/downloads/${req.downloadId ?? ''}`;
387
- const params = new URLSearchParams();
388
- if (req.downloadIdSignature !== undefined) {
389
- params.append('download_id_signature', req.downloadIdSignature);
390
- }
391
- const query = params.toString();
392
- const fullUrl = query !== '' ? `${url}?${query}` : url;
393
- let resp;
394
- const call = async (callSignal) => {
395
- const headers = new Headers();
396
- if (workspaceId !== undefined) {
397
- headers.set('X-Databricks-Workspace-Id', workspaceId);
398
- }
399
- headers.set('User-Agent', this.userAgent);
400
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
401
- const respBody = await executeHttpCall({
402
- request: httpReq,
403
- httpClient,
404
- logger: this.logger,
405
- });
406
- resp = parseResponse(respBody, unmarshalGenieGetDownloadFullQueryResultResponseSchema);
407
- };
408
- await executeCall(call, options);
409
- if (resp === undefined) {
410
- throw new Error('operation completed without a result.');
411
- }
412
- return resp;
413
- }
414
- /** Get details for evaluation results. */
415
- async genieGetEvalResultDetails(req, options) {
416
- const { host, workspaceId, httpClient } = await this.resolveConfig();
417
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs/${req.evalRunId ?? ''}/results/${req.resultId ?? ''}`;
418
- let resp;
419
- const call = async (callSignal) => {
420
- const headers = new Headers();
421
- if (workspaceId !== undefined) {
422
- headers.set('X-Databricks-Workspace-Id', workspaceId);
423
- }
424
- headers.set('User-Agent', this.userAgent);
425
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
426
- const respBody = await executeHttpCall({
427
- request: httpReq,
428
- httpClient,
429
- logger: this.logger,
430
- });
431
- resp = parseResponse(respBody, unmarshalGenieEvalResultDetailsSchema);
432
- };
433
- await executeCall(call, options);
434
- if (resp === undefined) {
435
- throw new Error('operation completed without a result.');
436
- }
437
- return resp;
438
- }
439
- /** Get evaluation run details. */
440
- async genieGetEvalRun(req, options) {
441
- const { host, workspaceId, httpClient } = await this.resolveConfig();
442
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs/${req.evalRunId ?? ''}`;
443
- let resp;
444
- const call = async (callSignal) => {
445
- const headers = new Headers();
446
- if (workspaceId !== undefined) {
447
- headers.set('X-Databricks-Workspace-Id', workspaceId);
448
- }
449
- headers.set('User-Agent', this.userAgent);
450
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
451
- const respBody = await executeHttpCall({
452
- request: httpReq,
453
- httpClient,
454
- logger: this.logger,
455
- });
456
- resp = parseResponse(respBody, unmarshalGenieEvalRunResponseSchema);
457
- };
458
- await executeCall(call, options);
459
- if (resp === undefined) {
460
- throw new Error('operation completed without a result.');
461
- }
462
- return resp;
463
- }
464
- /**
465
- * Get the result of SQL query if the message has a query attachment.
466
- * This is only available if a message has a query attachment and the message status is `EXECUTING_QUERY` OR `COMPLETED`.
467
- */
468
- async genieGetMessageAttachmentQueryResult(req, options) {
469
- const { host, workspaceId, httpClient } = await this.resolveConfig();
470
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/attachments/${req.attachmentId ?? ''}/query-result`;
471
- let resp;
472
- const call = async (callSignal) => {
473
- const headers = new Headers();
474
- if (workspaceId !== undefined) {
475
- headers.set('X-Databricks-Workspace-Id', workspaceId);
476
- }
477
- headers.set('User-Agent', this.userAgent);
478
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
479
- const respBody = await executeHttpCall({
480
- request: httpReq,
481
- httpClient,
482
- logger: this.logger,
483
- });
484
- resp = parseResponse(respBody, unmarshalGenieGetMessageQueryResultResponseSchema);
485
- };
486
- await executeCall(call, options);
487
- if (resp === undefined) {
488
- throw new Error('operation completed without a result.');
489
- }
490
- return resp;
491
- }
492
- /** DEPRECATED: Use [Get Message Attachment Query Result](:method:genie/getmessageattachmentqueryresult) instead. */
493
- async genieGetMessageQueryResult(req, options) {
494
- const { host, workspaceId, httpClient } = await this.resolveConfig();
495
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/query-result`;
496
- let resp;
497
- const call = async (callSignal) => {
498
- const headers = new Headers();
499
- if (workspaceId !== undefined) {
500
- headers.set('X-Databricks-Workspace-Id', workspaceId);
501
- }
502
- headers.set('User-Agent', this.userAgent);
503
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
504
- const respBody = await executeHttpCall({
505
- request: httpReq,
506
- httpClient,
507
- logger: this.logger,
508
- });
509
- resp = parseResponse(respBody, unmarshalGenieGetMessageQueryResultResponseSchema);
510
- };
511
- await executeCall(call, options);
512
- if (resp === undefined) {
513
- throw new Error('operation completed without a result.');
514
- }
515
- return resp;
516
- }
517
- /** DEPRECATED: Use [Get Message Attachment Query Result](:method:genie/getmessageattachmentqueryresult) instead. */
518
- async genieGetQueryResultByAttachment(req, options) {
519
- const { host, workspaceId, httpClient } = await this.resolveConfig();
520
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/query-result/${req.attachmentId ?? ''}`;
521
- let resp;
522
- const call = async (callSignal) => {
523
- const headers = new Headers();
524
- if (workspaceId !== undefined) {
525
- headers.set('X-Databricks-Workspace-Id', workspaceId);
526
- }
527
- headers.set('User-Agent', this.userAgent);
528
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
529
- const respBody = await executeHttpCall({
530
- request: httpReq,
531
- httpClient,
532
- logger: this.logger,
533
- });
534
- resp = parseResponse(respBody, unmarshalGenieGetMessageQueryResultResponseSchema);
535
- };
536
- await executeCall(call, options);
537
- if (resp === undefined) {
538
- throw new Error('operation completed without a result.');
539
- }
540
- return resp;
541
- }
542
- /** Get details of a Genie Space. */
543
- async genieGetSpace(req, options) {
544
- const { host, workspaceId, httpClient } = await this.resolveConfig();
545
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}`;
546
- const params = new URLSearchParams();
547
- if (req.includeSerializedSpace !== undefined) {
548
- params.append('include_serialized_space', String(req.includeSerializedSpace));
549
- }
550
- const query = params.toString();
551
- const fullUrl = query !== '' ? `${url}?${query}` : url;
552
- let resp;
553
- const call = async (callSignal) => {
554
- const headers = new Headers();
555
- if (workspaceId !== undefined) {
556
- headers.set('X-Databricks-Workspace-Id', workspaceId);
557
- }
558
- headers.set('User-Agent', this.userAgent);
559
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
560
- const respBody = await executeHttpCall({
561
- request: httpReq,
562
- httpClient,
563
- logger: this.logger,
564
- });
565
- resp = parseResponse(respBody, unmarshalGenieSpaceSchema);
566
- };
567
- await executeCall(call, options);
568
- if (resp === undefined) {
569
- throw new Error('operation completed without a result.');
570
- }
571
- return resp;
572
- }
573
- /** List all comments across all messages in a conversation. */
574
- async genieListConversationComments(req, options) {
575
- const { host, workspaceId, httpClient } = await this.resolveConfig();
576
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/list-comments`;
577
- const params = new URLSearchParams();
578
- if (req.pageSize !== undefined) {
579
- params.append('page_size', String(req.pageSize));
580
- }
581
- if (req.pageToken !== undefined) {
582
- params.append('page_token', req.pageToken);
583
- }
584
- const query = params.toString();
585
- const fullUrl = query !== '' ? `${url}?${query}` : url;
586
- let resp;
587
- const call = async (callSignal) => {
588
- const headers = new Headers();
589
- if (workspaceId !== undefined) {
590
- headers.set('X-Databricks-Workspace-Id', workspaceId);
591
- }
592
- headers.set('User-Agent', this.userAgent);
593
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
594
- const respBody = await executeHttpCall({
595
- request: httpReq,
596
- httpClient,
597
- logger: this.logger,
598
- });
599
- resp = parseResponse(respBody, unmarshalGenieListConversationCommentsResponseSchema);
600
- };
601
- await executeCall(call, options);
602
- if (resp === undefined) {
603
- throw new Error('operation completed without a result.');
604
- }
605
- return resp;
606
- }
607
- /** List messages in a conversation */
608
- async genieListConversationMessages(req, options) {
609
- const { host, workspaceId, httpClient } = await this.resolveConfig();
610
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages`;
611
- const params = new URLSearchParams();
612
- if (req.pageSize !== undefined) {
613
- params.append('page_size', String(req.pageSize));
614
- }
615
- if (req.pageToken !== undefined) {
616
- params.append('page_token', req.pageToken);
617
- }
618
- const query = params.toString();
619
- const fullUrl = query !== '' ? `${url}?${query}` : url;
620
- let resp;
621
- const call = async (callSignal) => {
622
- const headers = new Headers();
623
- if (workspaceId !== undefined) {
624
- headers.set('X-Databricks-Workspace-Id', workspaceId);
625
- }
626
- headers.set('User-Agent', this.userAgent);
627
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
628
- const respBody = await executeHttpCall({
629
- request: httpReq,
630
- httpClient,
631
- logger: this.logger,
632
- });
633
- resp = parseResponse(respBody, unmarshalGenieListConversationMessagesResponseSchema);
634
- };
635
- await executeCall(call, options);
636
- if (resp === undefined) {
637
- throw new Error('operation completed without a result.');
638
- }
639
- return resp;
640
- }
641
- /** Get a list of conversations in a Genie Space. */
642
- async genieListConversations(req, options) {
643
- const { host, workspaceId, httpClient } = await this.resolveConfig();
644
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations`;
645
- const params = new URLSearchParams();
646
- if (req.pageSize !== undefined) {
647
- params.append('page_size', String(req.pageSize));
648
- }
649
- if (req.pageToken !== undefined) {
650
- params.append('page_token', req.pageToken);
651
- }
652
- if (req.includeAll !== undefined) {
653
- params.append('include_all', String(req.includeAll));
654
- }
655
- const query = params.toString();
656
- const fullUrl = query !== '' ? `${url}?${query}` : url;
657
- let resp;
658
- const call = async (callSignal) => {
659
- const headers = new Headers();
660
- if (workspaceId !== undefined) {
661
- headers.set('X-Databricks-Workspace-Id', workspaceId);
662
- }
663
- headers.set('User-Agent', this.userAgent);
664
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
665
- const respBody = await executeHttpCall({
666
- request: httpReq,
667
- httpClient,
668
- logger: this.logger,
669
- });
670
- resp = parseResponse(respBody, unmarshalGenieListConversationsResponseSchema);
671
- };
672
- await executeCall(call, options);
673
- if (resp === undefined) {
674
- throw new Error('operation completed without a result.');
675
- }
676
- return resp;
677
- }
678
- /** List evaluation results for a specific evaluation run. */
679
- async genieListEvalResults(req, options) {
680
- const { host, workspaceId, httpClient } = await this.resolveConfig();
681
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs/${req.evalRunId ?? ''}/results`;
682
- const params = new URLSearchParams();
683
- if (req.pageSize !== undefined) {
684
- params.append('page_size', String(req.pageSize));
685
- }
686
- if (req.pageToken !== undefined) {
687
- params.append('page_token', req.pageToken);
688
- }
689
- const query = params.toString();
690
- const fullUrl = query !== '' ? `${url}?${query}` : url;
691
- let resp;
692
- const call = async (callSignal) => {
693
- const headers = new Headers();
694
- if (workspaceId !== undefined) {
695
- headers.set('X-Databricks-Workspace-Id', workspaceId);
696
- }
697
- headers.set('User-Agent', this.userAgent);
698
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
699
- const respBody = await executeHttpCall({
700
- request: httpReq,
701
- httpClient,
702
- logger: this.logger,
703
- });
704
- resp = parseResponse(respBody, unmarshalGenieListEvalResultsResponseSchema);
705
- };
706
- await executeCall(call, options);
707
- if (resp === undefined) {
708
- throw new Error('operation completed without a result.');
709
- }
710
- return resp;
711
- }
712
- /** Lists all evaluation runs in a space. */
713
- async genieListEvalRuns(req, options) {
714
- const { host, workspaceId, httpClient } = await this.resolveConfig();
715
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/eval-runs`;
716
- const params = new URLSearchParams();
717
- if (req.pageSize !== undefined) {
718
- params.append('page_size', String(req.pageSize));
719
- }
720
- if (req.pageToken !== undefined) {
721
- params.append('page_token', req.pageToken);
722
- }
723
- const query = params.toString();
724
- const fullUrl = query !== '' ? `${url}?${query}` : url;
725
- let resp;
726
- const call = async (callSignal) => {
727
- const headers = new Headers();
728
- if (workspaceId !== undefined) {
729
- headers.set('X-Databricks-Workspace-Id', workspaceId);
730
- }
731
- headers.set('User-Agent', this.userAgent);
732
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
733
- const respBody = await executeHttpCall({
734
- request: httpReq,
735
- httpClient,
736
- logger: this.logger,
737
- });
738
- resp = parseResponse(respBody, unmarshalGenieListEvalRunsResponseSchema);
739
- };
740
- await executeCall(call, options);
741
- if (resp === undefined) {
742
- throw new Error('operation completed without a result.');
743
- }
744
- return resp;
745
- }
746
- /** List comments on a specific conversation message. */
747
- async genieListMessageComments(req, options) {
748
- const { host, workspaceId, httpClient } = await this.resolveConfig();
749
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/comments`;
750
- const params = new URLSearchParams();
751
- if (req.pageSize !== undefined) {
752
- params.append('page_size', String(req.pageSize));
753
- }
754
- if (req.pageToken !== undefined) {
755
- params.append('page_token', req.pageToken);
756
- }
757
- const query = params.toString();
758
- const fullUrl = query !== '' ? `${url}?${query}` : url;
759
- let resp;
760
- const call = async (callSignal) => {
761
- const headers = new Headers();
762
- if (workspaceId !== undefined) {
763
- headers.set('X-Databricks-Workspace-Id', workspaceId);
764
- }
765
- headers.set('User-Agent', this.userAgent);
766
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
767
- const respBody = await executeHttpCall({
768
- request: httpReq,
769
- httpClient,
770
- logger: this.logger,
771
- });
772
- resp = parseResponse(respBody, unmarshalGenieListMessageCommentsResponseSchema);
773
- };
774
- await executeCall(call, options);
775
- if (resp === undefined) {
776
- throw new Error('operation completed without a result.');
777
- }
778
- return resp;
779
- }
780
- /** Get list of Genie Spaces. */
781
- async genieListSpaces(req, options) {
782
- const { host, workspaceId, httpClient } = await this.resolveConfig();
783
- const url = `${host}/api/2.0/genie/spaces`;
784
- const params = new URLSearchParams();
785
- if (req.pageSize !== undefined) {
786
- params.append('page_size', String(req.pageSize));
787
- }
788
- if (req.pageToken !== undefined) {
789
- params.append('page_token', req.pageToken);
790
- }
791
- const query = params.toString();
792
- const fullUrl = query !== '' ? `${url}?${query}` : url;
793
- let resp;
794
- const call = async (callSignal) => {
795
- const headers = new Headers();
796
- if (workspaceId !== undefined) {
797
- headers.set('X-Databricks-Workspace-Id', workspaceId);
798
- }
799
- headers.set('User-Agent', this.userAgent);
800
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
801
- const respBody = await executeHttpCall({
802
- request: httpReq,
803
- httpClient,
804
- logger: this.logger,
805
- });
806
- resp = parseResponse(respBody, unmarshalGenieListSpacesResponseSchema);
807
- };
808
- await executeCall(call, options);
809
- if (resp === undefined) {
810
- throw new Error('operation completed without a result.');
811
- }
812
- return resp;
813
- }
814
- /** Send feedback for a message. */
815
- async genieSendMessageFeedback(req, options) {
816
- const { host, workspaceId, httpClient } = await this.resolveConfig();
817
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/conversations/${req.conversationId ?? ''}/messages/${req.messageId ?? ''}/feedback`;
818
- const body = marshalRequest(req, marshalGenieSendMessageFeedbackRequestSchema);
819
- const call = async (callSignal) => {
820
- const headers = new Headers({ 'Content-Type': 'application/json' });
821
- if (workspaceId !== undefined) {
822
- headers.set('X-Databricks-Workspace-Id', workspaceId);
823
- }
824
- headers.set('User-Agent', this.userAgent);
825
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
826
- await executeHttpCall({
827
- request: httpReq,
828
- httpClient,
829
- logger: this.logger,
830
- });
831
- };
832
- await executeCall(call, options);
833
- }
834
- /** Start a new conversation. */
835
- async genieStartConversationBase(req, options) {
836
- const { host, workspaceId, httpClient } = await this.resolveConfig();
837
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}/start-conversation`;
838
- const body = marshalRequest(req, marshalGenieStartConversationRequestSchema);
839
- let resp;
840
- const call = async (callSignal) => {
841
- const headers = new Headers({ 'Content-Type': 'application/json' });
842
- if (workspaceId !== undefined) {
843
- headers.set('X-Databricks-Workspace-Id', workspaceId);
844
- }
845
- headers.set('User-Agent', this.userAgent);
846
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
847
- const respBody = await executeHttpCall({
848
- request: httpReq,
849
- httpClient,
850
- logger: this.logger,
851
- });
852
- resp = parseResponse(respBody, unmarshalGenieStartConversationResponseSchema);
853
- };
854
- await executeCall(call, options);
855
- if (resp === undefined) {
856
- throw new Error('operation completed without a result.');
857
- }
858
- return resp;
859
- }
860
- /** Start a new conversation. */
861
- async genieStartConversation(req, options) {
862
- const resp = await this.genieStartConversationBase(req, options);
863
- if (resp.messageId === undefined) {
864
- throw new Error('response field messageId required for polling is missing');
865
- }
866
- if (resp.conversationId === undefined) {
867
- throw new Error('response field conversationId required for polling is missing');
868
- }
869
- if (req.spaceId === undefined) {
870
- throw new Error('request field spaceId required for polling is missing');
871
- }
872
- return new GenieStartConversationWaiter(this, resp.messageId, resp.conversationId, req.spaceId);
873
- }
874
- /** Move a Genie Space to the trash. */
875
- async genieTrashSpace(req, options) {
876
- const { host, workspaceId, httpClient } = await this.resolveConfig();
877
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}`;
878
- const call = async (callSignal) => {
879
- const headers = new Headers();
880
- if (workspaceId !== undefined) {
881
- headers.set('X-Databricks-Workspace-Id', workspaceId);
882
- }
883
- headers.set('User-Agent', this.userAgent);
884
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
885
- await executeHttpCall({
886
- request: httpReq,
887
- httpClient,
888
- logger: this.logger,
889
- });
890
- };
891
- await executeCall(call, options);
892
- }
893
- /** Updates a Genie space with a serialized payload. */
894
- async updateSpace(req, options) {
895
- const { host, workspaceId, httpClient } = await this.resolveConfig();
896
- const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ''}`;
897
- const body = marshalRequest(req, marshalGenieUpdateSpaceRequestSchema);
898
- let resp;
899
- const call = async (callSignal) => {
900
- const headers = new Headers({ 'Content-Type': 'application/json' });
901
- if (workspaceId !== undefined) {
902
- headers.set('X-Databricks-Workspace-Id', workspaceId);
903
- }
904
- headers.set('User-Agent', this.userAgent);
905
- const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
906
- const respBody = await executeHttpCall({
907
- request: httpReq,
908
- httpClient,
909
- logger: this.logger,
910
- });
911
- resp = parseResponse(respBody, unmarshalGenieSpaceSchema);
912
- };
913
- await executeCall(call, options);
914
- if (resp === undefined) {
915
- throw new Error('operation completed without a result.');
916
- }
917
- return resp;
918
- }
919
- }
920
- export class GenieCreateConversationMessageWaiter {
921
- client;
922
- messageId;
923
- conversationId;
924
- spaceId;
925
- constructor(client, messageId, conversationId, spaceId) {
926
- this.client = client;
927
- this.messageId = messageId;
928
- this.conversationId = conversationId;
929
- this.spaceId = spaceId;
930
- }
931
- /**
932
- * Polls until the operation reaches a terminal state.
933
- *
934
- * Throws if a failure state is reached.
935
- */
936
- async wait(options) {
937
- let result;
938
- const call = async (callSignal) => {
939
- const pollResp = await this.client.genieGetConversationMessage({
940
- messageId: this.messageId,
941
- conversationId: this.conversationId,
942
- spaceId: this.spaceId,
943
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
944
- const status = pollResp.status;
945
- if (status === undefined) {
946
- throw new Error('response missing required status field');
947
- }
948
- switch (status) {
949
- case MessageStatus_MessageStatus.COMPLETED:
950
- result = pollResp;
951
- return;
952
- case MessageStatus_MessageStatus.FAILED: {
953
- const msg = '(no message)';
954
- throw new Error(`terminal state ${status}: ${msg}`);
955
- }
956
- default:
957
- throw new StillRunningError();
958
- }
959
- };
960
- await executeWait(call, options);
961
- if (result === undefined) {
962
- throw new Error('operation completed without a result.');
963
- }
964
- return result;
965
- }
966
- /** Checks whether the operation has reached a terminal state. */
967
- async done(options) {
968
- const pollResp = await this.client.genieGetConversationMessage({
969
- messageId: this.messageId,
970
- conversationId: this.conversationId,
971
- spaceId: this.spaceId,
972
- }, options);
973
- const status = pollResp.status;
974
- if (status === undefined) {
975
- throw new Error('response missing required status field');
976
- }
977
- switch (status) {
978
- case MessageStatus_MessageStatus.COMPLETED:
979
- case MessageStatus_MessageStatus.FAILED:
980
- return true;
981
- default:
982
- return false;
983
- }
984
- }
985
- }
986
- export class GenieStartConversationWaiter {
987
- client;
988
- messageId;
989
- conversationId;
990
- spaceId;
991
- constructor(client, messageId, conversationId, spaceId) {
992
- this.client = client;
993
- this.messageId = messageId;
994
- this.conversationId = conversationId;
995
- this.spaceId = spaceId;
996
- }
997
- /**
998
- * Polls until the operation reaches a terminal state.
999
- *
1000
- * Throws if a failure state is reached.
1001
- */
1002
- async wait(options) {
1003
- let result;
1004
- const call = async (callSignal) => {
1005
- const pollResp = await this.client.genieGetConversationMessage({
1006
- messageId: this.messageId,
1007
- conversationId: this.conversationId,
1008
- spaceId: this.spaceId,
1009
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
1010
- const status = pollResp.status;
1011
- if (status === undefined) {
1012
- throw new Error('response missing required status field');
1013
- }
1014
- switch (status) {
1015
- case MessageStatus_MessageStatus.COMPLETED:
1016
- result = pollResp;
1017
- return;
1018
- case MessageStatus_MessageStatus.FAILED: {
1019
- const msg = '(no message)';
1020
- throw new Error(`terminal state ${status}: ${msg}`);
1021
- }
1022
- default:
1023
- throw new StillRunningError();
1024
- }
1025
- };
1026
- await executeWait(call, options);
1027
- if (result === undefined) {
1028
- throw new Error('operation completed without a result.');
1029
- }
1030
- return result;
1031
- }
1032
- /** Checks whether the operation has reached a terminal state. */
1033
- async done(options) {
1034
- const pollResp = await this.client.genieGetConversationMessage({
1035
- messageId: this.messageId,
1036
- conversationId: this.conversationId,
1037
- spaceId: this.spaceId,
1038
- }, options);
1039
- const status = pollResp.status;
1040
- if (status === undefined) {
1041
- throw new Error('response missing required status field');
1042
- }
1043
- switch (status) {
1044
- case MessageStatus_MessageStatus.COMPLETED:
1045
- case MessageStatus_MessageStatus.FAILED:
1046
- return true;
1047
- default:
1048
- return false;
1049
- }
1050
- }
1051
- }
14
+ var GenieClient = class {
15
+ options;
16
+ logger;
17
+ userAgent;
18
+ config;
19
+ constructor(options) {
20
+ this.options = options;
21
+ this.logger = options.logger ?? new NoOpLogger();
22
+ this.userAgent = createDefault().with(PACKAGE_SEGMENT).with({
23
+ key: "sdk-js-auth",
24
+ value: VERSION
25
+ }).with({
26
+ key: "auth",
27
+ value: options.credentials?.name() ?? "default"
28
+ }).toString();
29
+ }
30
+ resolveConfig() {
31
+ this.config ??= resolveClientConfig(this.options);
32
+ return this.config;
33
+ }
34
+ /** Creates a Genie space from a serialized payload. */
35
+ async createSpace(req, options) {
36
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
37
+ const url = `${host}/api/2.0/genie/spaces`;
38
+ const body = marshalRequest(req, marshalGenieCreateSpaceRequestSchema);
39
+ let resp;
40
+ const call = async (callSignal) => {
41
+ const headers = new Headers({ "Content-Type": "application/json" });
42
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
43
+ headers.set("User-Agent", this.userAgent);
44
+ resp = parseResponse(await executeHttpCall({
45
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
46
+ httpClient,
47
+ logger: this.logger
48
+ }), unmarshalGenieSpaceSchema);
49
+ };
50
+ await executeCall(call, options);
51
+ if (resp === void 0) throw new Error("operation completed without a result.");
52
+ return resp;
53
+ }
54
+ /**
55
+ * Download a rendered image of a message visualization attachment.
56
+ * The response body is the raw PNG image, not a JSON payload.
57
+ * This is only available if the attachment is a visualization and the message status is `COMPLETED`.
58
+ * This endpoint is not supported for Private Link workspaces.
59
+ */
60
+ async downloadMessageAttachmentVisualization(req, options) {
61
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
62
+ const url = `${host}/api/2.0/genie/${req.name ?? ""}/download-visualization`;
63
+ let resp;
64
+ const call = async (callSignal) => {
65
+ const headers = new Headers();
66
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
67
+ headers.set("User-Agent", this.userAgent);
68
+ resp = { contents: (await sendAndCheckError({
69
+ request: buildHttpRequest("GET", url, headers, callSignal),
70
+ httpClient,
71
+ logger: this.logger
72
+ })).body ?? void 0 };
73
+ };
74
+ await executeCall(call, options);
75
+ if (resp === void 0) throw new Error("operation completed without a result.");
76
+ return resp;
77
+ }
78
+ /**
79
+ * Create new message in a [conversation](:method:genie/startconversation).
80
+ * The AI response uses all previously created messages in the conversation to respond.
81
+ */
82
+ async genieCreateConversationMessageBase(req, options) {
83
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
84
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages`;
85
+ const body = marshalRequest(req, marshalGenieCreateConversationMessageRequestSchema);
86
+ let resp;
87
+ const call = async (callSignal) => {
88
+ const headers = new Headers({ "Content-Type": "application/json" });
89
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
90
+ headers.set("User-Agent", this.userAgent);
91
+ resp = parseResponse(await executeHttpCall({
92
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
93
+ httpClient,
94
+ logger: this.logger
95
+ }), unmarshalGenieMessageSchema);
96
+ };
97
+ await executeCall(call, options);
98
+ if (resp === void 0) throw new Error("operation completed without a result.");
99
+ return resp;
100
+ }
101
+ /**
102
+ * Create new message in a [conversation](:method:genie/startconversation).
103
+ * The AI response uses all previously created messages in the conversation to respond.
104
+ */
105
+ async genieCreateConversationMessage(req, options) {
106
+ const resp = await this.genieCreateConversationMessageBase(req, options);
107
+ if (resp.messageId === void 0) throw new Error("response field messageId required for polling is missing");
108
+ if (req.conversationId === void 0) throw new Error("request field conversationId required for polling is missing");
109
+ if (req.spaceId === void 0) throw new Error("request field spaceId required for polling is missing");
110
+ return new GenieCreateConversationMessageWaiter(this, resp.messageId, req.conversationId, req.spaceId);
111
+ }
112
+ /** Create and run evaluations for multiple benchmark questions in a Genie space. */
113
+ async genieCreateEvalRun(req, options) {
114
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
115
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/eval-runs`;
116
+ const body = marshalRequest(req, marshalGenieCreateEvalRunRequestSchema);
117
+ let resp;
118
+ const call = async (callSignal) => {
119
+ const headers = new Headers({ "Content-Type": "application/json" });
120
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
121
+ headers.set("User-Agent", this.userAgent);
122
+ resp = parseResponse(await executeHttpCall({
123
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
124
+ httpClient,
125
+ logger: this.logger
126
+ }), unmarshalGenieEvalRunResponseSchema);
127
+ };
128
+ await executeCall(call, options);
129
+ if (resp === void 0) throw new Error("operation completed without a result.");
130
+ return resp;
131
+ }
132
+ /** Create a comment on a conversation message. */
133
+ async genieCreateMessageComment(req, options) {
134
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
135
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/comments`;
136
+ const body = marshalRequest(req, marshalGenieCreateMessageCommentRequestSchema);
137
+ let resp;
138
+ const call = async (callSignal) => {
139
+ const headers = new Headers({ "Content-Type": "application/json" });
140
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
141
+ headers.set("User-Agent", this.userAgent);
142
+ resp = parseResponse(await executeHttpCall({
143
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
144
+ httpClient,
145
+ logger: this.logger
146
+ }), unmarshalGenieMessageCommentSchema);
147
+ };
148
+ await executeCall(call, options);
149
+ if (resp === void 0) throw new Error("operation completed without a result.");
150
+ return resp;
151
+ }
152
+ /** Delete a conversation. */
153
+ async genieDeleteConversation(req, options) {
154
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
155
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}`;
156
+ const call = async (callSignal) => {
157
+ const headers = new Headers();
158
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
159
+ headers.set("User-Agent", this.userAgent);
160
+ await executeHttpCall({
161
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
162
+ httpClient,
163
+ logger: this.logger
164
+ });
165
+ };
166
+ await executeCall(call, options);
167
+ }
168
+ /** Delete a conversation message. */
169
+ async genieDeleteConversationMessage(req, options) {
170
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
171
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}`;
172
+ const call = async (callSignal) => {
173
+ const headers = new Headers();
174
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
175
+ headers.set("User-Agent", this.userAgent);
176
+ await executeHttpCall({
177
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
178
+ httpClient,
179
+ logger: this.logger
180
+ });
181
+ };
182
+ await executeCall(call, options);
183
+ }
184
+ /** Execute the SQL for a message query attachment. Use this API when the query attachment has expired and needs to be re-executed. */
185
+ async genieExecuteMessageAttachmentQuery(req, options) {
186
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
187
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/attachments/${req.attachmentId ?? ""}/execute-query`;
188
+ const body = marshalRequest(req, marshalGenieExecuteMessageAttachmentQueryRequestSchema);
189
+ let resp;
190
+ const call = async (callSignal) => {
191
+ const headers = new Headers({ "Content-Type": "application/json" });
192
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
193
+ headers.set("User-Agent", this.userAgent);
194
+ resp = parseResponse(await executeHttpCall({
195
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
196
+ httpClient,
197
+ logger: this.logger
198
+ }), unmarshalGenieGetMessageQueryResultResponseSchema);
199
+ };
200
+ await executeCall(call, options);
201
+ if (resp === void 0) throw new Error("operation completed without a result.");
202
+ return resp;
203
+ }
204
+ /** DEPRECATED: Use [Execute Message Attachment Query](:method:genie/executemessageattachmentquery) instead. */
205
+ async genieExecuteMessageQuery(req, options) {
206
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
207
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/execute-query`;
208
+ const body = marshalRequest(req, marshalGenieExecuteMessageQueryRequestSchema);
209
+ let resp;
210
+ const call = async (callSignal) => {
211
+ const headers = new Headers({ "Content-Type": "application/json" });
212
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
213
+ headers.set("User-Agent", this.userAgent);
214
+ resp = parseResponse(await executeHttpCall({
215
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
216
+ httpClient,
217
+ logger: this.logger
218
+ }), unmarshalGenieGetMessageQueryResultResponseSchema);
219
+ };
220
+ await executeCall(call, options);
221
+ if (resp === void 0) throw new Error("operation completed without a result.");
222
+ return resp;
223
+ }
224
+ /**
225
+ * 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.
226
+ * The query result is stored in an external link and can be retrieved using the [Get Download Full Query Result](:method:genie/getdownloadfullqueryresult) API.
227
+ * Both `download_id` and `download_id_signature` must be provided when calling the Get endpoint.
228
+ *
229
+ * ----
230
+ *
231
+ * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
232
+ *
233
+ * When you use the `EXTERNAL_LINKS` disposition, a
234
+ * short-lived, URL is generated, which can be
235
+ * used to download the results directly
236
+ * from . As a
237
+ * short-lived is
238
+ * embedded in this URL, you should protect
239
+ * the URL.
240
+ *
241
+ * Because URLs are already generated with
242
+ * embedded temporary s,
243
+ * you must not set an `Authorization` header in the download requests.
244
+ *
245
+ * See [Execute Statement](:method:statementexecution/executestatement) for more details.
246
+ *
247
+ * ----
248
+ */
249
+ async genieGenerateDownloadFullQueryResult(req, options) {
250
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
251
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/attachments/${req.attachmentId ?? ""}/downloads`;
252
+ const body = marshalRequest(req, marshalGenieGenerateDownloadFullQueryResultRequestSchema);
253
+ let resp;
254
+ const call = async (callSignal) => {
255
+ const headers = new Headers({ "Content-Type": "application/json" });
256
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
257
+ headers.set("User-Agent", this.userAgent);
258
+ resp = parseResponse(await executeHttpCall({
259
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
260
+ httpClient,
261
+ logger: this.logger
262
+ }), unmarshalGenieGenerateDownloadFullQueryResultResponseSchema);
263
+ };
264
+ await executeCall(call, options);
265
+ if (resp === void 0) throw new Error("operation completed without a result.");
266
+ return resp;
267
+ }
268
+ /** Get message from conversation. */
269
+ async genieGetConversationMessage(req, options) {
270
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
271
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}`;
272
+ let resp;
273
+ const call = async (callSignal) => {
274
+ const headers = new Headers();
275
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
276
+ headers.set("User-Agent", this.userAgent);
277
+ resp = parseResponse(await executeHttpCall({
278
+ request: buildHttpRequest("GET", url, headers, callSignal),
279
+ httpClient,
280
+ logger: this.logger
281
+ }), unmarshalGenieMessageSchema);
282
+ };
283
+ await executeCall(call, options);
284
+ if (resp === void 0) throw new Error("operation completed without a result.");
285
+ return resp;
286
+ }
287
+ /**
288
+ * 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.
289
+ * Both `download_id` and `download_id_signature` are required to call this endpoint.
290
+ * 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.
291
+ *
292
+ * ----
293
+ *
294
+ * ### **Warning: Databricks strongly recommends that you protect the URLs that are returned by the `EXTERNAL_LINKS` disposition.**
295
+ *
296
+ * When you use the `EXTERNAL_LINKS` disposition, a
297
+ * short-lived, URL is generated, which can be
298
+ * used to download the results directly
299
+ * from . As a
300
+ * short-lived is
301
+ * embedded in this URL, you should protect
302
+ * the URL.
303
+ *
304
+ * Because URLs are already generated with
305
+ * embedded temporary s,
306
+ * you must not set an `Authorization` header in the download requests.
307
+ *
308
+ * See [Execute Statement](:method:statementexecution/executestatement) for more details.
309
+ *
310
+ * ----
311
+ */
312
+ async genieGetDownloadFullQueryResult(req, options) {
313
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
314
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/attachments/${req.attachmentId ?? ""}/downloads/${req.downloadId ?? ""}`;
315
+ const params = new URLSearchParams();
316
+ if (req.downloadIdSignature !== void 0) params.append("download_id_signature", req.downloadIdSignature);
317
+ const query = params.toString();
318
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
319
+ let resp;
320
+ const call = async (callSignal) => {
321
+ const headers = new Headers();
322
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
323
+ headers.set("User-Agent", this.userAgent);
324
+ resp = parseResponse(await executeHttpCall({
325
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
326
+ httpClient,
327
+ logger: this.logger
328
+ }), unmarshalGenieGetDownloadFullQueryResultResponseSchema);
329
+ };
330
+ await executeCall(call, options);
331
+ if (resp === void 0) throw new Error("operation completed without a result.");
332
+ return resp;
333
+ }
334
+ /** Get details for evaluation results. */
335
+ async genieGetEvalResultDetails(req, options) {
336
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
337
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/eval-runs/${req.evalRunId ?? ""}/results/${req.resultId ?? ""}`;
338
+ let resp;
339
+ const call = async (callSignal) => {
340
+ const headers = new Headers();
341
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
342
+ headers.set("User-Agent", this.userAgent);
343
+ resp = parseResponse(await executeHttpCall({
344
+ request: buildHttpRequest("GET", url, headers, callSignal),
345
+ httpClient,
346
+ logger: this.logger
347
+ }), unmarshalGenieEvalResultDetailsSchema);
348
+ };
349
+ await executeCall(call, options);
350
+ if (resp === void 0) throw new Error("operation completed without a result.");
351
+ return resp;
352
+ }
353
+ /** Get evaluation run details. */
354
+ async genieGetEvalRun(req, options) {
355
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
356
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/eval-runs/${req.evalRunId ?? ""}`;
357
+ let resp;
358
+ const call = async (callSignal) => {
359
+ const headers = new Headers();
360
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
361
+ headers.set("User-Agent", this.userAgent);
362
+ resp = parseResponse(await executeHttpCall({
363
+ request: buildHttpRequest("GET", url, headers, callSignal),
364
+ httpClient,
365
+ logger: this.logger
366
+ }), unmarshalGenieEvalRunResponseSchema);
367
+ };
368
+ await executeCall(call, options);
369
+ if (resp === void 0) throw new Error("operation completed without a result.");
370
+ return resp;
371
+ }
372
+ /**
373
+ * Get the result of SQL query if the message has a query attachment.
374
+ * This is only available if a message has a query attachment and the message status is `EXECUTING_QUERY` OR `COMPLETED`.
375
+ */
376
+ async genieGetMessageAttachmentQueryResult(req, options) {
377
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
378
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/attachments/${req.attachmentId ?? ""}/query-result`;
379
+ let resp;
380
+ const call = async (callSignal) => {
381
+ const headers = new Headers();
382
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
383
+ headers.set("User-Agent", this.userAgent);
384
+ resp = parseResponse(await executeHttpCall({
385
+ request: buildHttpRequest("GET", url, headers, callSignal),
386
+ httpClient,
387
+ logger: this.logger
388
+ }), unmarshalGenieGetMessageQueryResultResponseSchema);
389
+ };
390
+ await executeCall(call, options);
391
+ if (resp === void 0) throw new Error("operation completed without a result.");
392
+ return resp;
393
+ }
394
+ /** DEPRECATED: Use [Get Message Attachment Query Result](:method:genie/getmessageattachmentqueryresult) instead. */
395
+ async genieGetMessageQueryResult(req, options) {
396
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
397
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/query-result`;
398
+ let resp;
399
+ const call = async (callSignal) => {
400
+ const headers = new Headers();
401
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
402
+ headers.set("User-Agent", this.userAgent);
403
+ resp = parseResponse(await executeHttpCall({
404
+ request: buildHttpRequest("GET", url, headers, callSignal),
405
+ httpClient,
406
+ logger: this.logger
407
+ }), unmarshalGenieGetMessageQueryResultResponseSchema);
408
+ };
409
+ await executeCall(call, options);
410
+ if (resp === void 0) throw new Error("operation completed without a result.");
411
+ return resp;
412
+ }
413
+ /** DEPRECATED: Use [Get Message Attachment Query Result](:method:genie/getmessageattachmentqueryresult) instead. */
414
+ async genieGetQueryResultByAttachment(req, options) {
415
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
416
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/query-result/${req.attachmentId ?? ""}`;
417
+ let resp;
418
+ const call = async (callSignal) => {
419
+ const headers = new Headers();
420
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
421
+ headers.set("User-Agent", this.userAgent);
422
+ resp = parseResponse(await executeHttpCall({
423
+ request: buildHttpRequest("GET", url, headers, callSignal),
424
+ httpClient,
425
+ logger: this.logger
426
+ }), unmarshalGenieGetMessageQueryResultResponseSchema);
427
+ };
428
+ await executeCall(call, options);
429
+ if (resp === void 0) throw new Error("operation completed without a result.");
430
+ return resp;
431
+ }
432
+ /** Get details of a Genie Space. */
433
+ async genieGetSpace(req, options) {
434
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
435
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}`;
436
+ const params = new URLSearchParams();
437
+ if (req.includeSerializedSpace !== void 0) params.append("include_serialized_space", String(req.includeSerializedSpace));
438
+ const query = params.toString();
439
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
440
+ let resp;
441
+ const call = async (callSignal) => {
442
+ const headers = new Headers();
443
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
444
+ headers.set("User-Agent", this.userAgent);
445
+ resp = parseResponse(await executeHttpCall({
446
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
447
+ httpClient,
448
+ logger: this.logger
449
+ }), unmarshalGenieSpaceSchema);
450
+ };
451
+ await executeCall(call, options);
452
+ if (resp === void 0) throw new Error("operation completed without a result.");
453
+ return resp;
454
+ }
455
+ /** List all comments across all messages in a conversation. */
456
+ async genieListConversationComments(req, options) {
457
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
458
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/list-comments`;
459
+ const params = new URLSearchParams();
460
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
461
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
462
+ const query = params.toString();
463
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
464
+ let resp;
465
+ const call = async (callSignal) => {
466
+ const headers = new Headers();
467
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
468
+ headers.set("User-Agent", this.userAgent);
469
+ resp = parseResponse(await executeHttpCall({
470
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
471
+ httpClient,
472
+ logger: this.logger
473
+ }), unmarshalGenieListConversationCommentsResponseSchema);
474
+ };
475
+ await executeCall(call, options);
476
+ if (resp === void 0) throw new Error("operation completed without a result.");
477
+ return resp;
478
+ }
479
+ /** List messages in a conversation */
480
+ async genieListConversationMessages(req, options) {
481
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
482
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages`;
483
+ const params = new URLSearchParams();
484
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
485
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
486
+ const query = params.toString();
487
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
488
+ let resp;
489
+ const call = async (callSignal) => {
490
+ const headers = new Headers();
491
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
492
+ headers.set("User-Agent", this.userAgent);
493
+ resp = parseResponse(await executeHttpCall({
494
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
495
+ httpClient,
496
+ logger: this.logger
497
+ }), unmarshalGenieListConversationMessagesResponseSchema);
498
+ };
499
+ await executeCall(call, options);
500
+ if (resp === void 0) throw new Error("operation completed without a result.");
501
+ return resp;
502
+ }
503
+ /** Get a list of conversations in a Genie Space. */
504
+ async genieListConversations(req, options) {
505
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
506
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations`;
507
+ const params = new URLSearchParams();
508
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
509
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
510
+ if (req.includeAll !== void 0) params.append("include_all", String(req.includeAll));
511
+ const query = params.toString();
512
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
513
+ let resp;
514
+ const call = async (callSignal) => {
515
+ const headers = new Headers();
516
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
517
+ headers.set("User-Agent", this.userAgent);
518
+ resp = parseResponse(await executeHttpCall({
519
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
520
+ httpClient,
521
+ logger: this.logger
522
+ }), unmarshalGenieListConversationsResponseSchema);
523
+ };
524
+ await executeCall(call, options);
525
+ if (resp === void 0) throw new Error("operation completed without a result.");
526
+ return resp;
527
+ }
528
+ /** List evaluation results for a specific evaluation run. */
529
+ async genieListEvalResults(req, options) {
530
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
531
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/eval-runs/${req.evalRunId ?? ""}/results`;
532
+ const params = new URLSearchParams();
533
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
534
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
535
+ const query = params.toString();
536
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
537
+ let resp;
538
+ const call = async (callSignal) => {
539
+ const headers = new Headers();
540
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
541
+ headers.set("User-Agent", this.userAgent);
542
+ resp = parseResponse(await executeHttpCall({
543
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
544
+ httpClient,
545
+ logger: this.logger
546
+ }), unmarshalGenieListEvalResultsResponseSchema);
547
+ };
548
+ await executeCall(call, options);
549
+ if (resp === void 0) throw new Error("operation completed without a result.");
550
+ return resp;
551
+ }
552
+ /** Lists all evaluation runs in a space. */
553
+ async genieListEvalRuns(req, options) {
554
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
555
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/eval-runs`;
556
+ const params = new URLSearchParams();
557
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
558
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
559
+ const query = params.toString();
560
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
561
+ let resp;
562
+ const call = async (callSignal) => {
563
+ const headers = new Headers();
564
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
565
+ headers.set("User-Agent", this.userAgent);
566
+ resp = parseResponse(await executeHttpCall({
567
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
568
+ httpClient,
569
+ logger: this.logger
570
+ }), unmarshalGenieListEvalRunsResponseSchema);
571
+ };
572
+ await executeCall(call, options);
573
+ if (resp === void 0) throw new Error("operation completed without a result.");
574
+ return resp;
575
+ }
576
+ /** List comments on a specific conversation message. */
577
+ async genieListMessageComments(req, options) {
578
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
579
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/comments`;
580
+ const params = new URLSearchParams();
581
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
582
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
583
+ const query = params.toString();
584
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
585
+ let resp;
586
+ const call = async (callSignal) => {
587
+ const headers = new Headers();
588
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
589
+ headers.set("User-Agent", this.userAgent);
590
+ resp = parseResponse(await executeHttpCall({
591
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
592
+ httpClient,
593
+ logger: this.logger
594
+ }), unmarshalGenieListMessageCommentsResponseSchema);
595
+ };
596
+ await executeCall(call, options);
597
+ if (resp === void 0) throw new Error("operation completed without a result.");
598
+ return resp;
599
+ }
600
+ /** Get list of Genie Spaces. */
601
+ async genieListSpaces(req, options) {
602
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
603
+ const url = `${host}/api/2.0/genie/spaces`;
604
+ const params = new URLSearchParams();
605
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
606
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
607
+ const query = params.toString();
608
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
609
+ let resp;
610
+ const call = async (callSignal) => {
611
+ const headers = new Headers();
612
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
613
+ headers.set("User-Agent", this.userAgent);
614
+ resp = parseResponse(await executeHttpCall({
615
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
616
+ httpClient,
617
+ logger: this.logger
618
+ }), unmarshalGenieListSpacesResponseSchema);
619
+ };
620
+ await executeCall(call, options);
621
+ if (resp === void 0) throw new Error("operation completed without a result.");
622
+ return resp;
623
+ }
624
+ /** Send feedback for a message. */
625
+ async genieSendMessageFeedback(req, options) {
626
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
627
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/conversations/${req.conversationId ?? ""}/messages/${req.messageId ?? ""}/feedback`;
628
+ const body = marshalRequest(req, marshalGenieSendMessageFeedbackRequestSchema);
629
+ const call = async (callSignal) => {
630
+ const headers = new Headers({ "Content-Type": "application/json" });
631
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
632
+ headers.set("User-Agent", this.userAgent);
633
+ await executeHttpCall({
634
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
635
+ httpClient,
636
+ logger: this.logger
637
+ });
638
+ };
639
+ await executeCall(call, options);
640
+ }
641
+ /** Start a new conversation. */
642
+ async genieStartConversationBase(req, options) {
643
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
644
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}/start-conversation`;
645
+ const body = marshalRequest(req, marshalGenieStartConversationRequestSchema);
646
+ let resp;
647
+ const call = async (callSignal) => {
648
+ const headers = new Headers({ "Content-Type": "application/json" });
649
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
650
+ headers.set("User-Agent", this.userAgent);
651
+ resp = parseResponse(await executeHttpCall({
652
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
653
+ httpClient,
654
+ logger: this.logger
655
+ }), unmarshalGenieStartConversationResponseSchema);
656
+ };
657
+ await executeCall(call, options);
658
+ if (resp === void 0) throw new Error("operation completed without a result.");
659
+ return resp;
660
+ }
661
+ /** Start a new conversation. */
662
+ async genieStartConversation(req, options) {
663
+ const resp = await this.genieStartConversationBase(req, options);
664
+ if (resp.messageId === void 0) throw new Error("response field messageId required for polling is missing");
665
+ if (resp.conversationId === void 0) throw new Error("response field conversationId required for polling is missing");
666
+ if (req.spaceId === void 0) throw new Error("request field spaceId required for polling is missing");
667
+ return new GenieStartConversationWaiter(this, resp.messageId, resp.conversationId, req.spaceId);
668
+ }
669
+ /** Move a Genie Space to the trash. */
670
+ async genieTrashSpace(req, options) {
671
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
672
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}`;
673
+ const call = async (callSignal) => {
674
+ const headers = new Headers();
675
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
676
+ headers.set("User-Agent", this.userAgent);
677
+ await executeHttpCall({
678
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
679
+ httpClient,
680
+ logger: this.logger
681
+ });
682
+ };
683
+ await executeCall(call, options);
684
+ }
685
+ /** Updates a Genie space with a serialized payload. */
686
+ async updateSpace(req, options) {
687
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
688
+ const url = `${host}/api/2.0/genie/spaces/${req.spaceId ?? ""}`;
689
+ const body = marshalRequest(req, marshalGenieUpdateSpaceRequestSchema);
690
+ let resp;
691
+ const call = async (callSignal) => {
692
+ const headers = new Headers({ "Content-Type": "application/json" });
693
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
694
+ headers.set("User-Agent", this.userAgent);
695
+ resp = parseResponse(await executeHttpCall({
696
+ request: buildHttpRequest("PATCH", url, headers, callSignal, body),
697
+ httpClient,
698
+ logger: this.logger
699
+ }), unmarshalGenieSpaceSchema);
700
+ };
701
+ await executeCall(call, options);
702
+ if (resp === void 0) throw new Error("operation completed without a result.");
703
+ return resp;
704
+ }
705
+ };
706
+ var GenieCreateConversationMessageWaiter = class {
707
+ constructor(client, messageId, conversationId, spaceId) {
708
+ this.client = client;
709
+ this.messageId = messageId;
710
+ this.conversationId = conversationId;
711
+ this.spaceId = spaceId;
712
+ }
713
+ /**
714
+ * Polls until the operation reaches a terminal state.
715
+ *
716
+ * Throws if a failure state is reached.
717
+ */
718
+ async wait(options) {
719
+ let result;
720
+ const call = async (callSignal) => {
721
+ const pollResp = await this.client.genieGetConversationMessage({
722
+ messageId: this.messageId,
723
+ conversationId: this.conversationId,
724
+ spaceId: this.spaceId
725
+ }, callSignal !== void 0 ? { signal: callSignal } : void 0);
726
+ const status = pollResp.status;
727
+ if (status === void 0) throw new Error("response missing required status field");
728
+ switch (status) {
729
+ case MessageStatus_MessageStatus.COMPLETED:
730
+ result = pollResp;
731
+ return;
732
+ case MessageStatus_MessageStatus.FAILED: throw new Error(`terminal state ${status}: (no message)`);
733
+ default: throw new StillRunningError();
734
+ }
735
+ };
736
+ await executeWait(call, options);
737
+ if (result === void 0) throw new Error("operation completed without a result.");
738
+ return result;
739
+ }
740
+ /** Checks whether the operation has reached a terminal state. */
741
+ async done(options) {
742
+ const status = (await this.client.genieGetConversationMessage({
743
+ messageId: this.messageId,
744
+ conversationId: this.conversationId,
745
+ spaceId: this.spaceId
746
+ }, options)).status;
747
+ if (status === void 0) throw new Error("response missing required status field");
748
+ switch (status) {
749
+ case MessageStatus_MessageStatus.COMPLETED:
750
+ case MessageStatus_MessageStatus.FAILED: return true;
751
+ default: return false;
752
+ }
753
+ }
754
+ };
755
+ var GenieStartConversationWaiter = class {
756
+ constructor(client, messageId, conversationId, spaceId) {
757
+ this.client = client;
758
+ this.messageId = messageId;
759
+ this.conversationId = conversationId;
760
+ this.spaceId = spaceId;
761
+ }
762
+ /**
763
+ * Polls until the operation reaches a terminal state.
764
+ *
765
+ * Throws if a failure state is reached.
766
+ */
767
+ async wait(options) {
768
+ let result;
769
+ const call = async (callSignal) => {
770
+ const pollResp = await this.client.genieGetConversationMessage({
771
+ messageId: this.messageId,
772
+ conversationId: this.conversationId,
773
+ spaceId: this.spaceId
774
+ }, callSignal !== void 0 ? { signal: callSignal } : void 0);
775
+ const status = pollResp.status;
776
+ if (status === void 0) throw new Error("response missing required status field");
777
+ switch (status) {
778
+ case MessageStatus_MessageStatus.COMPLETED:
779
+ result = pollResp;
780
+ return;
781
+ case MessageStatus_MessageStatus.FAILED: throw new Error(`terminal state ${status}: (no message)`);
782
+ default: throw new StillRunningError();
783
+ }
784
+ };
785
+ await executeWait(call, options);
786
+ if (result === void 0) throw new Error("operation completed without a result.");
787
+ return result;
788
+ }
789
+ /** Checks whether the operation has reached a terminal state. */
790
+ async done(options) {
791
+ const status = (await this.client.genieGetConversationMessage({
792
+ messageId: this.messageId,
793
+ conversationId: this.conversationId,
794
+ spaceId: this.spaceId
795
+ }, options)).status;
796
+ if (status === void 0) throw new Error("response missing required status field");
797
+ switch (status) {
798
+ case MessageStatus_MessageStatus.COMPLETED:
799
+ case MessageStatus_MessageStatus.FAILED: return true;
800
+ default: return false;
801
+ }
802
+ }
803
+ };
804
+
805
+ //#endregion
806
+ export { GenieClient, GenieCreateConversationMessageWaiter, GenieStartConversationWaiter };
1052
807
  //# sourceMappingURL=client.js.map