@alexkroman1/aai 1.3.2 → 1.4.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/.turbo/turbo-build.log +18 -14
- package/CHANGELOG.md +2 -0
- package/dist/_internal-types-3p3OJZPb.js +145 -0
- package/dist/anthropic-BrUCPKUc.js +10 -0
- package/dist/assemblyai-Cxg9eobY.js +18 -0
- package/dist/cartesia-DwDk2tEu.js +10 -0
- package/dist/host/_pipeline-test-fakes.d.ts +5 -5
- package/dist/host/pipeline-session.d.ts +5 -5
- package/dist/host/providers/resolve.d.ts +34 -0
- package/dist/host/providers/stt/assemblyai.d.ts +9 -18
- package/dist/host/providers/tts/cartesia.d.ts +11 -18
- package/dist/host/runtime-barrel.js +345 -42
- package/dist/host/runtime.d.ts +13 -9
- package/dist/index.js +2 -91
- package/dist/sdk/_internal-types.d.ts +27 -1
- package/dist/sdk/manifest-barrel.d.ts +2 -0
- package/dist/sdk/manifest-barrel.js +2 -2
- package/dist/sdk/manifest.d.ts +13 -2
- package/dist/sdk/protocol.d.ts +3 -3
- package/dist/sdk/protocol.js +1 -1
- package/dist/sdk/providers/llm/anthropic.d.ts +23 -0
- package/dist/sdk/providers/llm-barrel.d.ts +9 -0
- package/dist/sdk/providers/llm-barrel.js +2 -0
- package/dist/sdk/providers/stt/assemblyai.d.ts +30 -0
- package/dist/sdk/providers/stt-barrel.d.ts +9 -0
- package/dist/sdk/providers/stt-barrel.js +2 -0
- package/dist/sdk/providers/tts/cartesia.d.ts +23 -0
- package/dist/sdk/providers/tts-barrel.d.ts +9 -0
- package/dist/sdk/providers/tts-barrel.js +2 -0
- package/dist/sdk/providers.d.ts +59 -11
- package/dist/types-KUgezM6u.js +128 -0
- package/host/_pipeline-test-fakes.ts +6 -6
- package/host/integration/pipeline-reference.integration.test.ts +4 -4
- package/host/pipeline-session.ts +6 -6
- package/host/providers/providers.test-d.ts +19 -10
- package/host/providers/resolve.ts +87 -0
- package/host/providers/stt/assemblyai.test.ts +2 -2
- package/host/providers/stt/assemblyai.ts +25 -47
- package/host/providers/tts/cartesia.test.ts +2 -2
- package/host/providers/tts/cartesia.ts +43 -73
- package/host/runtime.ts +66 -39
- package/package.json +13 -7
- package/sdk/__snapshots__/exports.test.ts.snap +2 -0
- package/sdk/__snapshots__/schema-shapes.test.ts.snap +4 -0
- package/sdk/_internal-types.ts +28 -1
- package/sdk/define.test.ts +12 -10
- package/sdk/manifest-barrel.ts +2 -0
- package/sdk/manifest.test.ts +6 -3
- package/sdk/manifest.ts +26 -18
- package/sdk/providers/llm/anthropic.ts +31 -0
- package/sdk/providers/llm-barrel.ts +12 -0
- package/sdk/providers/stt/assemblyai.ts +38 -0
- package/sdk/providers/stt-barrel.ts +12 -0
- package/sdk/providers/tts/cartesia.ts +31 -0
- package/sdk/providers/tts-barrel.ts +12 -0
- package/sdk/providers.ts +81 -17
- package/dist/_internal-types-CoDTiBd1.js +0 -61
- package/dist/host/providers/llm.d.ts +0 -2
- package/dist/host/providers/stt-barrel.d.ts +0 -8
- package/dist/host/providers/stt-barrel.js +0 -92
- package/dist/host/providers/stt.d.ts +0 -2
- package/dist/host/providers/tts-barrel.d.ts +0 -8
- package/dist/host/providers/tts-barrel.js +0 -182
- package/dist/host/providers/tts.d.ts +0 -2
- package/dist/types-Cfx_4QDK.js +0 -39
- package/host/providers/llm.ts +0 -3
- package/host/providers/stt-barrel.ts +0 -13
- package/host/providers/stt.ts +0 -3
- package/host/providers/tts-barrel.ts +0 -13
- package/host/providers/tts.ts +0 -3
- /package/dist/{constants-BL3nvg4I.js → constants-C2nirZUI.js} +0 -0
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@alexkroman1/aai/tts` subpath barrel. Re-exports the TTS provider
|
|
3
|
-
* contract types (via `tts.ts` → `sdk/providers.ts`) alongside the
|
|
4
|
-
* concrete Cartesia adapter factory. Task 9 owns wiring this file
|
|
5
|
-
* into `package.json` exports.
|
|
6
|
-
*/
|
|
7
|
-
export * from "./tts/cartesia.ts";
|
|
8
|
-
export type * from "./tts.ts";
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { createNanoEvents } from "nanoevents";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { Cartesia } from "@cartesia/cartesia-js";
|
|
4
|
-
//#region host/providers/tts/cartesia.ts
|
|
5
|
-
/**
|
|
6
|
-
* Cartesia TTS adapter — streaming WebSocket with per-turn `context_id`.
|
|
7
|
-
*
|
|
8
|
-
* Wraps `@cartesia/cartesia-js`'s `TTSWS` / `TTSWSContext` and normalizes it
|
|
9
|
-
* onto the {@link TtsProvider} / {@link TtsEvents} contract consumed by the
|
|
10
|
-
* pipeline orchestrator.
|
|
11
|
-
*
|
|
12
|
-
* **Per-turn context lifecycle.** Each `sendText(...)` within the same turn
|
|
13
|
-
* appends to the same Cartesia context. On `flush()` or `cancel()`, a new
|
|
14
|
-
* context is minted for the next turn — so concurrent `cancel({ contextId })`
|
|
15
|
-
* only targets the in-flight turn, never the one that follows.
|
|
16
|
-
*
|
|
17
|
-
* **Audio format.** The adapter requests `raw` / `pcm_s16le` at the
|
|
18
|
-
* negotiated `sampleRate` so it can forward chunks as `Int16Array` with no
|
|
19
|
-
* conversion.
|
|
20
|
-
*/
|
|
21
|
-
function makeError(message) {
|
|
22
|
-
const err = new Error(message);
|
|
23
|
-
err.code = "tts_stream_error";
|
|
24
|
-
return err;
|
|
25
|
-
}
|
|
26
|
-
/** PCM16 sample rates supported by Cartesia's `raw` output format. */
|
|
27
|
-
const CARTESIA_PCM16_RATES = [
|
|
28
|
-
8e3,
|
|
29
|
-
16e3,
|
|
30
|
-
22050,
|
|
31
|
-
24e3,
|
|
32
|
-
44100,
|
|
33
|
-
48e3
|
|
34
|
-
];
|
|
35
|
-
function assertSupportedSampleRate(rate) {
|
|
36
|
-
if (CARTESIA_PCM16_RATES.includes(rate)) return rate;
|
|
37
|
-
const err = /* @__PURE__ */ new Error(`Cartesia TTS adapter: unsupported sample rate ${rate}. Supported: ${CARTESIA_PCM16_RATES.join(", ")}.`);
|
|
38
|
-
err.code = "tts_connect_failed";
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
function cartesia(opts) {
|
|
42
|
-
return {
|
|
43
|
-
name: "cartesia",
|
|
44
|
-
async open(openOpts) {
|
|
45
|
-
const apiKey = opts.apiKey ?? openOpts.apiKey ?? process.env.CARTESIA_API_KEY;
|
|
46
|
-
if (!apiKey) {
|
|
47
|
-
const err = /* @__PURE__ */ new Error("Cartesia TTS adapter: missing API key. Provide via the factory option, TtsOpenOptions, or the CARTESIA_API_KEY environment variable.");
|
|
48
|
-
err.code = "tts_auth_failed";
|
|
49
|
-
throw err;
|
|
50
|
-
}
|
|
51
|
-
const sampleRate = assertSupportedSampleRate(openOpts.sampleRate);
|
|
52
|
-
const model = opts.model ?? "sonic-2";
|
|
53
|
-
const language = opts.language ?? "en";
|
|
54
|
-
const client = new Cartesia({ apiKey });
|
|
55
|
-
let ws;
|
|
56
|
-
try {
|
|
57
|
-
ws = await client.tts.websocket();
|
|
58
|
-
} catch (cause) {
|
|
59
|
-
const err = /* @__PURE__ */ new Error(`Cartesia TTS: connect failed: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
60
|
-
err.code = "tts_connect_failed";
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
const emitter = createNanoEvents();
|
|
64
|
-
let closed = false;
|
|
65
|
-
/** Mint a fresh context bound to the shared TTSWS connection. */
|
|
66
|
-
const mintContext = () => ws.context({
|
|
67
|
-
model_id: model,
|
|
68
|
-
voice: {
|
|
69
|
-
mode: "id",
|
|
70
|
-
id: opts.voice
|
|
71
|
-
},
|
|
72
|
-
output_format: {
|
|
73
|
-
container: "raw",
|
|
74
|
-
encoding: "pcm_s16le",
|
|
75
|
-
sample_rate: sampleRate
|
|
76
|
-
},
|
|
77
|
-
contextId: randomUUID()
|
|
78
|
-
});
|
|
79
|
-
let context = mintContext();
|
|
80
|
-
/**
|
|
81
|
-
* `doneEmitted` guards against emitting `done` more than once per turn.
|
|
82
|
-
* Reset whenever a fresh context is minted (i.e. at turn boundaries).
|
|
83
|
-
*/
|
|
84
|
-
let doneEmitted = false;
|
|
85
|
-
const rotateContext = () => {
|
|
86
|
-
context = mintContext();
|
|
87
|
-
doneEmitted = false;
|
|
88
|
-
};
|
|
89
|
-
const emitDoneOnce = () => {
|
|
90
|
-
if (doneEmitted || closed) return;
|
|
91
|
-
doneEmitted = true;
|
|
92
|
-
emitter.emit("done");
|
|
93
|
-
};
|
|
94
|
-
ws.on("chunk", (event) => {
|
|
95
|
-
if (closed) return;
|
|
96
|
-
if (event.context_id !== context.contextId) return;
|
|
97
|
-
const buf = event.audio;
|
|
98
|
-
if (!buf || buf.byteLength === 0) return;
|
|
99
|
-
const evenBytes = buf.byteLength - buf.byteLength % 2;
|
|
100
|
-
if (evenBytes === 0) return;
|
|
101
|
-
const pcm = new Int16Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + evenBytes));
|
|
102
|
-
emitter.emit("audio", pcm);
|
|
103
|
-
});
|
|
104
|
-
ws.on("done", (event) => {
|
|
105
|
-
if (closed) return;
|
|
106
|
-
if (event.context_id !== context.contextId) return;
|
|
107
|
-
emitDoneOnce();
|
|
108
|
-
});
|
|
109
|
-
ws.on("error", (err) => {
|
|
110
|
-
if (closed) return;
|
|
111
|
-
emitter.emit("error", makeError(err?.message ?? String(err)));
|
|
112
|
-
});
|
|
113
|
-
const close = async () => {
|
|
114
|
-
if (closed) return;
|
|
115
|
-
closed = true;
|
|
116
|
-
try {
|
|
117
|
-
ws.close({
|
|
118
|
-
code: 1e3,
|
|
119
|
-
reason: "client close"
|
|
120
|
-
});
|
|
121
|
-
} catch {}
|
|
122
|
-
};
|
|
123
|
-
if (openOpts.signal.aborted) close();
|
|
124
|
-
else openOpts.signal.addEventListener("abort", () => void close(), { once: true });
|
|
125
|
-
/** Static part of each generation request; only `transcript` and
|
|
126
|
-
* `continue` vary per send. Pinned here so `language` threads through. */
|
|
127
|
-
const baseRequest = {
|
|
128
|
-
model_id: model,
|
|
129
|
-
voice: {
|
|
130
|
-
mode: "id",
|
|
131
|
-
id: opts.voice
|
|
132
|
-
},
|
|
133
|
-
output_format: {
|
|
134
|
-
container: "raw",
|
|
135
|
-
encoding: "pcm_s16le",
|
|
136
|
-
sample_rate: sampleRate
|
|
137
|
-
},
|
|
138
|
-
language
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Swallow rejections from async SDK calls — the global `error`
|
|
142
|
-
* listener on `ws` emits a normalized {@link TtsError}, so there's
|
|
143
|
-
* nothing useful for the caller to do with per-send failures.
|
|
144
|
-
*/
|
|
145
|
-
const ignoreRejection = (_err) => {};
|
|
146
|
-
return {
|
|
147
|
-
sendText(text) {
|
|
148
|
-
if (closed || text.length === 0) return;
|
|
149
|
-
context.send({
|
|
150
|
-
...baseRequest,
|
|
151
|
-
transcript: text,
|
|
152
|
-
continue: true
|
|
153
|
-
}).catch(ignoreRejection);
|
|
154
|
-
},
|
|
155
|
-
flush() {
|
|
156
|
-
if (closed) return;
|
|
157
|
-
context.send({
|
|
158
|
-
...baseRequest,
|
|
159
|
-
transcript: "",
|
|
160
|
-
continue: false
|
|
161
|
-
}).catch(ignoreRejection);
|
|
162
|
-
queueMicrotask(emitDoneOnce);
|
|
163
|
-
rotateContext();
|
|
164
|
-
},
|
|
165
|
-
cancel() {
|
|
166
|
-
if (closed) return;
|
|
167
|
-
context.cancel().catch(ignoreRejection);
|
|
168
|
-
emitDoneOnce();
|
|
169
|
-
rotateContext();
|
|
170
|
-
},
|
|
171
|
-
on(event, fn) {
|
|
172
|
-
return emitter.on(event, fn);
|
|
173
|
-
},
|
|
174
|
-
close,
|
|
175
|
-
_ws: ws,
|
|
176
|
-
_currentContextId: () => context.contextId
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
//#endregion
|
|
182
|
-
export { cartesia };
|
package/dist/types-Cfx_4QDK.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
//#region sdk/types.ts
|
|
3
|
-
/**
|
|
4
|
-
* Core type definitions for the AAI agent SDK.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Default system prompt used when `systemPrompt` is not provided.
|
|
8
|
-
*
|
|
9
|
-
* Optimized for voice-first interactions: short sentences, no visual
|
|
10
|
-
* formatting, confident tone, and concise answers.
|
|
11
|
-
*/
|
|
12
|
-
const DEFAULT_SYSTEM_PROMPT = `\
|
|
13
|
-
You are AAI, a helpful AI assistant.
|
|
14
|
-
|
|
15
|
-
Voice-First Rules:
|
|
16
|
-
- Optimize for natural speech. Avoid jargon unless central to the answer. \
|
|
17
|
-
Use short, punchy sentences.
|
|
18
|
-
- Never mention "search results," "sources," or "the provided text." \
|
|
19
|
-
Speak as if the knowledge is your own.
|
|
20
|
-
- No visual formatting. Do not say "bullet point," "bold," or "bracketed one." \
|
|
21
|
-
If you need to list items, say "First," "Next," and "Finally."
|
|
22
|
-
- Start with the most important information. No introductory filler.
|
|
23
|
-
- Be concise. Keep answers to 1-3 sentences. For complex topics, provide a high-level summary.
|
|
24
|
-
- Be confident. Avoid hedging phrases like "It seems that" or "I believe."
|
|
25
|
-
- If you don't have enough information, say so directly rather than guessing.
|
|
26
|
-
- Never use exclamation points. Keep your tone calm and conversational.`;
|
|
27
|
-
/** Default greeting spoken when a session starts. */
|
|
28
|
-
const DEFAULT_GREETING = "Hey there. I'm a voice assistant. What can I help you with?";
|
|
29
|
-
/** @internal Zod schema for {@link BuiltinTool}. Exported for reuse in internal schemas. */
|
|
30
|
-
const BuiltinToolSchema = z.enum([
|
|
31
|
-
"web_search",
|
|
32
|
-
"visit_webpage",
|
|
33
|
-
"fetch_json",
|
|
34
|
-
"run_code"
|
|
35
|
-
]);
|
|
36
|
-
/** @internal Zod schema for {@link ToolChoice}. Exported for reuse in internal schemas. */
|
|
37
|
-
const ToolChoiceSchema = z.enum(["auto", "required"]);
|
|
38
|
-
//#endregion
|
|
39
|
-
export { ToolChoiceSchema as i, DEFAULT_GREETING as n, DEFAULT_SYSTEM_PROMPT as r, BuiltinToolSchema as t };
|
package/host/providers/llm.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
-
/**
|
|
3
|
-
* `@alexkroman1/aai/stt` subpath barrel. Re-exports the STT provider
|
|
4
|
-
* contract types (via `stt.ts` → `sdk/providers.ts`) alongside the
|
|
5
|
-
* concrete AssemblyAI adapter factory. Task 9 owns wiring this file
|
|
6
|
-
* into `package.json` exports.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// biome-ignore lint/performance/noReExportAll: subpath barrel
|
|
10
|
-
export * from "./stt/assemblyai.ts";
|
|
11
|
-
// Type-only re-export — no biome suppression needed; `export type *` is
|
|
12
|
-
// excluded from the `noReExportAll` rule.
|
|
13
|
-
export type * from "./stt.ts";
|
package/host/providers/stt.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
-
/**
|
|
3
|
-
* `@alexkroman1/aai/tts` subpath barrel. Re-exports the TTS provider
|
|
4
|
-
* contract types (via `tts.ts` → `sdk/providers.ts`) alongside the
|
|
5
|
-
* concrete Cartesia adapter factory. Task 9 owns wiring this file
|
|
6
|
-
* into `package.json` exports.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// biome-ignore lint/performance/noReExportAll: subpath barrel
|
|
10
|
-
export * from "./tts/cartesia.ts";
|
|
11
|
-
// Type-only re-export — no biome suppression needed; `export type *` is
|
|
12
|
-
// excluded from the `noReExportAll` rule.
|
|
13
|
-
export type * from "./tts.ts";
|
package/host/providers/tts.ts
DELETED
|
File without changes
|