@aviaryhq/cloudglue-js 0.5.9 → 0.6.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.
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnhancedResponseApi = void 0;
4
+ const error_1 = require("../error");
5
+ class EnhancedResponseApi {
6
+ constructor(api) {
7
+ this.api = api;
8
+ }
9
+ /**
10
+ * Create a new response using the Response API.
11
+ * This provides an OpenAI Responses-compatible interface for chat completions with video collections.
12
+ *
13
+ * @param params - Response creation parameters
14
+ * @returns The created response
15
+ */
16
+ async createResponse(params) {
17
+ return this.api.createResponse(params);
18
+ }
19
+ /**
20
+ * List all responses with pagination and filtering options.
21
+ *
22
+ * @param params - Optional pagination and filtering parameters
23
+ * @returns Paginated list of responses
24
+ */
25
+ async listResponses(params = {}) {
26
+ return this.api.listResponses({ queries: params });
27
+ }
28
+ /**
29
+ * Retrieve a specific response by its ID.
30
+ *
31
+ * @param responseId - The ID of the response to retrieve
32
+ * @returns The response object
33
+ */
34
+ async getResponse(responseId) {
35
+ return this.api.getResponse({ params: { id: responseId } });
36
+ }
37
+ /**
38
+ * Delete a response by ID.
39
+ * This operation is idempotent - deleting a non-existent response returns success.
40
+ *
41
+ * @param responseId - The ID of the response to delete
42
+ * @returns Deletion confirmation
43
+ */
44
+ async deleteResponse(responseId) {
45
+ return this.api.deleteResponse(undefined, { params: { id: responseId } });
46
+ }
47
+ /**
48
+ * Cancel a background response that is in progress.
49
+ * If the response is already completed, failed, or cancelled, this returns the response as-is.
50
+ *
51
+ * @param responseId - The ID of the response to cancel
52
+ * @returns The response object
53
+ */
54
+ async cancelResponse(responseId) {
55
+ return this.api.cancelResponse(undefined, { params: { id: responseId } });
56
+ }
57
+ /**
58
+ * Waits for a background response to complete by polling until it reaches
59
+ * a terminal state (completed, failed, or cancelled) or until maxAttempts is reached.
60
+ *
61
+ * @param responseId - The ID of the response to wait for
62
+ * @param options - Optional configuration for polling behavior
63
+ * @returns The final response object
64
+ * @throws {CloudGlueError} If the response fails or maxAttempts is reached
65
+ */
66
+ async waitForReady(responseId, options = {}) {
67
+ const { pollingInterval = 5000, maxAttempts = 36 } = options;
68
+ let attempts = 0;
69
+ while (attempts < maxAttempts) {
70
+ const response = await this.getResponse(responseId);
71
+ // If we've reached a terminal state, return the response
72
+ if (['completed', 'failed', 'cancelled'].includes(response.status)) {
73
+ if (response.status === 'failed') {
74
+ throw new error_1.CloudGlueError(`Response generation failed: ${response.error?.message || responseId}`);
75
+ }
76
+ return response;
77
+ }
78
+ // Wait for the polling interval before trying again
79
+ await new Promise((resolve) => setTimeout(resolve, pollingInterval));
80
+ attempts++;
81
+ }
82
+ throw new error_1.CloudGlueError(`Timeout waiting for response ${responseId} to complete after ${maxAttempts} attempts`);
83
+ }
84
+ }
85
+ exports.EnhancedResponseApi = EnhancedResponseApi;