@alexkroman1/aai 1.3.1 → 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 +4 -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
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
|
|
2
|
-
> @alexkroman1/aai@1.
|
|
2
|
+
> @alexkroman1/aai@1.4.0 build /home/runner/work/agent/agent/packages/aai
|
|
3
3
|
> tsdown && tsc -p tsconfig.build.json
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m [34mtsdown v0.21.7[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.12[39m
|
|
6
6
|
[34mℹ[39m config file: [4m/home/runner/work/agent/agent/packages/aai/tsdown.config.ts[24m
|
|
7
|
-
[34mℹ[39m entry: [34mindex.ts, sdk/protocol.ts, host/runtime-barrel.ts, sdk/manifest-barrel.ts,
|
|
7
|
+
[34mℹ[39m entry: [34mindex.ts, sdk/protocol.ts, host/runtime-barrel.ts, sdk/manifest-barrel.ts, sdk/providers/stt-barrel.ts, sdk/providers/tts-barrel.ts, sdk/providers/llm-barrel.ts[39m
|
|
8
8
|
[34mℹ[39m target: [34mnode22[39m
|
|
9
9
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
10
|
[34mℹ[39m Build start
|
|
11
|
-
[34mℹ[39m [2mdist/[22m[1mhost/runtime-barrel.js[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[1msdk/
|
|
15
|
-
[34mℹ[39m [2mdist/[22m[
|
|
16
|
-
[34mℹ[39m [2mdist/[22m[1msdk/
|
|
17
|
-
[34mℹ[39m [2mdist/[
|
|
18
|
-
[34mℹ[39m [2mdist/[
|
|
19
|
-
[34mℹ[39m [2mdist/[
|
|
20
|
-
[34mℹ[39m [2mdist/[
|
|
21
|
-
[34mℹ[39m
|
|
22
|
-
[
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mhost/runtime-barrel.js[22m [2m74.18 kB[22m [2m│ gzip: 22.09 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[1msdk/protocol.js[22m [2m 4.75 kB[22m [2m│ gzip: 1.76 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m 2.88 kB[22m [2m│ gzip: 1.24 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[1msdk/manifest-barrel.js[22m [2m 0.36 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
15
|
+
[34mℹ[39m [2mdist/[22m[1msdk/providers/stt-barrel.js[22m [2m 0.13 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
16
|
+
[34mℹ[39m [2mdist/[22m[1msdk/providers/llm-barrel.js[22m [2m 0.12 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
17
|
+
[34mℹ[39m [2mdist/[22m[1msdk/providers/tts-barrel.js[22m [2m 0.12 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
18
|
+
[34mℹ[39m [2mdist/[22mtypes-KUgezM6u.js [2m 5.64 kB[22m [2m│ gzip: 2.39 kB[22m
|
|
19
|
+
[34mℹ[39m [2mdist/[22m_internal-types-3p3OJZPb.js [2m 5.61 kB[22m [2m│ gzip: 2.07 kB[22m
|
|
20
|
+
[34mℹ[39m [2mdist/[22mconstants-C2nirZUI.js [2m 3.10 kB[22m [2m│ gzip: 1.38 kB[22m
|
|
21
|
+
[34mℹ[39m [2mdist/[22mws-upgrade-BeOQ7fXL.js [2m 1.14 kB[22m [2m│ gzip: 0.54 kB[22m
|
|
22
|
+
[34mℹ[39m [2mdist/[22massemblyai-Cxg9eobY.js [2m 0.53 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
23
|
+
[34mℹ[39m [2mdist/[22manthropic-BrUCPKUc.js [2m 0.23 kB[22m [2m│ gzip: 0.18 kB[22m
|
|
24
|
+
[34mℹ[39m [2mdist/[22mcartesia-DwDk2tEu.js [2m 0.22 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
25
|
+
[34mℹ[39m 14 files, total: 99.00 kB
|
|
26
|
+
[32m✔[39m Build complete in [32m39ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { i as ToolChoiceSchema, o as validateAllowedHostPattern, t as BuiltinToolSchema } from "./types-KUgezM6u.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region sdk/providers.ts
|
|
4
|
+
/**
|
|
5
|
+
* Enforce the all-or-nothing provider rule and return the derived mode.
|
|
6
|
+
*
|
|
7
|
+
* Pipeline mode requires STT, LLM, and TTS all set; S2S mode requires
|
|
8
|
+
* none of them. Anything in-between is a configuration error.
|
|
9
|
+
*/
|
|
10
|
+
function assertProviderTriple(stt, llm, tts) {
|
|
11
|
+
const count = (stt != null ? 1 : 0) + (llm != null ? 1 : 0) + (tts != null ? 1 : 0);
|
|
12
|
+
if (count !== 0 && count !== 3) throw new Error("stt, llm, and tts must be set together");
|
|
13
|
+
return count === 3 ? "pipeline" : "s2s";
|
|
14
|
+
}
|
|
15
|
+
/** Build an {@link SttError} with a typed `code`. Zero-dep helper so both sdk/ and host/ can use it. */
|
|
16
|
+
function makeSttError(code, message) {
|
|
17
|
+
return Object.assign(new Error(message), { code });
|
|
18
|
+
}
|
|
19
|
+
/** Build a {@link TtsError} with a typed `code`. Mirror of {@link makeSttError}. */
|
|
20
|
+
function makeTtsError(code, message) {
|
|
21
|
+
return Object.assign(new Error(message), { code });
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region sdk/manifest.ts
|
|
25
|
+
/**
|
|
26
|
+
* Canonical manifest format for directory-based agents.
|
|
27
|
+
*
|
|
28
|
+
* Flows from build → host → sdk. Validated via Zod at the boundary,
|
|
29
|
+
* then used as a plain typed object throughout the runtime.
|
|
30
|
+
*/
|
|
31
|
+
const ToolManifestSchema = z.object({
|
|
32
|
+
description: z.string(),
|
|
33
|
+
parameters: z.record(z.string(), z.unknown()).optional()
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Provider descriptor — a `{ kind, options }` pair produced by factories
|
|
37
|
+
* like `assemblyAI(...)` / `anthropic(...)` / `cartesia(...)`. Kept
|
|
38
|
+
* deliberately generic at the schema layer: kind-specific validation lives
|
|
39
|
+
* in the host-side resolver, which knows what each adapter expects.
|
|
40
|
+
*/
|
|
41
|
+
const ProviderDescriptorSchema = z.object({
|
|
42
|
+
kind: z.string().min(1),
|
|
43
|
+
options: z.record(z.string(), z.unknown())
|
|
44
|
+
});
|
|
45
|
+
z.object({
|
|
46
|
+
name: z.string().min(1),
|
|
47
|
+
systemPrompt: z.string().optional(),
|
|
48
|
+
greeting: z.string().optional(),
|
|
49
|
+
sttPrompt: z.string().optional(),
|
|
50
|
+
builtinTools: z.array(BuiltinToolSchema).optional(),
|
|
51
|
+
maxSteps: z.number().int().positive().optional(),
|
|
52
|
+
toolChoice: z.enum(["auto", "required"]).optional(),
|
|
53
|
+
idleTimeoutMs: z.number().int().positive().optional(),
|
|
54
|
+
theme: z.record(z.string(), z.string()).optional(),
|
|
55
|
+
tools: z.record(z.string(), ToolManifestSchema).optional(),
|
|
56
|
+
allowedHosts: z.array(z.string()).optional().superRefine((hosts, ctx) => {
|
|
57
|
+
if (!hosts) return;
|
|
58
|
+
for (const h of hosts) {
|
|
59
|
+
const result = validateAllowedHostPattern(h);
|
|
60
|
+
if (!result.valid) ctx.addIssue({
|
|
61
|
+
code: z.ZodIssueCode.custom,
|
|
62
|
+
message: `Invalid allowedHosts pattern "${h}": ${result.reason}`
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
stt: ProviderDescriptorSchema.optional(),
|
|
67
|
+
llm: ProviderDescriptorSchema.optional(),
|
|
68
|
+
tts: ProviderDescriptorSchema.optional()
|
|
69
|
+
});
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region sdk/_internal-types.ts
|
|
72
|
+
/**
|
|
73
|
+
* Zod schema for serializable agent configuration sent over the wire.
|
|
74
|
+
*
|
|
75
|
+
* This is the JSON-safe subset of the agent definition that can be
|
|
76
|
+
* transmitted between the worker and the host process via structured clone.
|
|
77
|
+
*/
|
|
78
|
+
const AgentConfigSchema = z.object({
|
|
79
|
+
name: z.string().min(1),
|
|
80
|
+
systemPrompt: z.string(),
|
|
81
|
+
greeting: z.string(),
|
|
82
|
+
sttPrompt: z.string().optional(),
|
|
83
|
+
maxSteps: z.number().int().positive().optional(),
|
|
84
|
+
toolChoice: ToolChoiceSchema.optional(),
|
|
85
|
+
builtinTools: z.array(BuiltinToolSchema).readonly().optional(),
|
|
86
|
+
idleTimeoutMs: z.number().nonnegative().optional(),
|
|
87
|
+
stt: ProviderDescriptorSchema.optional(),
|
|
88
|
+
llm: ProviderDescriptorSchema.optional(),
|
|
89
|
+
tts: ProviderDescriptorSchema.optional(),
|
|
90
|
+
mode: z.enum(["s2s", "pipeline"]).optional()
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Extract the serializable {@link AgentConfig} subset from a source object.
|
|
94
|
+
*
|
|
95
|
+
* When `stt`, `llm`, and `tts` descriptors are present they are all three
|
|
96
|
+
* required (or none) — enforced here so the server can trust the config.
|
|
97
|
+
* `mode` is derived from their presence.
|
|
98
|
+
*/
|
|
99
|
+
function toAgentConfig(src) {
|
|
100
|
+
const config = {
|
|
101
|
+
name: src.name,
|
|
102
|
+
systemPrompt: src.systemPrompt,
|
|
103
|
+
greeting: src.greeting
|
|
104
|
+
};
|
|
105
|
+
if (src.sttPrompt !== void 0) config.sttPrompt = src.sttPrompt;
|
|
106
|
+
if (src.maxSteps !== void 0) config.maxSteps = src.maxSteps;
|
|
107
|
+
if (src.toolChoice !== void 0) config.toolChoice = src.toolChoice;
|
|
108
|
+
if (src.builtinTools) config.builtinTools = [...src.builtinTools];
|
|
109
|
+
if (src.idleTimeoutMs !== void 0) config.idleTimeoutMs = src.idleTimeoutMs;
|
|
110
|
+
config.mode = assertProviderTriple(src.stt, src.llm, src.tts);
|
|
111
|
+
if (config.mode === "pipeline") {
|
|
112
|
+
config.stt = src.stt;
|
|
113
|
+
config.llm = src.llm;
|
|
114
|
+
config.tts = src.tts;
|
|
115
|
+
}
|
|
116
|
+
return config;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Zod schema for serialized tool definitions sent over the wire.
|
|
120
|
+
*
|
|
121
|
+
* `parameters` must be a valid JSON Schema object (with `type`, `properties`,
|
|
122
|
+
* etc.) — the Vercel AI SDK wraps it via `jsonSchema()`.
|
|
123
|
+
*/
|
|
124
|
+
const ToolSchemaSchema = z.object({
|
|
125
|
+
name: z.string().min(1),
|
|
126
|
+
description: z.string().min(1),
|
|
127
|
+
parameters: z.record(z.string(), z.unknown())
|
|
128
|
+
});
|
|
129
|
+
/** Empty Zod object schema used as default when tools have no parameters. */
|
|
130
|
+
const EMPTY_PARAMS = z.object({});
|
|
131
|
+
/**
|
|
132
|
+
* Convert agent tool definitions to JSON Schema format for wire transport.
|
|
133
|
+
*
|
|
134
|
+
* Transforms the Zod-based `parameters` of each tool into a plain JSON Schema
|
|
135
|
+
* object suitable for structured clone / JSON serialization.
|
|
136
|
+
*/
|
|
137
|
+
function agentToolsToSchemas(tools) {
|
|
138
|
+
return Object.entries(tools).map(([name, def]) => ({
|
|
139
|
+
name,
|
|
140
|
+
description: def.description,
|
|
141
|
+
parameters: z.toJSONSchema(def.parameters ?? EMPTY_PARAMS)
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { toAgentConfig as a, makeSttError as c, agentToolsToSchemas as i, makeTtsError as l, EMPTY_PARAMS as n, ProviderDescriptorSchema as o, ToolSchemaSchema as r, assertProviderTriple as s, AgentConfigSchema as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region sdk/providers/stt/assemblyai.ts
|
|
2
|
+
/** Kind tag recognised by the host-side resolver. */
|
|
3
|
+
const ASSEMBLYAI_KIND = "assemblyai";
|
|
4
|
+
/**
|
|
5
|
+
* Build an AssemblyAI STT descriptor.
|
|
6
|
+
*
|
|
7
|
+
* The API key is resolved host-side from the agent's env
|
|
8
|
+
* (`ASSEMBLYAI_API_KEY`); there is no factory-time key parameter, so the
|
|
9
|
+
* descriptor stays free of secrets and safe to serialize.
|
|
10
|
+
*/
|
|
11
|
+
function assemblyAI(opts = {}) {
|
|
12
|
+
return {
|
|
13
|
+
kind: ASSEMBLYAI_KIND,
|
|
14
|
+
options: { ...opts }
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { assemblyAI as n, ASSEMBLYAI_KIND as t };
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import type { LanguageModel } from "ai";
|
|
16
16
|
import { type Emitter } from "nanoevents";
|
|
17
17
|
import { vi } from "vitest";
|
|
18
|
-
import type { SttEvents,
|
|
18
|
+
import type { SttEvents, SttOpener, SttOpenOptions, SttSession, TtsEvents, TtsOpener, TtsOpenOptions, TtsSession } from "../sdk/providers.ts";
|
|
19
19
|
export type FakeSttSession = SttSession & {
|
|
20
20
|
readonly emitter: Emitter<SttEvents>;
|
|
21
21
|
readonly opts: SttOpenOptions;
|
|
@@ -27,7 +27,7 @@ export type FakeSttSession = SttSession & {
|
|
|
27
27
|
fireFinal(text: string): void;
|
|
28
28
|
fireError(code: "stt_stream_error" | "stt_connect_failed" | "stt_auth_failed", message: string): void;
|
|
29
29
|
};
|
|
30
|
-
export type FakeSttProvider =
|
|
30
|
+
export type FakeSttProvider = SttOpener & {
|
|
31
31
|
/** The most recently opened session, or undefined if `open()` hasn't been called. */
|
|
32
32
|
last(): FakeSttSession | undefined;
|
|
33
33
|
readonly sessions: FakeSttSession[];
|
|
@@ -46,7 +46,7 @@ export type FakeTtsSession = TtsSession & {
|
|
|
46
46
|
fireAudio(pcm: Int16Array): void;
|
|
47
47
|
fireError(code: "tts_stream_error" | "tts_connect_failed" | "tts_auth_failed", message: string): void;
|
|
48
48
|
};
|
|
49
|
-
export type FakeTtsProvider =
|
|
49
|
+
export type FakeTtsProvider = TtsOpener & {
|
|
50
50
|
/** The most recently opened session, or undefined if `open()` hasn't been called. */
|
|
51
51
|
last(): FakeTtsSession | undefined;
|
|
52
52
|
readonly sessions: FakeTtsSession[];
|
|
@@ -63,12 +63,12 @@ export declare function createFakeTtsProvider(options?: {
|
|
|
63
63
|
* Fake STT provider that throws on `open()` with a given error code. Used to
|
|
64
64
|
* test atomic provider open — TTS should not be opened at all when STT fails.
|
|
65
65
|
*/
|
|
66
|
-
export declare function createFailingSttProvider(code: "stt_connect_failed" | "stt_auth_failed" | "stt_stream_error", message: string):
|
|
66
|
+
export declare function createFailingSttProvider(code: "stt_connect_failed" | "stt_auth_failed" | "stt_stream_error", message: string): SttOpener;
|
|
67
67
|
/**
|
|
68
68
|
* Fake TTS provider that throws on `open()` with a given error code. Used to
|
|
69
69
|
* test atomic provider open — STT should be closed when TTS fails.
|
|
70
70
|
*/
|
|
71
|
-
export declare function createFailingTtsProvider(code: "tts_connect_failed" | "tts_auth_failed" | "tts_stream_error", message: string):
|
|
71
|
+
export declare function createFailingTtsProvider(code: "tts_connect_failed" | "tts_auth_failed" | "tts_stream_error", message: string): TtsOpener;
|
|
72
72
|
/**
|
|
73
73
|
* A scripted stream part. `text` yields a `text-delta` in the LLM provider's
|
|
74
74
|
* raw wire format; `tool-call` / `tool-result` emit the corresponding parts
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { LanguageModel } from "ai";
|
|
9
9
|
import type { AgentConfig, ExecuteTool, ToolSchema } from "../sdk/_internal-types.ts";
|
|
10
10
|
import type { ClientSink } from "../sdk/protocol.ts";
|
|
11
|
-
import type {
|
|
11
|
+
import type { SttOpener, TtsOpener } from "../sdk/providers.ts";
|
|
12
12
|
import { type Logger } from "./runtime-config.ts";
|
|
13
13
|
import type { Session } from "./session.ts";
|
|
14
14
|
/** Configuration options for {@link createPipelineSession}. */
|
|
@@ -27,12 +27,12 @@ export interface PipelineSessionOptions {
|
|
|
27
27
|
toolGuidance?: readonly string[] | undefined;
|
|
28
28
|
/** Function to invoke tools by name. */
|
|
29
29
|
executeTool: ExecuteTool;
|
|
30
|
-
/** STT
|
|
31
|
-
stt:
|
|
30
|
+
/** STT opener (resolved from an {@link SttProvider} descriptor). */
|
|
31
|
+
stt: SttOpener;
|
|
32
32
|
/** LLM provider (Vercel AI SDK `LanguageModel`). */
|
|
33
33
|
llm: LanguageModel;
|
|
34
|
-
/** TTS
|
|
35
|
-
tts:
|
|
34
|
+
/** TTS opener (resolved from a {@link TtsProvider} descriptor). */
|
|
35
|
+
tts: TtsOpener;
|
|
36
36
|
/** STT API key. */
|
|
37
37
|
sttApiKey: string;
|
|
38
38
|
/** TTS API key. */
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Descriptor → concrete-provider resolution (host-only).
|
|
3
|
+
*
|
|
4
|
+
* User code (and the server, after extracting config from a bundled agent)
|
|
5
|
+
* holds `SttProvider` / `LlmProvider` / `TtsProvider` **descriptors** —
|
|
6
|
+
* plain `{ kind, options }` data. At session start the runtime calls the
|
|
7
|
+
* resolvers here to turn each descriptor into its openable / callable
|
|
8
|
+
* host-side counterpart, importing the third-party SDK only at that point.
|
|
9
|
+
*
|
|
10
|
+
* The guest sandbox never imports these functions, which is how the agent
|
|
11
|
+
* bundle stays free of `@ai-sdk/anthropic` / `assemblyai` /
|
|
12
|
+
* `@cartesia/cartesia-js`.
|
|
13
|
+
*/
|
|
14
|
+
import type { LanguageModel } from "ai";
|
|
15
|
+
import type { LlmProvider, SttOpener, SttProvider, TtsOpener, TtsProvider } from "../../sdk/providers.ts";
|
|
16
|
+
/**
|
|
17
|
+
* Look up a provider API key: agent env first (set via `aai secret put` or
|
|
18
|
+
* `.env`), then the host's `process.env` as a fallback for self-hosted mode.
|
|
19
|
+
* Returns `""` if neither has it — the caller decides whether that's fatal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveApiKey(envVar: string, env: Record<string, string>): string;
|
|
22
|
+
/** Resolve an {@link SttProvider} descriptor into a host-side opener. */
|
|
23
|
+
export declare function resolveStt(descriptor: SttProvider): SttOpener;
|
|
24
|
+
/** Resolve a {@link TtsProvider} descriptor into a host-side opener. */
|
|
25
|
+
export declare function resolveTts(descriptor: TtsProvider): TtsOpener;
|
|
26
|
+
/**
|
|
27
|
+
* Resolve an {@link LlmProvider} descriptor into a Vercel AI SDK
|
|
28
|
+
* {@link LanguageModel}.
|
|
29
|
+
*
|
|
30
|
+
* The API key is pulled from the agent's env (e.g. `ANTHROPIC_API_KEY`).
|
|
31
|
+
* Missing keys throw here — the pipeline session would fail on first
|
|
32
|
+
* `streamText` call otherwise, and the error is clearer at construction.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveLlm(descriptor: LlmProvider, env: Record<string, string>): LanguageModel;
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AssemblyAI Universal-Streaming STT
|
|
2
|
+
* AssemblyAI Universal-Streaming STT opener (host-only).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The user-facing descriptor factory (`assemblyAI(...)`) lives in
|
|
5
|
+
* `sdk/providers/stt/assemblyai.ts`. This module is the host-side
|
|
6
|
+
* counterpart: it takes the descriptor options + an API key and
|
|
7
|
+
* returns an {@link SttOpener} that the pipeline session drives.
|
|
7
8
|
*
|
|
8
9
|
* Default model: `"u3pro-rt"` (Universal-3 Pro Real-Time). The adapter
|
|
9
10
|
* maps that to the SDK's `"u3-rt-pro"` `speechModel` value; any other
|
|
10
11
|
* string is forwarded verbatim.
|
|
11
12
|
*/
|
|
12
13
|
import { type StreamingTranscriber } from "assemblyai";
|
|
13
|
-
import type {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Streaming speech model. Defaults to `"u3pro-rt"` (Universal-3 Pro
|
|
17
|
-
* Real-Time). Arbitrary strings are forwarded to the SDK unchanged.
|
|
18
|
-
*/
|
|
19
|
-
model?: "u3pro-rt" | string;
|
|
20
|
-
/**
|
|
21
|
-
* AssemblyAI API key. Falls back to `SttOpenOptions.apiKey`, then
|
|
22
|
-
* `process.env.ASSEMBLYAI_API_KEY`.
|
|
23
|
-
*/
|
|
24
|
-
apiKey?: string;
|
|
25
|
-
}
|
|
14
|
+
import type { AssemblyAIOptions } from "../../../sdk/providers/stt/assemblyai.ts";
|
|
15
|
+
import { type SttOpener, type SttSession } from "../../../sdk/providers.ts";
|
|
26
16
|
/** Internal: SttSession with a test-only handle to the raw SDK transcriber. */
|
|
27
17
|
export interface AssemblyAISession extends SttSession {
|
|
28
18
|
/** @internal Test-only: exposes the underlying SDK transcriber for fixture replay. */
|
|
29
19
|
readonly _transcriber: StreamingTranscriber;
|
|
30
20
|
}
|
|
31
|
-
|
|
21
|
+
/** Build an {@link SttOpener} from resolved AssemblyAI descriptor options. */
|
|
22
|
+
export declare function openAssemblyAI(opts?: AssemblyAIOptions): SttOpener;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cartesia TTS
|
|
2
|
+
* Cartesia TTS opener (host-only).
|
|
3
|
+
*
|
|
4
|
+
* The user-facing descriptor factory (`cartesia(...)`) lives in
|
|
5
|
+
* `sdk/providers/tts/cartesia.ts`. This module is the host-side
|
|
6
|
+
* counterpart: it takes the descriptor options + an API key and
|
|
7
|
+
* returns a {@link TtsOpener} that the pipeline session drives.
|
|
3
8
|
*
|
|
4
9
|
* Wraps `@cartesia/cartesia-js`'s `TTSWS` / `TTSWSContext` and normalizes it
|
|
5
|
-
* onto the {@link
|
|
6
|
-
* pipeline orchestrator.
|
|
10
|
+
* onto the {@link TtsEvents} contract consumed by the pipeline orchestrator.
|
|
7
11
|
*
|
|
8
12
|
* **Per-turn context lifecycle.** Each `sendText(...)` within the same turn
|
|
9
13
|
* appends to the same Cartesia context. On `flush()` or `cancel()`, a new
|
|
@@ -15,20 +19,8 @@
|
|
|
15
19
|
* conversion.
|
|
16
20
|
*/
|
|
17
21
|
import type { TTSWS } from "@cartesia/cartesia-js/resources/tts";
|
|
18
|
-
import type {
|
|
19
|
-
|
|
20
|
-
/** Cartesia voice ID. Required. */
|
|
21
|
-
voice: string;
|
|
22
|
-
/** Model ID. Defaults to `"sonic-2"`. */
|
|
23
|
-
model?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Cartesia API key. Falls back to `TtsOpenOptions.apiKey`, then
|
|
26
|
-
* `process.env.CARTESIA_API_KEY`.
|
|
27
|
-
*/
|
|
28
|
-
apiKey?: string;
|
|
29
|
-
/** Spoken language hint. Defaults to `"en"`. */
|
|
30
|
-
language?: string;
|
|
31
|
-
}
|
|
22
|
+
import type { CartesiaOptions } from "../../../sdk/providers/tts/cartesia.ts";
|
|
23
|
+
import { type TtsOpener, type TtsSession } from "../../../sdk/providers.ts";
|
|
32
24
|
/** Internal: TtsSession with a test-only handle to the raw SDK socket. */
|
|
33
25
|
export interface CartesiaSession extends TtsSession {
|
|
34
26
|
/** @internal Test-only: exposes the underlying SDK WebSocket wrapper. */
|
|
@@ -36,4 +28,5 @@ export interface CartesiaSession extends TtsSession {
|
|
|
36
28
|
/** @internal Test-only: id of the currently-active context. */
|
|
37
29
|
readonly _currentContextId: () => string;
|
|
38
30
|
}
|
|
39
|
-
|
|
31
|
+
/** Build a {@link TtsOpener} from resolved Cartesia descriptor options. */
|
|
32
|
+
export declare function openCartesia(opts: CartesiaOptions): TtsOpener;
|