@kognitivedev/backend-cloud 0.2.29
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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-test.log +14 -0
- package/CHANGELOG.md +11 -0
- package/README.md +88 -0
- package/dist/cloud-voice-parameters.d.ts +11 -0
- package/dist/cloud-voice-parameters.js +219 -0
- package/dist/cloud-voice-prompt-service.d.ts +24 -0
- package/dist/cloud-voice-prompt-service.js +382 -0
- package/dist/cloud-voice-runtime-service.d.ts +73 -0
- package/dist/cloud-voice-runtime-service.js +443 -0
- package/dist/cloud-voice.d.ts +36 -0
- package/dist/cloud-voice.js +683 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +26 -0
- package/dist/phone-control.d.ts +50 -0
- package/dist/phone-control.js +97 -0
- package/dist/phone-runtime/audio-playout-tracker.d.ts +51 -0
- package/dist/phone-runtime/audio-playout-tracker.js +93 -0
- package/dist/phone-runtime/openai-twilio-realtime.d.ts +95 -0
- package/dist/phone-runtime/openai-twilio-realtime.js +1074 -0
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +216 -0
- package/dist/types.d.ts +468 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +14 -0
- package/package.json +47 -0
- package/src/__tests__/audio-playout-tracker.test.ts +46 -0
- package/src/__tests__/cloud-voice.test.ts +1006 -0
- package/src/__tests__/openai-twilio-realtime.test.ts +1193 -0
- package/src/__tests__/phone-control.test.ts +105 -0
- package/src/cloud-voice-parameters.ts +236 -0
- package/src/cloud-voice-prompt-service.ts +493 -0
- package/src/cloud-voice-runtime-service.ts +465 -0
- package/src/cloud-voice.ts +831 -0
- package/src/index.ts +10 -0
- package/src/phone-control.ts +156 -0
- package/src/phone-runtime/audio-playout-tracker.ts +132 -0
- package/src/phone-runtime/openai-twilio-realtime.ts +1250 -0
- package/src/tools.ts +227 -0
- package/src/types.ts +529 -0
- package/src/utils.ts +11 -0
- package/tsconfig.json +13 -0
package/dist/utils.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getString = getString;
|
|
4
|
+
exports.getNumber = getNumber;
|
|
5
|
+
exports.getRecord = getRecord;
|
|
6
|
+
function getString(value, fallback = "") {
|
|
7
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
8
|
+
}
|
|
9
|
+
function getNumber(value, fallback) {
|
|
10
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
11
|
+
}
|
|
12
|
+
function getRecord(value) {
|
|
13
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kognitivedev/backend-cloud",
|
|
3
|
+
"version": "0.2.29",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"dev": "tsc -w --noCheck",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@kognitivedev/telephony": "^0.2.29",
|
|
23
|
+
"@kognitivedev/voice-media-bridge": "^0.2.29",
|
|
24
|
+
"ws": "^8.20.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"@types/ws": "^8.18.1",
|
|
29
|
+
"typescript": "^5.0.0",
|
|
30
|
+
"vitest": "^3.0.0"
|
|
31
|
+
},
|
|
32
|
+
"description": "Reusable backend orchestration helpers for Kognitive Cloud products",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"kognitive",
|
|
35
|
+
"backend",
|
|
36
|
+
"cloud",
|
|
37
|
+
"voice",
|
|
38
|
+
"agents"
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/kognitivedev/kognitive",
|
|
44
|
+
"directory": "packages/backend-cloud"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://kognitive.dev"
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { PhonePlayoutTracker } from "../phone-runtime/audio-playout-tracker";
|
|
3
|
+
|
|
4
|
+
describe("PhonePlayoutTracker", () => {
|
|
5
|
+
it("reports heard and queued assistant audio for interruptions", () => {
|
|
6
|
+
const tracker = new PhonePlayoutTracker({ frameDurationMs: 20 });
|
|
7
|
+
tracker.startAssistantItem("assistant-item-1");
|
|
8
|
+
tracker.recordOutboundFrame({ markName: "m1" });
|
|
9
|
+
tracker.recordOutboundFrame({ markName: "m2" });
|
|
10
|
+
tracker.recordCarrierMark("m1");
|
|
11
|
+
|
|
12
|
+
expect(tracker.interrupt({ elapsedMs: 30, providerTruncationSupported: true })).toMatchObject({
|
|
13
|
+
assistantItemId: "assistant-item-1",
|
|
14
|
+
heardAudioMs: 30,
|
|
15
|
+
queuedAudioMs: 40,
|
|
16
|
+
pendingMarks: 1,
|
|
17
|
+
interrupted: true,
|
|
18
|
+
providerTruncationSupported: true,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("waits until carrier marks drain before reporting idle", async () => {
|
|
23
|
+
const tracker = new PhonePlayoutTracker({ frameDurationMs: 20 });
|
|
24
|
+
tracker.recordOutboundFrame({ markName: "m1" });
|
|
25
|
+
|
|
26
|
+
const wait = tracker.waitForIdle({ timeoutMs: 500, quietMs: 0, pollMs: 10 });
|
|
27
|
+
setTimeout(() => tracker.recordCarrierMark("m1"), 25);
|
|
28
|
+
|
|
29
|
+
await expect(wait).resolves.toMatchObject({
|
|
30
|
+
idle: true,
|
|
31
|
+
reason: "idle",
|
|
32
|
+
pendingMarks: 0,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("times out when carrier marks never drain", async () => {
|
|
37
|
+
const tracker = new PhonePlayoutTracker({ frameDurationMs: 20 });
|
|
38
|
+
tracker.recordOutboundFrame({ markName: "m1" });
|
|
39
|
+
|
|
40
|
+
await expect(tracker.waitForIdle({ timeoutMs: 20, quietMs: 0, pollMs: 10 })).resolves.toMatchObject({
|
|
41
|
+
idle: false,
|
|
42
|
+
reason: "timeout",
|
|
43
|
+
pendingMarks: 1,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|