Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [4.41.8]

- Fix: cap `waitUntilReady` polling delay at the remaining `pollingTimeout` budget to avoid delaying timeout expiration when `pollingInterval` exceeds remaining timeout

## [4.41.7]

- Add `summarization` to the speech understanding feature requests and responses (`SummarizationRequest`, `SummarizationResponse`): `summary_type`, `headline_length`, `approximate_chapters` and `effort`. The feature was already accepted by the API but missing from the SDK types, so setting it failed to type check
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assemblyai",
"version": "4.41.7",
"version": "4.41.8",
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription.",
"engines": {
"node": ">=18"
Expand Down
14 changes: 9 additions & 5 deletions src/services/transcripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ export class TranscriptService extends BaseService {
const transcript = await this.get(transcriptId);
if (transcript.status === "completed" || transcript.status === "error") {
return transcript;
} else if (
pollingTimeout > 0 &&
Date.now() - startTime > pollingTimeout
) {
throw new Error("Polling timeout");
}
if (pollingTimeout > 0) {
const elapsed = Date.now() - startTime;
if (elapsed >= pollingTimeout) {
throw new Error("Polling timeout");
}
const remaining = pollingTimeout - elapsed;
const sleepDelay = Math.min(pollingInterval, remaining);
await new Promise((resolve) => setTimeout(resolve, sleepDelay));
} else {
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/transcript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,20 @@ describe("transcript", () => {
fetchMock.resetMocks();
}, 5000);

it("waitUntilReady should cap polling delay at remaining pollingTimeout budget", async () => {
fetchMock.mockResponse(JSON.stringify({ status: "processing" }));
const startTime = Date.now();
const promise = assembly.transcripts.waitUntilReady(transcriptId, {
pollingInterval: 5_000,
pollingTimeout: 200,
});

await expect(promise).rejects.toThrow("Polling timeout");
const duration = Date.now() - startTime;
expect(duration).toBeLessThan(2_000);
fetchMock.resetMocks();
}, 5000);

it("create should fail to poll", async () => {
fetchMock.mockResponse(JSON.stringify({ status: "queued" }));
const promise = assembly.transcripts.create(
Expand Down