@alexkroman1/aai 0.12.2 → 1.0.2
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 +20 -0
- package/CHANGELOG.md +174 -0
- package/dist/constants-VTFoymJ-.js +47 -0
- package/dist/host/_run-code.d.ts +4 -2
- package/dist/host/_runtime-conformance.d.ts +4 -5
- package/dist/host/builtin-tools.d.ts +11 -7
- package/dist/host/runtime-barrel.d.ts +15 -0
- package/dist/{direct-executor-ZUU0Ke4j.js → host/runtime-barrel.js} +463 -345
- package/dist/host/runtime-config.d.ts +42 -0
- package/dist/host/runtime.d.ts +119 -35
- package/dist/host/s2s.d.ts +14 -38
- package/dist/host/server.d.ts +16 -8
- package/dist/host/session-ctx.d.ts +55 -0
- package/dist/host/session.d.ts +21 -70
- package/dist/host/tool-executor.d.ts +20 -0
- package/dist/host/unstorage-kv.d.ts +1 -1
- package/dist/host/ws-handler.d.ts +4 -2
- package/dist/index.d.ts +9 -20
- package/dist/index.js +63 -2
- package/dist/{isolate → sdk}/_internal-types.d.ts +6 -10
- package/dist/{isolate → sdk}/constants.d.ts +6 -4
- package/dist/sdk/define.d.ts +66 -0
- package/dist/{isolate → sdk}/kv.d.ts +1 -49
- package/dist/sdk/manifest-barrel.d.ts +8 -0
- package/dist/sdk/manifest-barrel.js +52 -0
- package/dist/sdk/manifest.d.ts +50 -0
- package/dist/{isolate → sdk}/protocol.d.ts +59 -36
- package/dist/sdk/protocol.js +163 -0
- package/dist/{isolate → sdk}/system-prompt.d.ts +3 -2
- package/dist/sdk/types.d.ts +201 -0
- package/dist/sdk/ws-upgrade.d.ts +5 -0
- package/dist/{system-prompt-CVJSQJiA.js → system-prompt-nik_iavo.js} +11 -10
- package/dist/types-Cfx_4QDK.js +39 -0
- package/dist/ws-upgrade-BeOQ7fXL.js +30 -0
- package/exports-no-dev-deps.test.ts +62 -0
- package/host/_mock-ws.ts +185 -0
- package/host/_run-code.ts +217 -0
- package/host/_runtime-conformance.ts +143 -0
- package/host/_test-utils.ts +276 -0
- package/host/builtin-tools.test.ts +774 -0
- package/host/builtin-tools.ts +255 -0
- package/host/cleanup.test.ts +422 -0
- package/host/fixture-replay.test.ts +463 -0
- package/host/fixtures/README.md +40 -0
- package/host/fixtures/greeting-session-sequence.json +40 -0
- package/host/fixtures/reply-audio-samples.json +42 -0
- package/host/fixtures/reply-lifecycle.json +21 -0
- package/host/fixtures/session-ready.json +48 -0
- package/host/fixtures/session-updated.json +45 -0
- package/host/fixtures/simple-question-sequence.json +73 -0
- package/host/fixtures/tool-call-sequence.json +114 -0
- package/host/fixtures/tool-calls.json +11 -0
- package/host/fixtures/tool-config-session-sequence.json +51 -0
- package/host/fixtures/user-speech-recognition.json +30 -0
- package/host/fixtures/web-search-sequence.json +122 -0
- package/host/integration.test.ts +222 -0
- package/host/runtime-barrel.ts +25 -0
- package/host/runtime-config.test.ts +71 -0
- package/host/runtime-config.ts +99 -0
- package/host/runtime.test.ts +641 -0
- package/host/runtime.ts +308 -0
- package/host/s2s-fixtures.test.ts +237 -0
- package/host/s2s.test.ts +562 -0
- package/host/s2s.ts +310 -0
- package/host/server-shutdown.test.ts +76 -0
- package/host/server.test.ts +116 -0
- package/host/server.ts +223 -0
- package/host/session-ctx.ts +107 -0
- package/host/session-fixture-replay.test.ts +136 -0
- package/host/session-prompt.test.ts +77 -0
- package/host/session.test.ts +590 -0
- package/host/session.ts +370 -0
- package/host/tool-executor.test.ts +124 -0
- package/host/tool-executor.ts +80 -0
- package/host/unstorage-kv.test.ts +99 -0
- package/host/unstorage-kv.ts +69 -0
- package/host/ws-handler.test.ts +739 -0
- package/host/ws-handler.ts +255 -0
- package/index.ts +16 -0
- package/package.json +28 -72
- package/sdk/_internal-types.test.ts +34 -0
- package/sdk/_internal-types.ts +115 -0
- package/sdk/compat-fixtures/README.md +26 -0
- package/sdk/compat-fixtures/v1.json +68 -0
- package/sdk/constants.ts +77 -0
- package/sdk/define.test.ts +57 -0
- package/sdk/define.ts +88 -0
- package/sdk/kv.ts +60 -0
- package/sdk/manifest-barrel.ts +12 -0
- package/sdk/manifest.test.ts +56 -0
- package/sdk/manifest.ts +89 -0
- package/sdk/protocol-compat.test.ts +187 -0
- package/sdk/protocol-snapshot.test.ts +199 -0
- package/sdk/protocol.test.ts +170 -0
- package/sdk/protocol.ts +223 -0
- package/sdk/schema-alignment.test.ts +191 -0
- package/sdk/system-prompt.test.ts +111 -0
- package/sdk/system-prompt.ts +74 -0
- package/sdk/tsconfig.json +12 -0
- package/sdk/types-inference.test.ts +122 -0
- package/sdk/types.test.ts +14 -0
- package/sdk/types.ts +226 -0
- package/sdk/utils.test.ts +52 -0
- package/sdk/utils.ts +20 -0
- package/sdk/ws-upgrade.test.ts +48 -0
- package/sdk/ws-upgrade.ts +13 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +10 -0
- package/tsdown.config.ts +26 -0
- package/vitest.config.ts +17 -0
- package/dist/host/_test-utils.d.ts +0 -73
- package/dist/host/direct-executor.d.ts +0 -128
- package/dist/host/index.d.ts +0 -18
- package/dist/host/index.js +0 -165
- package/dist/host/matchers.d.ts +0 -20
- package/dist/host/matchers.js +0 -41
- package/dist/host/server.js +0 -164
- package/dist/host/testing.d.ts +0 -294
- package/dist/host/testing.js +0 -2
- package/dist/host/vite-plugin.d.ts +0 -15
- package/dist/host/vite-plugin.js +0 -83
- package/dist/isolate/_kv-utils.d.ts +0 -10
- package/dist/isolate/_utils.js +0 -17
- package/dist/isolate/hooks.d.ts +0 -44
- package/dist/isolate/hooks.js +0 -58
- package/dist/isolate/index.d.ts +0 -18
- package/dist/isolate/index.js +0 -6
- package/dist/isolate/kv.js +0 -1
- package/dist/isolate/protocol.js +0 -2
- package/dist/isolate/types.d.ts +0 -418
- package/dist/isolate/types.js +0 -175
- package/dist/protocol-rcOrz7T3.js +0 -183
- package/dist/testing-Bb2B5Uob.js +0 -513
- package/dist/types.test-d.d.ts +0 -7
- /package/dist/{isolate/_utils.d.ts → sdk/utils.d.ts} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Runtime barrel — the full Node.js runtime engine for running agents.
|
|
4
|
+
*
|
|
5
|
+
* Used by aai-server (sandbox) and aai-cli (dev server).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// biome-ignore-all lint/performance/noReExportAll: barrel file by design
|
|
9
|
+
|
|
10
|
+
// Note: ./_runtime-conformance.ts is intentionally NOT re-exported here.
|
|
11
|
+
// It imports `vitest`, which is a devDependency. Re-exporting it would pull
|
|
12
|
+
// `vitest` into the production bundle of this barrel and break runtime
|
|
13
|
+
// imports in environments without dev deps installed (e.g. the deployed
|
|
14
|
+
// platform server). It is consumed directly by sibling test files.
|
|
15
|
+
|
|
16
|
+
export * from "./builtin-tools.ts";
|
|
17
|
+
export * from "./runtime.ts";
|
|
18
|
+
export * from "./runtime-config.ts";
|
|
19
|
+
export * from "./s2s.ts";
|
|
20
|
+
export * from "./server.ts";
|
|
21
|
+
export * from "./session.ts";
|
|
22
|
+
export * from "./session-ctx.ts";
|
|
23
|
+
export * from "./tool-executor.ts";
|
|
24
|
+
export * from "./unstorage-kv.ts";
|
|
25
|
+
export * from "./ws-handler.ts";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
+
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { jsonLogger } from "./runtime-config.ts";
|
|
5
|
+
|
|
6
|
+
/** Parse the JSON line at `index` from `chunks`, failing if missing. */
|
|
7
|
+
function parseEntry(chunks: string[], index: number): Record<string, unknown> {
|
|
8
|
+
const raw = chunks[index];
|
|
9
|
+
if (raw === undefined) throw new Error(`No chunk at index ${index}`);
|
|
10
|
+
return JSON.parse(raw) as Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("jsonLogger", () => {
|
|
14
|
+
let stdoutChunks: string[];
|
|
15
|
+
let stderrChunks: string[];
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
stdoutChunks = [];
|
|
19
|
+
stderrChunks = [];
|
|
20
|
+
vi.spyOn(process.stdout, "write").mockImplementation((chunk: string | Uint8Array) => {
|
|
21
|
+
stdoutChunks.push(String(chunk));
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
vi.spyOn(process.stderr, "write").mockImplementation((chunk: string | Uint8Array) => {
|
|
25
|
+
stderrChunks.push(String(chunk));
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
vi.restoreAllMocks();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("outputs single-line JSON with timestamp, level, and msg", () => {
|
|
35
|
+
jsonLogger.info("hello world");
|
|
36
|
+
expect(stdoutChunks).toHaveLength(1);
|
|
37
|
+
|
|
38
|
+
const entry = parseEntry(stdoutChunks, 0);
|
|
39
|
+
expect(entry.level).toBe("info");
|
|
40
|
+
expect(entry.msg).toBe("hello world");
|
|
41
|
+
expect(entry.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("includes caller-provided context fields", () => {
|
|
45
|
+
jsonLogger.info("with ctx", { sessionId: "abc", count: 3 });
|
|
46
|
+
|
|
47
|
+
const entry = parseEntry(stdoutChunks, 0);
|
|
48
|
+
expect(entry.sessionId).toBe("abc");
|
|
49
|
+
expect(entry.count).toBe(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("writes warn and error to stderr", () => {
|
|
53
|
+
jsonLogger.warn("a warning");
|
|
54
|
+
jsonLogger.error("an error");
|
|
55
|
+
|
|
56
|
+
expect(stderrChunks).toHaveLength(2);
|
|
57
|
+
expect(parseEntry(stderrChunks, 0).level).toBe("warn");
|
|
58
|
+
expect(parseEntry(stderrChunks, 1).level).toBe("error");
|
|
59
|
+
expect(stdoutChunks).toHaveLength(0);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("writes info and debug to stdout", () => {
|
|
63
|
+
jsonLogger.info("info msg");
|
|
64
|
+
jsonLogger.debug("debug msg");
|
|
65
|
+
|
|
66
|
+
expect(stdoutChunks).toHaveLength(2);
|
|
67
|
+
expect(parseEntry(stdoutChunks, 0).level).toBe("info");
|
|
68
|
+
expect(parseEntry(stdoutChunks, 1).level).toBe("debug");
|
|
69
|
+
expect(stderrChunks).toHaveLength(0);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime dependencies injected into the session pipeline.
|
|
5
|
+
*
|
|
6
|
+
* Defines the {@link Logger} interface, a default {@link consoleLogger},
|
|
7
|
+
* and the {@link S2SConfig} for Speech-to-Speech endpoint configuration.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { DEFAULT_STT_SAMPLE_RATE, DEFAULT_TTS_SAMPLE_RATE } from "../sdk/constants.ts";
|
|
11
|
+
|
|
12
|
+
/** Structured context attached to log messages. */
|
|
13
|
+
export type LogContext = Record<string, unknown>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Structured logger interface. Used by tests to suppress output and by
|
|
17
|
+
* consumers to plug in custom logging backends.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const myLogger: Logger = {
|
|
22
|
+
* info: (msg, ctx) => myBackend.log("info", msg, ctx),
|
|
23
|
+
* warn: (msg, ctx) => myBackend.log("warn", msg, ctx),
|
|
24
|
+
* error: (msg, ctx) => myBackend.log("error", msg, ctx),
|
|
25
|
+
* debug: (msg, ctx) => myBackend.log("debug", msg, ctx),
|
|
26
|
+
* };
|
|
27
|
+
* createServer({ agent, logger: myLogger });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type Logger = {
|
|
31
|
+
info(msg: string, ctx?: LogContext): void;
|
|
32
|
+
warn(msg: string, ctx?: LogContext): void;
|
|
33
|
+
error(msg: string, ctx?: LogContext): void;
|
|
34
|
+
debug(msg: string, ctx?: LogContext): void;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function consoleLog(fn: typeof console.log): Logger[keyof Logger] {
|
|
38
|
+
return (msg: string, ctx?: LogContext) => (ctx ? fn(msg, ctx) : fn(msg));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Default console-backed logger. */
|
|
42
|
+
export const consoleLogger: Logger = {
|
|
43
|
+
info: consoleLog(console.log),
|
|
44
|
+
warn: consoleLog(console.warn),
|
|
45
|
+
error: consoleLog(console.error),
|
|
46
|
+
debug: consoleLog(console.debug),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Structured JSON logger for production diagnostics. Each log entry is a
|
|
51
|
+
* single-line JSON object with `timestamp`, `level`, `msg`, and any
|
|
52
|
+
* caller-provided context fields.
|
|
53
|
+
*/
|
|
54
|
+
function jsonLog(level: string) {
|
|
55
|
+
return (msg: string, ctx?: LogContext): void => {
|
|
56
|
+
const entry: Record<string, unknown> = {
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
|
+
level,
|
|
59
|
+
msg,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (ctx) {
|
|
63
|
+
Object.assign(entry, ctx);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Single-line JSON to stdout/stderr based on level.
|
|
67
|
+
const out = level === "error" || level === "warn" ? process.stderr : process.stdout;
|
|
68
|
+
out.write(`${JSON.stringify(entry)}\n`);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const jsonLogger: Logger = {
|
|
73
|
+
info: jsonLog("info"),
|
|
74
|
+
warn: jsonLog("warn"),
|
|
75
|
+
error: jsonLog("error"),
|
|
76
|
+
debug: jsonLog("debug"),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Speech-to-Speech (S2S) endpoint configuration.
|
|
81
|
+
*
|
|
82
|
+
* Controls which AssemblyAI real-time WebSocket endpoint to connect to and
|
|
83
|
+
* the audio sample rates for input (microphone → STT) and output (TTS → speaker).
|
|
84
|
+
*/
|
|
85
|
+
export type S2SConfig = {
|
|
86
|
+
/** The WebSocket URL of the S2S real-time endpoint. */
|
|
87
|
+
wssUrl: string;
|
|
88
|
+
/** Sample rate in Hz for audio sent to STT (microphone capture). */
|
|
89
|
+
inputSampleRate: number;
|
|
90
|
+
/** Sample rate in Hz for TTS audio received from the server. */
|
|
91
|
+
outputSampleRate: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Default S2S endpoint configuration. */
|
|
95
|
+
export const DEFAULT_S2S_CONFIG: S2SConfig = {
|
|
96
|
+
wssUrl: "wss://agents.assemblyai.com/v1/voice",
|
|
97
|
+
inputSampleRate: DEFAULT_STT_SAMPLE_RATE,
|
|
98
|
+
outputSampleRate: DEFAULT_TTS_SAMPLE_RATE,
|
|
99
|
+
};
|