@mycadet/assistant 0.12.10 → 0.13.0
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/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
- package/node_modules/@mycadet/ces-client/src/http-credentials.ts +18 -1
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
- package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -20
- package/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
- package/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
- package/openapi.yaml +2 -708
- package/package.json +2 -3
- package/scripts/sync-web-search-catalog.ts +1 -2
- package/src/__tests__/cloud-profile-guard.test.ts +41 -5
- package/src/__tests__/config-schema.test.ts +6 -38
- package/src/__tests__/conversation-queue.test.ts +45 -6
- package/src/__tests__/db-readiness-http-gate.test.ts +0 -6
- package/src/__tests__/persist-onboarding-artifacts.test.ts +0 -1
- package/src/__tests__/persona-resolver.test.ts +0 -51
- package/src/__tests__/provider-cloud-proxy-integration.test.ts +2 -110
- package/src/__tests__/run-due-schedules.test.ts +0 -4
- package/src/__tests__/schedule-store.test.ts +0 -12
- package/src/__tests__/stt-stream-session.test.ts +4 -4
- package/src/__tests__/telephony-tts-guard.test.ts +2 -50
- package/src/__tests__/voice-config-update.test.ts +12 -167
- package/src/__tests__/web-search-catalog-parity.test.ts +0 -2
- package/src/__tests__/workspace-migration-130-speech-mode-to-provider.test.ts +9 -7
- package/src/__tests__/workspace-migration-132-web-search-mode-to-provider.test.ts +6 -6
- package/src/calls/__tests__/voice-session-bridge.test.ts +1 -4
- package/src/calls/resolve-call-tts-provider.ts +6 -25
- package/src/calls/telephony-credential-preflight.ts +0 -10
- package/src/calls/telephony-tts-capability.ts +1 -17
- package/src/cli/commands/tts.ts +1 -2
- package/src/cli/index.help.ts +0 -2
- package/src/cli/program.ts +0 -2
- package/src/config/bundled-skills/settings/tools/voice-config-update.ts +4 -42
- package/src/config/schemas/__tests__/stt.test.ts +10 -14
- package/src/config/schemas/llm.ts +3 -5
- package/src/config/schemas/services.ts +5 -6
- package/src/config/schemas/stt.ts +1 -3
- package/src/config/schemas/tts.ts +1 -30
- package/src/daemon/daemon-readiness.ts +4 -29
- package/src/daemon/lifecycle.ts +0 -31
- package/src/daemon/providers-setup.ts +0 -8
- package/src/heartbeat/__tests__/heartbeat-service.test.ts +0 -1
- package/src/heartbeat/heartbeat-service.ts +1 -66
- package/src/ipc/__tests__/db-readiness-ipc-gate.test.ts +1 -9
- package/src/live-voice/__tests__/live-voice-credential-preflight.test.ts +0 -44
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +4 -6
- package/src/live-voice/__tests__/live-voice-stt.test.ts +1 -1
- package/src/live-voice/live-voice-credential-preflight.ts +9 -33
- package/src/live-voice/live-voice-session.ts +10 -6
- package/src/live-voice/live-voice-tts.ts +1 -8
- package/src/plugins/defaults/memory/worker.ts +3 -3
- package/src/prompts/persona-resolver.ts +0 -35
- package/src/providers/__tests__/search-provider-catalog.test.ts +5 -8
- package/src/providers/__tests__/voice-error-copy.test.ts +9 -10
- package/src/providers/search-provider-catalog.ts +7 -39
- package/src/providers/speech-to-text/__tests__/provider-catalog.test.ts +3 -47
- package/src/providers/speech-to-text/__tests__/resolve.test.ts +6 -372
- package/src/providers/speech-to-text/provider-catalog.ts +2 -73
- package/src/providers/speech-to-text/resolve.ts +3 -120
- package/src/runtime/http-router-types.ts +1 -3
- package/src/runtime/http-server.ts +1 -1
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +13 -11
- package/src/runtime/routes/__tests__/tts-routes.test.ts +2 -6
- package/src/runtime/routes/conversation-query-routes.ts +0 -96
- package/src/runtime/routes/inbound-stages/transcribe-audio.test.ts +7 -7
- package/src/runtime/routes/index.ts +0 -4
- package/src/runtime/routes/live-voice-routes.test.ts +4 -11
- package/src/runtime/routes/live-voice-routes.ts +8 -11
- package/src/runtime/routes/secret-routes.ts +0 -6
- package/src/runtime/routes/tts-routes.ts +0 -38
- package/src/schedule/__tests__/plugin-schedule-reconciler.test.ts +1 -7
- package/src/schedule/__tests__/worker-mcp-readiness.test.ts +0 -4
- package/src/schedule/schedule-store.ts +0 -7
- package/src/schedule/scheduler.ts +0 -5
- package/src/schedule/worker.ts +1 -1
- package/src/stt/__tests__/daemon-batch-transcriber.test.ts +2 -10
- package/src/stt/daemon-batch-transcriber.ts +4 -38
- package/src/stt/types.ts +1 -9
- package/src/tools/network/__tests__/web-search.test.ts +3 -250
- package/src/tools/network/web-search.ts +4 -165
- package/src/tts/__tests__/provider-resolution.test.ts +0 -5
- package/src/tts/provider-catalog.ts +0 -4
- package/src/tts/types.ts +0 -1
- package/src/__tests__/cloud-speech-defaults.test.ts +0 -330
- package/src/__tests__/migration-cross-version-compatibility.test.ts +0 -1708
- package/src/__tests__/migration-export-http.test.ts +0 -557
- package/src/__tests__/migration-export-streaming.test.ts +0 -350
- package/src/__tests__/migration-export-to-gcs.test.ts +0 -706
- package/src/__tests__/migration-import-commit-http.test.ts +0 -1176
- package/src/__tests__/migration-import-from-gcs.test.ts +0 -534
- package/src/__tests__/migration-import-from-path.test.ts +0 -324
- package/src/__tests__/migration-import-from-url.test.ts +0 -588
- package/src/__tests__/migration-import-preflight-http.test.ts +0 -739
- package/src/__tests__/migration-jobs-status.test.ts +0 -139
- package/src/__tests__/migration-parity-persistence.test.ts +0 -1891
- package/src/__tests__/migration-transport.test.ts +0 -1089
- package/src/__tests__/migration-validate-http.test.ts +0 -634
- package/src/__tests__/migration-wizard.test.ts +0 -1395
- package/src/__tests__/rebind-secrets-screen.test.ts +0 -876
- package/src/__tests__/sanitize-config-for-transfer.test.ts +0 -259
- package/src/__tests__/transfer-progress-screen.test.ts +0 -1217
- package/src/__tests__/validation-results-screen.test.ts +0 -1130
- package/src/__tests__/vbundle-pax-and-symlink.test.ts +0 -147
- package/src/background-wake/background-wake-routes.test.ts +0 -906
- package/src/background-wake/cloud-client.test.ts +0 -328
- package/src/background-wake/cloud-client.ts +0 -196
- package/src/background-wake/next-wake.test.ts +0 -335
- package/src/background-wake/next-wake.ts +0 -188
- package/src/background-wake/publisher.ts +0 -93
- package/src/background-wake/wake-intent-hooks.test.ts +0 -234
- package/src/cli/commands/__tests__/backup.test.ts +0 -363
- package/src/cli/commands/backup.help.ts +0 -180
- package/src/cli/commands/backup.ts +0 -398
- package/src/cloud/cloud-speech.test.ts +0 -335
- package/src/cloud/cloud-speech.ts +0 -300
- package/src/config/cloud-speech-defaults.ts +0 -300
- package/src/config/sanitize-for-transfer.ts +0 -111
- package/src/live-voice/__tests__/live-voice-cloud-speech-fallback.test.ts +0 -250
- package/src/providers/speech-to-text/__tests__/cadet-cloud-realtime.test.ts +0 -457
- package/src/providers/speech-to-text/__tests__/cadet-cloud.test.ts +0 -271
- package/src/providers/speech-to-text/__tests__/cadet-speech-relay-connection.test.ts +0 -126
- package/src/providers/speech-to-text/cadet-cloud-flux-realtime.ts +0 -309
- package/src/providers/speech-to-text/cadet-cloud-realtime.ts +0 -315
- package/src/providers/speech-to-text/cadet-cloud.ts +0 -108
- package/src/providers/speech-to-text/cadet-speech-relay-connection.ts +0 -176
- package/src/runtime/migrations/__tests__/gcs-signed-url.test.ts +0 -254
- package/src/runtime/migrations/__tests__/job-registry.test.ts +0 -346
- package/src/runtime/migrations/__tests__/origin-mode.test.ts +0 -62
- package/src/runtime/migrations/__tests__/rebind-secrets-credentials.test.ts +0 -184
- package/src/runtime/migrations/__tests__/staged-import-path.test.ts +0 -110
- package/src/runtime/migrations/__tests__/v1-test-helpers.ts +0 -112
- package/src/runtime/migrations/__tests__/vbundle-builder-credentials.test.ts +0 -285
- package/src/runtime/migrations/__tests__/vbundle-builder-fd-leak.test.ts +0 -126
- package/src/runtime/migrations/__tests__/vbundle-builder-v1-shape.test.ts +0 -253
- package/src/runtime/migrations/__tests__/vbundle-import-credentials.test.ts +0 -208
- package/src/runtime/migrations/__tests__/vbundle-import-parity.test.ts +0 -485
- package/src/runtime/migrations/__tests__/vbundle-import-policy.test.ts +0 -349
- package/src/runtime/migrations/__tests__/vbundle-import-version-compat.test.ts +0 -196
- package/src/runtime/migrations/__tests__/vbundle-legacy-user-md.test.ts +0 -551
- package/src/runtime/migrations/__tests__/vbundle-metadata-merge-integration.test.ts +0 -428
- package/src/runtime/migrations/__tests__/vbundle-metadata-merge.test.ts +0 -220
- package/src/runtime/migrations/__tests__/vbundle-streaming-importer.test.ts +0 -1823
- package/src/runtime/migrations/__tests__/vbundle-streaming-validator.test.ts +0 -598
- package/src/runtime/migrations/__tests__/vbundle-symlink-importer.test.ts +0 -463
- package/src/runtime/migrations/__tests__/vbundle-symlink-streaming-importer.test.ts +0 -538
- package/src/runtime/migrations/__tests__/vbundle-symlink-streaming.test.ts +0 -515
- package/src/runtime/migrations/__tests__/vbundle-symlink-tar.test.ts +0 -453
- package/src/runtime/migrations/__tests__/vbundle-symlink-walker.test.ts +0 -319
- package/src/runtime/migrations/__tests__/vbundle-tar-stream.test.ts +0 -240
- package/src/runtime/migrations/__tests__/vbundle-validator-v1-schema.test.ts +0 -473
- package/src/runtime/migrations/gcs-signed-url.ts +0 -190
- package/src/runtime/migrations/job-registry.ts +0 -297
- package/src/runtime/migrations/migration-transport.ts +0 -612
- package/src/runtime/migrations/migration-wizard.ts +0 -747
- package/src/runtime/migrations/origin-mode.ts +0 -42
- package/src/runtime/migrations/rebind-secrets-screen.ts +0 -412
- package/src/runtime/migrations/staged-import-path.ts +0 -116
- package/src/runtime/migrations/transfer-progress-screen.ts +0 -323
- package/src/runtime/migrations/validation-results-screen.ts +0 -469
- package/src/runtime/migrations/vbundle-builder.ts +0 -1382
- package/src/runtime/migrations/vbundle-import-analyzer.ts +0 -405
- package/src/runtime/migrations/vbundle-import-policy.ts +0 -241
- package/src/runtime/migrations/vbundle-importer.ts +0 -826
- package/src/runtime/migrations/vbundle-metadata-merge.ts +0 -113
- package/src/runtime/migrations/vbundle-streaming-importer.ts +0 -2844
- package/src/runtime/migrations/vbundle-streaming-validator.ts +0 -426
- package/src/runtime/migrations/vbundle-tar-stream.ts +0 -244
- package/src/runtime/migrations/vbundle-validator.ts +0 -724
- package/src/runtime/routes/__tests__/migration-cadet-metadata-reconcile.test.ts +0 -227
- package/src/runtime/routes/__tests__/migration-export-secrets-redacted.test.ts +0 -54
- package/src/runtime/routes/__tests__/migration-import-allowed-hosts-env.test.ts +0 -70
- package/src/runtime/routes/__tests__/migration-import-credential-filter.test.ts +0 -257
- package/src/runtime/routes/background-wake-routes.ts +0 -387
- package/src/runtime/routes/migration-routes.ts +0 -2584
- package/src/tools/network/__tests__/cloud-search-proxy.test.ts +0 -282
- package/src/tools/network/cloud-search-proxy.ts +0 -211
- package/src/tts/__tests__/cadet-provider.test.ts +0 -253
- package/src/tts/providers/cadet-provider.ts +0 -244
- package/src/types/tar-stream.d.ts +0 -66
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
interface MockCloudClient {
|
|
4
|
-
cloudAssistantId: string;
|
|
5
|
-
fetch: ReturnType<typeof mock>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let mockClient: MockCloudClient | null = null;
|
|
9
|
-
|
|
10
|
-
mock.module("./client.js", () => ({
|
|
11
|
-
CadetCloudClient: {
|
|
12
|
-
create: async () => mockClient,
|
|
13
|
-
},
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
managedSpeechSynthesize,
|
|
18
|
-
managedSpeechTranscribe,
|
|
19
|
-
managedSpeechVoices,
|
|
20
|
-
} from "./cloud-speech.js";
|
|
21
|
-
|
|
22
|
-
const AUDIO = Buffer.from([0x01, 0x02, 0x03, 0xff]);
|
|
23
|
-
|
|
24
|
-
describe("managedSpeechTranscribe", () => {
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
mockClient = {
|
|
27
|
-
cloudAssistantId: "asst-123",
|
|
28
|
-
fetch: mock(
|
|
29
|
-
async () =>
|
|
30
|
-
new Response(
|
|
31
|
-
JSON.stringify({
|
|
32
|
-
text: "hello world",
|
|
33
|
-
providerId: "deepgram",
|
|
34
|
-
model: "nova-3",
|
|
35
|
-
durationSeconds: 12.5,
|
|
36
|
-
}),
|
|
37
|
-
{ status: 200, headers: { "content-type": "application/json" } },
|
|
38
|
-
),
|
|
39
|
-
),
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
mockClient = null;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("posts base64 audio to the assistant's transcribe endpoint", async () => {
|
|
48
|
-
const result = await managedSpeechTranscribe({
|
|
49
|
-
audio: AUDIO,
|
|
50
|
-
mimeType: "audio/wav",
|
|
51
|
-
source: "dictation",
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
expect(result).toEqual({
|
|
55
|
-
ok: true,
|
|
56
|
-
value: { text: "hello world", durationSeconds: 12.5 },
|
|
57
|
-
});
|
|
58
|
-
const [path, init] = mockClient!.fetch.mock.calls[0] as [
|
|
59
|
-
string,
|
|
60
|
-
RequestInit,
|
|
61
|
-
];
|
|
62
|
-
expect(path).toBe("/v1/assistants/asst-123/cloud-speech/stt/transcribe/");
|
|
63
|
-
expect(init.method).toBe("POST");
|
|
64
|
-
const body = JSON.parse(init.body as string);
|
|
65
|
-
expect(body).toEqual({
|
|
66
|
-
audioBase64: AUDIO.toString("base64"),
|
|
67
|
-
mimeType: "audio/wav",
|
|
68
|
-
source: "dictation",
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("omits source when not provided", async () => {
|
|
73
|
-
await managedSpeechTranscribe({ audio: AUDIO, mimeType: "audio/wav" });
|
|
74
|
-
const [, init] = mockClient!.fetch.mock.calls[0] as [string, RequestInit];
|
|
75
|
-
expect(JSON.parse(init.body as string)).not.toHaveProperty("source");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("sends the spoken language when one is given", async () => {
|
|
79
|
-
// The cloud forwards this to Deepgram, which otherwise decodes the
|
|
80
|
-
// audio as English rather than detecting its language.
|
|
81
|
-
await managedSpeechTranscribe({
|
|
82
|
-
audio: AUDIO,
|
|
83
|
-
mimeType: "audio/wav",
|
|
84
|
-
language: "multi",
|
|
85
|
-
});
|
|
86
|
-
const [, init] = mockClient!.fetch.mock.calls[0] as [string, RequestInit];
|
|
87
|
-
expect(JSON.parse(init.body as string).language).toBe("multi");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("omits language when not provided", async () => {
|
|
91
|
-
// An absent field and an empty one are different requests upstream, and
|
|
92
|
-
// the empty one fails the cloud serializer.
|
|
93
|
-
await managedSpeechTranscribe({ audio: AUDIO, mimeType: "audio/wav" });
|
|
94
|
-
const [, init] = mockClient!.fetch.mock.calls[0] as [string, RequestInit];
|
|
95
|
-
expect(JSON.parse(init.body as string)).not.toHaveProperty("language");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("returns unavailable when no platform client resolves", async () => {
|
|
99
|
-
mockClient = null;
|
|
100
|
-
const result = await managedSpeechTranscribe({
|
|
101
|
-
audio: AUDIO,
|
|
102
|
-
mimeType: "audio/wav",
|
|
103
|
-
});
|
|
104
|
-
expect(result).toMatchObject({ ok: false, kind: "unavailable" });
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("returns unavailable when the assistant ID is missing", async () => {
|
|
108
|
-
mockClient!.cloudAssistantId = "";
|
|
109
|
-
const result = await managedSpeechTranscribe({
|
|
110
|
-
audio: AUDIO,
|
|
111
|
-
mimeType: "audio/wav",
|
|
112
|
-
});
|
|
113
|
-
expect(result).toMatchObject({ ok: false, kind: "unavailable" });
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("surfaces the cloud error code on 402", async () => {
|
|
117
|
-
mockClient!.fetch = mock(
|
|
118
|
-
async () =>
|
|
119
|
-
new Response(
|
|
120
|
-
JSON.stringify({
|
|
121
|
-
code: "insufficient_balance",
|
|
122
|
-
detail: "Insufficient balance. Please add funds to continue.",
|
|
123
|
-
}),
|
|
124
|
-
{ status: 402, headers: { "content-type": "application/json" } },
|
|
125
|
-
),
|
|
126
|
-
);
|
|
127
|
-
const result = await managedSpeechTranscribe({
|
|
128
|
-
audio: AUDIO,
|
|
129
|
-
mimeType: "audio/wav",
|
|
130
|
-
});
|
|
131
|
-
expect(result).toMatchObject({
|
|
132
|
-
ok: false,
|
|
133
|
-
kind: "platform-error",
|
|
134
|
-
status: 402,
|
|
135
|
-
code: "insufficient_balance",
|
|
136
|
-
message: "Insufficient balance. Please add funds to continue.",
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test("treats a malformed 200 body as a cloud error", async () => {
|
|
141
|
-
mockClient!.fetch = mock(
|
|
142
|
-
async () =>
|
|
143
|
-
new Response(JSON.stringify({ unexpected: true }), {
|
|
144
|
-
status: 200,
|
|
145
|
-
headers: { "content-type": "application/json" },
|
|
146
|
-
}),
|
|
147
|
-
);
|
|
148
|
-
const result = await managedSpeechTranscribe({
|
|
149
|
-
audio: AUDIO,
|
|
150
|
-
mimeType: "audio/wav",
|
|
151
|
-
});
|
|
152
|
-
expect(result).toMatchObject({ ok: false, kind: "platform-error" });
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe("managedSpeechVoices", () => {
|
|
157
|
-
const CATALOG = {
|
|
158
|
-
voices: [
|
|
159
|
-
{
|
|
160
|
-
model: "aura-2-thalia-en",
|
|
161
|
-
label: "Thalia",
|
|
162
|
-
description: "American · clear, confident, energetic",
|
|
163
|
-
sampleUrl: "https://static.deepgram.com/examples/Aura-2-thalia.wav",
|
|
164
|
-
source: "deepgram",
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
defaultModel: "aura-2-thalia-en",
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
beforeEach(() => {
|
|
171
|
-
mockClient = {
|
|
172
|
-
cloudAssistantId: "asst-123",
|
|
173
|
-
fetch: mock(async () => Response.json(CATALOG)),
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
afterEach(() => {
|
|
178
|
-
mockClient = null;
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test("fetches and parses the cloud voice catalog", async () => {
|
|
182
|
-
const result = await managedSpeechVoices();
|
|
183
|
-
|
|
184
|
-
expect(result.ok).toBe(true);
|
|
185
|
-
if (result.ok) {
|
|
186
|
-
expect(result.value).toEqual(CATALOG);
|
|
187
|
-
}
|
|
188
|
-
const [path, init] = mockClient!.fetch.mock.calls[0] as [
|
|
189
|
-
string,
|
|
190
|
-
RequestInit,
|
|
191
|
-
];
|
|
192
|
-
expect(path).toBe("/v1/assistants/asst-123/cloud-speech/tts/voices/");
|
|
193
|
-
expect(init.method).toBe("GET");
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test("drops malformed voice entries and tolerates a null default", async () => {
|
|
197
|
-
mockClient!.fetch = mock(async () =>
|
|
198
|
-
Response.json({
|
|
199
|
-
voices: [CATALOG.voices[0], { model: "missing-fields" }],
|
|
200
|
-
defaultModel: null,
|
|
201
|
-
}),
|
|
202
|
-
);
|
|
203
|
-
const result = await managedSpeechVoices();
|
|
204
|
-
|
|
205
|
-
expect(result.ok).toBe(true);
|
|
206
|
-
if (result.ok) {
|
|
207
|
-
expect(result.value.voices).toEqual(CATALOG.voices);
|
|
208
|
-
expect(result.value.defaultModel).toBeNull();
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test("treats a malformed body as a cloud error", async () => {
|
|
213
|
-
mockClient!.fetch = mock(async () => Response.json({ nope: true }));
|
|
214
|
-
const result = await managedSpeechVoices();
|
|
215
|
-
expect(result).toMatchObject({ ok: false, kind: "platform-error" });
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test("propagates platform error responses", async () => {
|
|
219
|
-
mockClient!.fetch = mock(
|
|
220
|
-
async () =>
|
|
221
|
-
new Response(JSON.stringify({ code: "x", detail: "nope" }), {
|
|
222
|
-
status: 502,
|
|
223
|
-
}),
|
|
224
|
-
);
|
|
225
|
-
const result = await managedSpeechVoices();
|
|
226
|
-
expect(result).toMatchObject({
|
|
227
|
-
ok: false,
|
|
228
|
-
kind: "platform-error",
|
|
229
|
-
status: 502,
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
describe("managedSpeechSynthesize", () => {
|
|
235
|
-
const MP3_BYTES = Buffer.from([0x49, 0x44, 0x33, 0x04, 0x00]);
|
|
236
|
-
|
|
237
|
-
beforeEach(() => {
|
|
238
|
-
mockClient = {
|
|
239
|
-
cloudAssistantId: "asst-123",
|
|
240
|
-
fetch: mock(
|
|
241
|
-
async () =>
|
|
242
|
-
new Response(new Uint8Array(MP3_BYTES), {
|
|
243
|
-
status: 200,
|
|
244
|
-
headers: { "content-type": "audio/mpeg" },
|
|
245
|
-
}),
|
|
246
|
-
),
|
|
247
|
-
};
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
afterEach(() => {
|
|
251
|
-
mockClient = null;
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test("posts text and format, round-trips binary audio and content type", async () => {
|
|
255
|
-
const result = await managedSpeechSynthesize({
|
|
256
|
-
text: "hello",
|
|
257
|
-
format: "pcm_16000",
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
expect(result.ok).toBe(true);
|
|
261
|
-
if (result.ok) {
|
|
262
|
-
expect(Buffer.compare(result.value.audio, MP3_BYTES)).toBe(0);
|
|
263
|
-
expect(result.value.contentType).toBe("audio/mpeg");
|
|
264
|
-
}
|
|
265
|
-
const [path, init] = mockClient!.fetch.mock.calls[0] as [
|
|
266
|
-
string,
|
|
267
|
-
RequestInit,
|
|
268
|
-
];
|
|
269
|
-
expect(path).toBe("/v1/assistants/asst-123/cloud-speech/tts/synthesize/");
|
|
270
|
-
expect(JSON.parse(init.body as string)).toEqual({
|
|
271
|
-
text: "hello",
|
|
272
|
-
format: "pcm_16000",
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test("includes the voice model in the body only when provided", async () => {
|
|
277
|
-
await managedSpeechSynthesize({
|
|
278
|
-
text: "hello",
|
|
279
|
-
format: "mp3",
|
|
280
|
-
model: "aura-2-zeus-en",
|
|
281
|
-
});
|
|
282
|
-
const [, init] = mockClient!.fetch.mock.calls[0] as [string, RequestInit];
|
|
283
|
-
expect(JSON.parse(init.body as string)).toEqual({
|
|
284
|
-
text: "hello",
|
|
285
|
-
format: "mp3",
|
|
286
|
-
model: "aura-2-zeus-en",
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
await managedSpeechSynthesize({ text: "hello", format: "mp3" });
|
|
290
|
-
const [, second] = mockClient!.fetch.mock.calls[1] as [string, RequestInit];
|
|
291
|
-
expect(JSON.parse(second.body as string)).not.toHaveProperty("model");
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
test("falls back to audio/mpeg when no content type is returned", async () => {
|
|
295
|
-
mockClient!.fetch = mock(
|
|
296
|
-
async () => new Response(new Uint8Array(MP3_BYTES), { status: 200 }),
|
|
297
|
-
);
|
|
298
|
-
const result = await managedSpeechSynthesize({
|
|
299
|
-
text: "hello",
|
|
300
|
-
format: "mp3",
|
|
301
|
-
});
|
|
302
|
-
expect(result.ok && result.value.contentType).toBe("audio/mpeg");
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
test("treats empty audio as a cloud error", async () => {
|
|
306
|
-
mockClient!.fetch = mock(
|
|
307
|
-
async () => new Response(new Uint8Array(0), { status: 200 }),
|
|
308
|
-
);
|
|
309
|
-
const result = await managedSpeechSynthesize({
|
|
310
|
-
text: "hello",
|
|
311
|
-
format: "mp3",
|
|
312
|
-
});
|
|
313
|
-
expect(result).toMatchObject({ ok: false, kind: "platform-error" });
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
test("surfaces insufficient_balance on 402", async () => {
|
|
317
|
-
mockClient!.fetch = mock(
|
|
318
|
-
async () =>
|
|
319
|
-
new Response(
|
|
320
|
-
JSON.stringify({ code: "insufficient_balance", detail: "Top up." }),
|
|
321
|
-
{ status: 402, headers: { "content-type": "application/json" } },
|
|
322
|
-
),
|
|
323
|
-
);
|
|
324
|
-
const result = await managedSpeechSynthesize({
|
|
325
|
-
text: "hello",
|
|
326
|
-
format: "mp3",
|
|
327
|
-
});
|
|
328
|
-
expect(result).toMatchObject({
|
|
329
|
-
ok: false,
|
|
330
|
-
kind: "platform-error",
|
|
331
|
-
status: 402,
|
|
332
|
-
code: "insufficient_balance",
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
});
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client for the cloud's cloud speech endpoints: Cadet-held Deepgram
|
|
3
|
-
* key, billed to the org's credits. The daemon sends complete audio (STT) or
|
|
4
|
-
* text (TTS) and the cloud does the provider call — no speech credentials
|
|
5
|
-
* ever live on this machine.
|
|
6
|
-
*
|
|
7
|
-
* Contract (mirrors `mycadet-platform` — do not change unilaterally):
|
|
8
|
-
* - `POST /v1/assistants/{id}/cloud-speech/stt/transcribe/`
|
|
9
|
-
* `{audioBase64, mimeType, source?}` → 200 `{text, providerId, model,
|
|
10
|
-
* durationSeconds}`.
|
|
11
|
-
* - `POST /v1/assistants/{id}/cloud-speech/tts/synthesize/`
|
|
12
|
-
* `{text, format?}` → 200 binary audio, `Content-Type` from upstream.
|
|
13
|
-
* - Errors: `{code, detail}`; notable codes: `insufficient_balance` (402),
|
|
14
|
-
* `missing_price` (400), `provider_configuration_error` (500).
|
|
15
|
-
*
|
|
16
|
-
* Pure platform HTTP client: no provider-catalog, config-schema, or resolver
|
|
17
|
-
* imports — the cadet STT/TTS providers build on top of it.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { z } from "zod";
|
|
21
|
-
|
|
22
|
-
import { CadetCloudClient } from "./client.js";
|
|
23
|
-
|
|
24
|
-
export type CloudSpeechResult<T> =
|
|
25
|
-
| { ok: true; value: T }
|
|
26
|
-
| {
|
|
27
|
-
ok: false;
|
|
28
|
-
kind: "unavailable" | "platform-error";
|
|
29
|
-
status?: number;
|
|
30
|
-
/** Platform error code (e.g. `insufficient_balance`) when the body carried one. */
|
|
31
|
-
code?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Platform-supplied human-readable message, present only when the error
|
|
34
|
-
* body carried a `detail` field. Absent when the failure fell back to a
|
|
35
|
-
* bare HTTP status. `message` mirrors this when set; callers use the
|
|
36
|
-
* presence of `detail` to distinguish real platform copy (safe to surface
|
|
37
|
-
* verbatim) from the generic status fallback.
|
|
38
|
-
*/
|
|
39
|
-
detail?: string;
|
|
40
|
-
message: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export interface CloudSpeechTranscription {
|
|
44
|
-
text: string;
|
|
45
|
-
durationSeconds: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const CloudSpeechTranscriptionSchema = z.object({
|
|
49
|
-
text: z.string(),
|
|
50
|
-
durationSeconds: z.number(),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export interface CloudSpeechSynthesis {
|
|
54
|
-
audio: Buffer;
|
|
55
|
-
contentType: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type CloudSpeechTtsFormat = "mp3" | "wav_8000" | "pcm_16000";
|
|
59
|
-
|
|
60
|
-
async function resolveClient(): Promise<
|
|
61
|
-
{ client: CadetCloudClient } | { error: CloudSpeechResult<never> }
|
|
62
|
-
> {
|
|
63
|
-
const client = await CadetCloudClient.create();
|
|
64
|
-
if (!client) {
|
|
65
|
-
return {
|
|
66
|
-
error: {
|
|
67
|
-
ok: false,
|
|
68
|
-
kind: "unavailable",
|
|
69
|
-
message: "Cloud speech is unavailable: no Cadet Cloud connection.",
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (!client.cloudAssistantId) {
|
|
74
|
-
return {
|
|
75
|
-
error: {
|
|
76
|
-
ok: false,
|
|
77
|
-
kind: "unavailable",
|
|
78
|
-
message:
|
|
79
|
-
"Cloud speech is unavailable: platform assistant ID is missing.",
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return { client };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Whether cloud speech can be used at all: a cloud connection whose
|
|
88
|
-
* assistant identity is fully provisioned. A stored API key alone is not
|
|
89
|
-
* enough — synthesis/transcription would fail before any request is made.
|
|
90
|
-
*/
|
|
91
|
-
export async function managedSpeechAvailable(): Promise<boolean> {
|
|
92
|
-
return !("error" in (await resolveClient()));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export async function managedSpeechTranscribe(input: {
|
|
96
|
-
audio: Buffer;
|
|
97
|
-
mimeType: string;
|
|
98
|
-
source?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Spoken language to decode: a BCP-47 code, or `"multi"` for nova-3
|
|
101
|
-
* code-switching. Omitted means the cloud sends none, which Deepgram
|
|
102
|
-
* decodes as English rather than detecting the language. Older platform
|
|
103
|
-
* builds that predate the field ignore it, so sending one is safe before
|
|
104
|
-
* the cloud side deploys.
|
|
105
|
-
*/
|
|
106
|
-
language?: string;
|
|
107
|
-
signal?: AbortSignal;
|
|
108
|
-
}): Promise<CloudSpeechResult<CloudSpeechTranscription>> {
|
|
109
|
-
const resolved = await resolveClient();
|
|
110
|
-
if ("error" in resolved) {
|
|
111
|
-
return resolved.error;
|
|
112
|
-
}
|
|
113
|
-
const { client } = resolved;
|
|
114
|
-
|
|
115
|
-
const response = await client.fetch(
|
|
116
|
-
`/v1/assistants/${encodeURIComponent(client.cloudAssistantId)}/cloud-speech/stt/transcribe/`,
|
|
117
|
-
{
|
|
118
|
-
method: "POST",
|
|
119
|
-
headers: { "Content-Type": "application/json" },
|
|
120
|
-
body: JSON.stringify({
|
|
121
|
-
audioBase64: input.audio.toString("base64"),
|
|
122
|
-
mimeType: input.mimeType,
|
|
123
|
-
...(input.source !== undefined ? { source: input.source } : {}),
|
|
124
|
-
...(input.language ? { language: input.language } : {}),
|
|
125
|
-
}),
|
|
126
|
-
signal: input.signal,
|
|
127
|
-
},
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
if (!response.ok) {
|
|
131
|
-
return await platformError(response, "transcription");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const parsed = CloudSpeechTranscriptionSchema.safeParse(
|
|
135
|
-
await response.json().catch(() => null),
|
|
136
|
-
);
|
|
137
|
-
if (!parsed.success) {
|
|
138
|
-
return {
|
|
139
|
-
ok: false,
|
|
140
|
-
kind: "platform-error",
|
|
141
|
-
status: response.status,
|
|
142
|
-
message: "Cloud speech transcription returned a malformed response.",
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
ok: true,
|
|
147
|
-
value: {
|
|
148
|
-
text: parsed.data.text,
|
|
149
|
-
durationSeconds: parsed.data.durationSeconds,
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export async function managedSpeechSynthesize(input: {
|
|
155
|
-
text: string;
|
|
156
|
-
format: CloudSpeechTtsFormat;
|
|
157
|
-
/** Voice model (e.g. "aura-2-thalia-en"); omitted = platform default. */
|
|
158
|
-
model?: string;
|
|
159
|
-
signal?: AbortSignal;
|
|
160
|
-
}): Promise<CloudSpeechResult<CloudSpeechSynthesis>> {
|
|
161
|
-
const resolved = await resolveClient();
|
|
162
|
-
if ("error" in resolved) {
|
|
163
|
-
return resolved.error;
|
|
164
|
-
}
|
|
165
|
-
const { client } = resolved;
|
|
166
|
-
|
|
167
|
-
const response = await client.fetch(
|
|
168
|
-
`/v1/assistants/${encodeURIComponent(client.cloudAssistantId)}/cloud-speech/tts/synthesize/`,
|
|
169
|
-
{
|
|
170
|
-
method: "POST",
|
|
171
|
-
headers: { "Content-Type": "application/json" },
|
|
172
|
-
body: JSON.stringify({
|
|
173
|
-
text: input.text,
|
|
174
|
-
format: input.format,
|
|
175
|
-
...(input.model !== undefined ? { model: input.model } : {}),
|
|
176
|
-
}),
|
|
177
|
-
signal: input.signal,
|
|
178
|
-
},
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
if (!response.ok) {
|
|
182
|
-
return await platformError(response, "synthesis");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const audio = Buffer.from(await response.arrayBuffer());
|
|
186
|
-
if (audio.length === 0) {
|
|
187
|
-
return {
|
|
188
|
-
ok: false,
|
|
189
|
-
kind: "platform-error",
|
|
190
|
-
status: response.status,
|
|
191
|
-
message: "Cloud speech synthesis returned empty audio.",
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
ok: true,
|
|
196
|
-
value: {
|
|
197
|
-
audio,
|
|
198
|
-
contentType: response.headers.get("content-type") ?? "audio/mpeg",
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export interface CloudSpeechVoice {
|
|
204
|
-
model: string;
|
|
205
|
-
label: string;
|
|
206
|
-
description: string;
|
|
207
|
-
sampleUrl: string;
|
|
208
|
-
/** Upstream provider that synthesizes this voice (e.g. "deepgram"). */
|
|
209
|
-
source: string;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export interface CloudSpeechVoiceCatalog {
|
|
213
|
-
/** Offered voices in display order; only currently-usable voices. */
|
|
214
|
-
voices: CloudSpeechVoice[];
|
|
215
|
-
/** Always one of `voices`; null when no voices are offered. */
|
|
216
|
-
defaultModel: string | null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const CloudSpeechVoiceSchema = z.object({
|
|
220
|
-
model: z.string(),
|
|
221
|
-
label: z.string(),
|
|
222
|
-
description: z.string(),
|
|
223
|
-
sampleUrl: z.string(),
|
|
224
|
-
source: z.string(),
|
|
225
|
-
});
|
|
226
|
-
const CloudSpeechVoiceCatalogSchema = z.object({
|
|
227
|
-
voices: z.array(CloudSpeechVoiceSchema.nullable().catch(null)),
|
|
228
|
-
defaultModel: z.string().nullable().optional().catch(null),
|
|
229
|
-
});
|
|
230
|
-
const CloudSpeechErrorSchema = z.object({
|
|
231
|
-
code: z.string().optional().catch(undefined),
|
|
232
|
-
detail: z.string().optional().catch(undefined),
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
export async function managedSpeechVoices(input?: {
|
|
236
|
-
signal?: AbortSignal;
|
|
237
|
-
}): Promise<CloudSpeechResult<CloudSpeechVoiceCatalog>> {
|
|
238
|
-
const resolved = await resolveClient();
|
|
239
|
-
if ("error" in resolved) {
|
|
240
|
-
return resolved.error;
|
|
241
|
-
}
|
|
242
|
-
const { client } = resolved;
|
|
243
|
-
|
|
244
|
-
const response = await client.fetch(
|
|
245
|
-
`/v1/assistants/${encodeURIComponent(client.cloudAssistantId)}/cloud-speech/tts/voices/`,
|
|
246
|
-
{ method: "GET", signal: input?.signal },
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
if (!response.ok) {
|
|
250
|
-
return await platformError(response, "voice listing");
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const parsed = CloudSpeechVoiceCatalogSchema.safeParse(
|
|
254
|
-
await response.json().catch(() => null),
|
|
255
|
-
);
|
|
256
|
-
if (!parsed.success) {
|
|
257
|
-
return {
|
|
258
|
-
ok: false,
|
|
259
|
-
kind: "platform-error",
|
|
260
|
-
status: response.status,
|
|
261
|
-
message: "Cloud speech voice listing returned a malformed response.",
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
ok: true,
|
|
266
|
-
value: {
|
|
267
|
-
voices: parsed.data.voices.filter(
|
|
268
|
-
(voice): voice is CloudSpeechVoice => voice !== null,
|
|
269
|
-
),
|
|
270
|
-
defaultModel: parsed.data.defaultModel ?? null,
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async function platformError(
|
|
276
|
-
response: Response,
|
|
277
|
-
operation: string,
|
|
278
|
-
): Promise<CloudSpeechResult<never>> {
|
|
279
|
-
let code: string | undefined;
|
|
280
|
-
let detail: string | undefined;
|
|
281
|
-
try {
|
|
282
|
-
const parsed = CloudSpeechErrorSchema.safeParse(await response.json());
|
|
283
|
-
if (parsed.success) {
|
|
284
|
-
code = parsed.data.code;
|
|
285
|
-
detail = parsed.data.detail;
|
|
286
|
-
}
|
|
287
|
-
} catch {
|
|
288
|
-
// Non-JSON error body; status alone will have to do.
|
|
289
|
-
}
|
|
290
|
-
return {
|
|
291
|
-
ok: false,
|
|
292
|
-
kind: "platform-error",
|
|
293
|
-
status: response.status,
|
|
294
|
-
code,
|
|
295
|
-
detail,
|
|
296
|
-
message:
|
|
297
|
-
detail ??
|
|
298
|
-
`Cloud speech ${operation} failed (platform returned ${response.status}).`,
|
|
299
|
-
};
|
|
300
|
-
}
|