voice-router-dev 0.2.2 → 0.2.4
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/index.d.mts +62 -27
- package/dist/index.d.ts +62 -27
- package/dist/index.js +83 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2041,7 +2041,8 @@ var GladiaAdapter = class extends BaseAdapter {
|
|
|
2041
2041
|
encoding: options?.encoding ? mapEncodingToProvider(options.encoding, "gladia") : void 0,
|
|
2042
2042
|
sample_rate: validatedSampleRate,
|
|
2043
2043
|
channels: options?.channels,
|
|
2044
|
-
endpointing: options?.endpointing
|
|
2044
|
+
endpointing: options?.endpointing,
|
|
2045
|
+
model: options?.model
|
|
2045
2046
|
};
|
|
2046
2047
|
if (options?.language) {
|
|
2047
2048
|
streamingRequest.language_config = {
|
|
@@ -3303,6 +3304,7 @@ var DeepgramAdapter = class extends BaseAdapter {
|
|
|
3303
3304
|
if (options?.sampleRate) params.append("sample_rate", options.sampleRate.toString());
|
|
3304
3305
|
if (options?.channels) params.append("channels", options.channels.toString());
|
|
3305
3306
|
if (options?.language) params.append("language", options.language);
|
|
3307
|
+
if (options?.model) params.append("model", options.model);
|
|
3306
3308
|
if (options?.languageDetection) params.append("detect_language", "true");
|
|
3307
3309
|
if (options?.diarization) params.append("diarize", "true");
|
|
3308
3310
|
if (options?.interimResults) params.append("interim_results", "true");
|
|
@@ -4288,15 +4290,46 @@ var GladiaWebhookHandler = class extends BaseWebhookHandler {
|
|
|
4288
4290
|
super(...arguments);
|
|
4289
4291
|
this.provider = "gladia";
|
|
4290
4292
|
}
|
|
4293
|
+
/**
|
|
4294
|
+
* Convert Gladia WordDTO to unified Word type
|
|
4295
|
+
*/
|
|
4296
|
+
mapWord(word) {
|
|
4297
|
+
return {
|
|
4298
|
+
text: word.word,
|
|
4299
|
+
start: word.start,
|
|
4300
|
+
end: word.end,
|
|
4301
|
+
confidence: word.confidence
|
|
4302
|
+
};
|
|
4303
|
+
}
|
|
4304
|
+
/**
|
|
4305
|
+
* Convert Gladia UtteranceDTO to unified Utterance type
|
|
4306
|
+
*/
|
|
4307
|
+
mapUtterance(utterance) {
|
|
4308
|
+
return {
|
|
4309
|
+
text: utterance.text,
|
|
4310
|
+
start: utterance.start,
|
|
4311
|
+
end: utterance.end,
|
|
4312
|
+
confidence: utterance.confidence,
|
|
4313
|
+
speaker: utterance.speaker !== void 0 ? String(utterance.speaker) : void 0,
|
|
4314
|
+
words: utterance.words?.map((w) => this.mapWord(w))
|
|
4315
|
+
};
|
|
4316
|
+
}
|
|
4291
4317
|
/**
|
|
4292
4318
|
* Check if payload matches Gladia webhook format
|
|
4319
|
+
*
|
|
4320
|
+
* Gladia callbacks have the structure:
|
|
4321
|
+
* - { id, event: "transcription.success", payload: TranscriptionResultDTO, custom_metadata? }
|
|
4322
|
+
* - { id, event: "transcription.error", error: ErrorDTO, custom_metadata? }
|
|
4293
4323
|
*/
|
|
4294
4324
|
matches(payload, _options) {
|
|
4295
4325
|
if (!payload || typeof payload !== "object") {
|
|
4296
4326
|
return false;
|
|
4297
4327
|
}
|
|
4298
4328
|
const obj = payload;
|
|
4299
|
-
if (!("
|
|
4329
|
+
if (!("id" in obj) || !("event" in obj)) {
|
|
4330
|
+
return false;
|
|
4331
|
+
}
|
|
4332
|
+
if (typeof obj.id !== "string") {
|
|
4300
4333
|
return false;
|
|
4301
4334
|
}
|
|
4302
4335
|
if (typeof obj.event !== "string") {
|
|
@@ -4305,11 +4338,13 @@ var GladiaWebhookHandler = class extends BaseWebhookHandler {
|
|
|
4305
4338
|
if (!obj.event.startsWith("transcription.")) {
|
|
4306
4339
|
return false;
|
|
4307
4340
|
}
|
|
4308
|
-
if (
|
|
4341
|
+
if (obj.event === "transcription.success" && !("payload" in obj)) {
|
|
4342
|
+
return false;
|
|
4343
|
+
}
|
|
4344
|
+
if (obj.event === "transcription.error" && !("error" in obj)) {
|
|
4309
4345
|
return false;
|
|
4310
4346
|
}
|
|
4311
|
-
|
|
4312
|
-
return typeof payloadObj.id === "string";
|
|
4347
|
+
return true;
|
|
4313
4348
|
}
|
|
4314
4349
|
/**
|
|
4315
4350
|
* Parse Gladia webhook payload to unified format
|
|
@@ -4318,38 +4353,57 @@ var GladiaWebhookHandler = class extends BaseWebhookHandler {
|
|
|
4318
4353
|
if (!this.matches(payload)) {
|
|
4319
4354
|
return this.createErrorEvent(payload, "Invalid Gladia webhook payload");
|
|
4320
4355
|
}
|
|
4321
|
-
const
|
|
4322
|
-
const jobId =
|
|
4323
|
-
const event =
|
|
4324
|
-
if (event === "transcription.created") {
|
|
4325
|
-
return {
|
|
4326
|
-
success: true,
|
|
4327
|
-
provider: this.provider,
|
|
4328
|
-
eventType: "transcription.created",
|
|
4329
|
-
data: {
|
|
4330
|
-
id: jobId,
|
|
4331
|
-
status: "queued"
|
|
4332
|
-
},
|
|
4333
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4334
|
-
raw: payload
|
|
4335
|
-
};
|
|
4336
|
-
}
|
|
4356
|
+
const obj = payload;
|
|
4357
|
+
const jobId = obj.id;
|
|
4358
|
+
const event = obj.event;
|
|
4337
4359
|
if (event === "transcription.success") {
|
|
4360
|
+
const successPayload = payload;
|
|
4361
|
+
const result = successPayload.payload;
|
|
4362
|
+
const transcription = result.transcription;
|
|
4363
|
+
const metadata = result.metadata;
|
|
4364
|
+
const utterances = transcription?.utterances?.map(
|
|
4365
|
+
(u) => this.mapUtterance(u)
|
|
4366
|
+
);
|
|
4367
|
+
const words = transcription?.utterances?.flatMap(
|
|
4368
|
+
(u) => u.words?.map((w) => this.mapWord(w)) ?? []
|
|
4369
|
+
);
|
|
4370
|
+
const speakerIds = /* @__PURE__ */ new Set();
|
|
4371
|
+
transcription?.utterances?.forEach((u) => {
|
|
4372
|
+
if (u.speaker !== void 0) {
|
|
4373
|
+
speakerIds.add(u.speaker);
|
|
4374
|
+
}
|
|
4375
|
+
});
|
|
4376
|
+
const speakers = speakerIds.size > 0 ? Array.from(speakerIds).map((id) => ({ id: String(id) })) : void 0;
|
|
4377
|
+
const summary = result.summarization?.success && result.summarization.results ? result.summarization.results : void 0;
|
|
4338
4378
|
return {
|
|
4339
4379
|
success: true,
|
|
4340
4380
|
provider: this.provider,
|
|
4341
4381
|
eventType: "transcription.completed",
|
|
4342
4382
|
data: {
|
|
4343
4383
|
id: jobId,
|
|
4344
|
-
status: "completed"
|
|
4345
|
-
|
|
4346
|
-
|
|
4384
|
+
status: "completed",
|
|
4385
|
+
text: transcription?.full_transcript,
|
|
4386
|
+
duration: metadata?.audio_duration,
|
|
4387
|
+
language: transcription?.languages?.[0],
|
|
4388
|
+
speakers,
|
|
4389
|
+
words,
|
|
4390
|
+
utterances,
|
|
4391
|
+
summary,
|
|
4392
|
+
metadata: {
|
|
4393
|
+
transcription_time: metadata?.transcription_time,
|
|
4394
|
+
billing_time: metadata?.billing_time,
|
|
4395
|
+
number_of_distinct_channels: metadata?.number_of_distinct_channels,
|
|
4396
|
+
custom_metadata: successPayload.custom_metadata
|
|
4397
|
+
},
|
|
4398
|
+
completedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4347
4399
|
},
|
|
4348
4400
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4349
4401
|
raw: payload
|
|
4350
4402
|
};
|
|
4351
4403
|
}
|
|
4352
4404
|
if (event === "transcription.error") {
|
|
4405
|
+
const errorPayload = payload;
|
|
4406
|
+
const error = errorPayload.error;
|
|
4353
4407
|
return {
|
|
4354
4408
|
success: false,
|
|
4355
4409
|
provider: this.provider,
|
|
@@ -4357,7 +4411,11 @@ var GladiaWebhookHandler = class extends BaseWebhookHandler {
|
|
|
4357
4411
|
data: {
|
|
4358
4412
|
id: jobId,
|
|
4359
4413
|
status: "error",
|
|
4360
|
-
error: "Transcription failed"
|
|
4414
|
+
error: error?.message || "Transcription failed",
|
|
4415
|
+
metadata: {
|
|
4416
|
+
error_code: error?.code,
|
|
4417
|
+
custom_metadata: errorPayload.custom_metadata
|
|
4418
|
+
}
|
|
4361
4419
|
},
|
|
4362
4420
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4363
4421
|
raw: payload
|