@aignostics/sdk 3.5.1 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/dist/index.cjs CHANGED
@@ -3082,6 +3082,59 @@ var PlatformSDKHttp = class {
3082
3082
  handleRequestError(error);
3083
3083
  }
3084
3084
  }
3085
+ /**
3086
+ * Download an artifact file from a completed application run as a stream
3087
+ *
3088
+ * Prefer this method over `downloadArtifact` when downloading large (e.g. multi-gigabyte)
3089
+ * artifacts: instead of buffering the entire file into memory before returning it, this
3090
+ * method streams the artifact's bytes as they arrive, keeping memory usage low regardless
3091
+ * of the artifact's size.
3092
+ *
3093
+ * The download is performed with automatic retries for transient failures.
3094
+ * Non-retryable HTTP status codes (403, 404, 410, 422) will abort immediately.
3095
+ *
3096
+ * @param runId - The unique identifier of the application run
3097
+ * @param artifactId - The unique identifier of the artifact to download
3098
+ * @returns A promise that resolves to a Node.js `Readable` stream yielding the artifact's binary content
3099
+ * @throws {AuthenticationError} If no valid authentication token is available
3100
+ * @throws {APIError} If the API request fails (e.g., 403, 404, 410, 422, or other HTTP errors)
3101
+ * @throws {UnexpectedError} If a non-HTTP error occurs
3102
+ *
3103
+ * @example
3104
+ * ```typescript
3105
+ * import { pipeline } from 'node:stream/promises';
3106
+ * import { createWriteStream } from 'node:fs';
3107
+ *
3108
+ * const stream = await sdk.downloadArtifactStream('run-123', 'artifact-456');
3109
+ * await pipeline(stream, createWriteStream('output.bin'));
3110
+ * ```
3111
+ *
3112
+ * @remarks
3113
+ * Retries only cover failures at the initial-request stage (a non-2xx status surfaced from
3114
+ * the response headers before the body begins streaming). Once the response body has started
3115
+ * streaming, a mid-stream connection drop CANNOT be retried by this method — the consumer must
3116
+ * listen for the stream's `error` event and re-download if needed.
3117
+ */
3118
+ async downloadArtifactStream(runId, artifactId) {
3119
+ const client = await this.#getClient();
3120
+ try {
3121
+ const response = await downloadWithRetry(
3122
+ () => client.getArtifactUrlV1RunsRunIdArtifactsArtifactIdFileGet(
3123
+ {
3124
+ runId,
3125
+ artifactId
3126
+ },
3127
+ {
3128
+ responseType: "stream"
3129
+ }
3130
+ ),
3131
+ [403, 404, 410, 422]
3132
+ );
3133
+ return response.data;
3134
+ } catch (error) {
3135
+ handleRequestError(error);
3136
+ }
3137
+ }
3085
3138
  };
3086
3139
 
3087
3140
  // src/index.ts