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