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