@alexkroman1/aai 1.4.5 → 1.5.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.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +9 -9
  2. package/CHANGELOG.md +13 -0
  3. package/dist/assemblyai-C969QGi4.js +35 -0
  4. package/dist/cartesia-BfQPOQ7Y.js +37 -0
  5. package/dist/host/_pipeline-test-fakes.d.ts +3 -1
  6. package/dist/host/providers/stt/deepgram.d.ts +28 -0
  7. package/dist/host/providers/tts/cartesia.d.ts +1 -1
  8. package/dist/host/providers/tts/rime.d.ts +44 -0
  9. package/dist/host/runtime-barrel.d.ts +4 -2
  10. package/dist/host/runtime-barrel.js +1432 -1208
  11. package/dist/host/runtime.d.ts +2 -2
  12. package/dist/host/s2s.d.ts +16 -16
  13. package/dist/host/session-core.d.ts +37 -0
  14. package/dist/host/transports/pipeline-transport.d.ts +48 -0
  15. package/dist/host/transports/s2s-transport.d.ts +19 -0
  16. package/dist/host/transports/types.d.ts +45 -0
  17. package/dist/host/ws-handler.d.ts +14 -10
  18. package/dist/sdk/protocol.d.ts +6 -5
  19. package/dist/sdk/providers/llm-barrel.js +1 -1
  20. package/dist/sdk/providers/stt/deepgram.d.ts +35 -0
  21. package/dist/sdk/providers/stt-barrel.d.ts +1 -0
  22. package/dist/sdk/providers/stt-barrel.js +2 -2
  23. package/dist/sdk/providers/tts/cartesia.d.ts +12 -4
  24. package/dist/sdk/providers/tts/rime.d.ts +42 -0
  25. package/dist/sdk/providers/tts-barrel.d.ts +1 -0
  26. package/dist/sdk/providers/tts-barrel.js +2 -2
  27. package/host/_pipeline-test-fakes.ts +6 -3
  28. package/host/_test-utils.ts +209 -128
  29. package/host/cleanup.test.ts +25 -298
  30. package/host/integration/pipeline-reference.integration.test.ts +30 -35
  31. package/host/providers/resolve.ts +10 -2
  32. package/host/providers/stt/deepgram.test.ts +229 -0
  33. package/host/providers/stt/deepgram.ts +172 -0
  34. package/host/providers/tts/cartesia.ts +7 -3
  35. package/host/providers/tts/rime.test.ts +251 -0
  36. package/host/providers/tts/rime.ts +322 -0
  37. package/host/runtime-barrel.ts +4 -2
  38. package/host/runtime.test.ts +13 -46
  39. package/host/runtime.ts +131 -23
  40. package/host/s2s.test.ts +122 -131
  41. package/host/s2s.ts +44 -52
  42. package/host/session-core.test.ts +257 -0
  43. package/host/session-core.ts +262 -0
  44. package/host/transports/pipeline-transport.test.ts +651 -0
  45. package/host/transports/pipeline-transport.ts +532 -0
  46. package/host/{fixture-replay.test.ts → transports/s2s-transport-fixtures.test.ts} +76 -106
  47. package/host/transports/s2s-transport.test.ts +56 -0
  48. package/host/transports/s2s-transport.ts +116 -0
  49. package/host/transports/types.test.ts +22 -0
  50. package/host/transports/types.ts +51 -0
  51. package/host/ws-handler.test.ts +324 -242
  52. package/host/ws-handler.ts +56 -59
  53. package/package.json +2 -1
  54. package/sdk/__snapshots__/exports.test.ts.snap +3 -3
  55. package/sdk/protocol-compat.test.ts +8 -0
  56. package/sdk/protocol.ts +6 -5
  57. package/sdk/providers/stt/deepgram.ts +43 -0
  58. package/sdk/providers/stt-barrel.ts +2 -0
  59. package/sdk/providers/tts/cartesia.ts +15 -5
  60. package/sdk/providers/tts/rime.ts +52 -0
  61. package/sdk/providers/tts-barrel.ts +2 -0
  62. package/dist/assemblyai-Cxg9eobY.js +0 -18
  63. package/dist/cartesia-DwDk2tEu.js +0 -10
  64. package/dist/host/pipeline-session-ctx.d.ts +0 -24
  65. package/dist/host/pipeline-session.d.ts +0 -52
  66. package/dist/host/session-ctx.d.ts +0 -73
  67. package/dist/host/session.d.ts +0 -62
  68. package/host/pipeline-session-ctx.test.ts +0 -31
  69. package/host/pipeline-session-ctx.ts +0 -36
  70. package/host/pipeline-session.test.ts +0 -672
  71. package/host/pipeline-session.ts +0 -533
  72. package/host/s2s-fixtures.test.ts +0 -237
  73. package/host/session-ctx.test.ts +0 -387
  74. package/host/session-ctx.ts +0 -134
  75. package/host/session-fixture-replay.test.ts +0 -128
  76. package/host/session.test.ts +0 -634
  77. package/host/session.ts +0 -412
  78. /package/dist/{anthropic-BrUCPKUc.js → anthropic-CcLZygAr.js} +0 -0
@@ -1,62 +0,0 @@
1
- /** S2S session — relays audio between client and AssemblyAI S2S API. */
2
- import type { AgentConfig, ExecuteTool, ToolSchema } from "../sdk/_internal-types.ts";
3
- import type { ClientSink } from "../sdk/protocol.ts";
4
- import type { Logger, S2SConfig } from "./runtime-config.ts";
5
- import { type CreateS2sWebSocket, connectS2s } from "./s2s.ts";
6
- /**
7
- * A voice session managing the Speech-to-Speech connection for one client.
8
- *
9
- * Created by {@link createS2sSession}. Each session owns a single S2S WebSocket
10
- * connection and relays audio between the browser client and AssemblyAI.
11
- *
12
- * @internal Exported for use by `ws-handler.ts`, `server.ts`, and `runtime.ts`.
13
- */
14
- export type Session = {
15
- start(): Promise<void>;
16
- stop(): Promise<void>;
17
- onAudio(data: Uint8Array): void;
18
- onAudioReady(): void;
19
- onCancel(): void;
20
- onReset(): void;
21
- onHistory(incoming: readonly {
22
- role: "user" | "assistant";
23
- content: string;
24
- }[]): void;
25
- waitForTurn(): Promise<void>;
26
- };
27
- /** Configuration options for creating a new S2S voice session. */
28
- export type S2sSessionOptions = {
29
- /** Unique session identifier (used for KV scoping and logging). */
30
- id: string;
31
- /** Agent slug — identifies which deployed agent this session belongs to. */
32
- agent: string;
33
- /** Sink for pushing events and audio to the connected browser client. */
34
- client: ClientSink;
35
- /** Serializable agent config (name, system prompt, greeting, maxSteps, etc.). */
36
- agentConfig: AgentConfig;
37
- /** JSON Schema definitions for the agent's custom tools. */
38
- toolSchemas: readonly ToolSchema[];
39
- /** Optional natural-language guidance appended to the system prompt for tool usage. */
40
- toolGuidance?: readonly string[];
41
- /** AssemblyAI API key — stays host-side, never forwarded to the guest sandbox. */
42
- apiKey: string;
43
- /** S2S connection config (sample rates, model selection). */
44
- s2sConfig: S2SConfig;
45
- /** Function to invoke tools by name (wired to direct-executor or sandbox RPC). */
46
- executeTool: ExecuteTool;
47
- /** Override WebSocket constructor for testing. */
48
- createWebSocket?: CreateS2sWebSocket;
49
- /** Agent environment variables (secrets). Forwarded to tool context. */
50
- env?: Record<string, string | undefined>;
51
- /** Skip the initial greeting audio on connect (used for session resume). */
52
- skipGreeting?: boolean;
53
- /** Logger instance. Defaults to `consoleLogger`. */
54
- logger?: Logger;
55
- /** Max conversation messages to retain. Defaults to DEFAULT_MAX_HISTORY (200). */
56
- maxHistory?: number;
57
- };
58
- /** @internal Not part of the public API. Exposed for testing only. */
59
- export declare const _internals: {
60
- connectS2s: typeof connectS2s;
61
- };
62
- export declare function createS2sSession(opts: S2sSessionOptions): Session;
@@ -1,31 +0,0 @@
1
- // Copyright 2025 the AAI authors. MIT license.
2
- import { describe, expect, test } from "vitest";
3
- import { buildPipelineCtx } from "./pipeline-session-ctx.ts";
4
- import { consoleLogger } from "./runtime-config.ts";
5
-
6
- const baseDeps = {
7
- id: "sess-1",
8
- agent: "demo",
9
- client: { event: () => undefined, playAudioChunk: () => undefined } as never,
10
- agentConfig: { name: "demo", systemPrompt: "", maxSteps: 3 } as never,
11
- executeTool: (async () => "") as never,
12
- log: consoleLogger,
13
- };
14
-
15
- describe("buildPipelineCtx", () => {
16
- test("starts with null provider sessions", () => {
17
- const ctx = buildPipelineCtx(baseDeps);
18
- expect(ctx.stt).toBeNull();
19
- expect(ctx.tts).toBeNull();
20
- });
21
-
22
- test("pushMessages + beginReply + cancelReply match S2S semantics", () => {
23
- const ctx = buildPipelineCtx(baseDeps);
24
- ctx.pushMessages({ role: "user", content: "hi" });
25
- ctx.beginReply("r1");
26
- expect(ctx.reply.currentReplyId).toBe("r1");
27
- ctx.cancelReply();
28
- expect(ctx.reply.currentReplyId).toBeNull();
29
- expect(ctx.conversationMessages).toEqual([{ role: "user", content: "hi" }]);
30
- });
31
- });
@@ -1,36 +0,0 @@
1
- // Copyright 2025 the AAI authors. MIT license.
2
- /** Pipeline session context — base ctx + STT/TTS session slots. */
3
-
4
- import type { AgentConfig, ExecuteTool } from "../sdk/_internal-types.ts";
5
- import type { ClientSink } from "../sdk/protocol.ts";
6
- import type { SttSession, TtsSession } from "../sdk/providers.ts";
7
- import type { Logger } from "./runtime-config.ts";
8
- import { _buildBaseCtx, type BaseSessionCtx } from "./session-ctx.ts";
9
-
10
- /**
11
- * Pipeline session context — {@link BaseSessionCtx} plus STT/TTS provider
12
- * session handles. Replaces the S2S `s2s` field with decoupled `stt` + `tts`
13
- * slots so the pipeline orchestrator can drive independent providers.
14
- */
15
- export type PipelineSessionCtx = BaseSessionCtx & {
16
- stt: SttSession | null;
17
- tts: TtsSession | null;
18
- };
19
-
20
- export function buildPipelineCtx(opts: {
21
- id: string;
22
- agent: string;
23
- client: ClientSink;
24
- agentConfig: AgentConfig;
25
- executeTool: ExecuteTool;
26
- log: Logger;
27
- maxHistory?: number | undefined;
28
- }): PipelineSessionCtx {
29
- // Mutate the base ctx in place rather than spreading into a new object —
30
- // the helper methods close over the base ctx reference, so spreading would
31
- // leave them writing to an orphan object.
32
- const base = _buildBaseCtx(opts) as PipelineSessionCtx;
33
- base.stt = null;
34
- base.tts = null;
35
- return base;
36
- }