@alexkroman1/aai 0.10.3 → 0.11.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/dist/_internal-types.d.ts +8 -1
- package/dist/_run-code.d.ts +16 -12
- package/dist/_runtime-conformance.d.ts +55 -0
- package/dist/_test-utils.d.ts +73 -0
- package/dist/_utils.d.ts +0 -19
- package/dist/_utils.js +28 -2
- package/dist/builtin-tools.d.ts +1 -5
- package/dist/constants-CwotjpJR.js +45 -0
- package/dist/constants.d.ts +42 -0
- package/dist/direct-executor-DAGCZOAN.js +1530 -0
- package/dist/direct-executor.d.ts +90 -31
- package/dist/hooks.d.ts +44 -0
- package/dist/hooks.js +58 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/internal.d.ts +19 -0
- package/dist/internal.js +164 -0
- package/dist/kv.d.ts +1 -1
- package/dist/kv.js +32 -1
- package/dist/matchers.js +1 -1
- package/dist/protocol.d.ts +3 -29
- package/dist/protocol.js +140 -2
- package/dist/server.d.ts +27 -40
- package/dist/server.js +117 -145
- package/dist/session.d.ts +65 -44
- package/dist/{testing-BbitshLb.js → testing-Dmx-dudh.js} +39 -43
- package/dist/testing.d.ts +9 -14
- package/dist/testing.js +2 -2
- package/dist/types.d.ts +24 -226
- package/dist/types.js +176 -2
- package/dist/types.test-d.d.ts +7 -0
- package/dist/vite-plugin.d.ts +15 -0
- package/dist/vite-plugin.js +82 -0
- package/dist/ws-handler.d.ts +1 -2
- package/package.json +34 -95
- package/dist/_embeddings.d.ts +0 -31
- package/dist/_internal-types-IfPcaJd5.js +0 -61
- package/dist/_internal-types.js +0 -2
- package/dist/_session-ctx.d.ts +0 -73
- package/dist/_session-otel.d.ts +0 -43
- package/dist/_session-persist.d.ts +0 -30
- package/dist/_ssrf-DCp_27V4.js +0 -123
- package/dist/_ssrf.d.ts +0 -30
- package/dist/_ssrf.js +0 -2
- package/dist/_utils-DgzpOMSV.js +0 -61
- package/dist/direct-executor-B-5mq3cu.js +0 -570
- package/dist/kv-iXtikQmR.js +0 -32
- package/dist/middleware-core-BwyBIPed.js +0 -107
- package/dist/middleware-core.d.ts +0 -47
- package/dist/middleware-core.js +0 -2
- package/dist/middleware.d.ts +0 -37
- package/dist/protocol-B-H2Q4ox.js +0 -162
- package/dist/runtime-CxcwaK68.js +0 -58
- package/dist/runtime.js +0 -2
- package/dist/s2s-M7JqtgFw.js +0 -272
- package/dist/s2s.js +0 -2
- package/dist/session-BYlwcrya.js +0 -683
- package/dist/session.js +0 -2
- package/dist/telemetry-CJlaDFNc.js +0 -95
- package/dist/telemetry.d.ts +0 -49
- package/dist/telemetry.js +0 -2
- package/dist/types-D8ZBxTL_.js +0 -192
- package/dist/unstorage-kv-CDgP-frt.js +0 -64
- package/dist/unstorage-kv.js +0 -2
- package/dist/unstorage-vector-Cj5llNhg.js +0 -172
- package/dist/unstorage-vector.d.ts +0 -47
- package/dist/unstorage-vector.js +0 -2
- package/dist/vector.d.ts +0 -86
- package/dist/vector.js +0 -49
- package/dist/worker-entry-2jaiqIj0.js +0 -70
- package/dist/worker-entry.d.ts +0 -47
- package/dist/worker-entry.js +0 -2
- package/dist/ws-handler-C0Q6eSay.js +0 -207
- package/dist/ws-handler.js +0 -2
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { JSONSchema7 } from "json-schema";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import type { Message } from "./types.ts";
|
|
8
9
|
import { type ToolDef } from "./types.ts";
|
|
10
|
+
/**
|
|
11
|
+
* Function signature for executing a tool by name.
|
|
12
|
+
*
|
|
13
|
+
* Used by session.ts to invoke tools, by direct-executor.ts and
|
|
14
|
+
* _harness-runtime.ts to implement the execution.
|
|
15
|
+
*/
|
|
16
|
+
export type ExecuteTool = (name: string, args: Readonly<Record<string, unknown>>, sessionId?: string, messages?: readonly Message[]) => Promise<string>;
|
|
9
17
|
/**
|
|
10
18
|
* Zod schema for serializable agent configuration sent over the wire.
|
|
11
19
|
*
|
|
@@ -31,7 +39,6 @@ export declare const AgentConfigSchema: z.ZodObject<{
|
|
|
31
39
|
visit_webpage: "visit_webpage";
|
|
32
40
|
fetch_json: "fetch_json";
|
|
33
41
|
run_code: "run_code";
|
|
34
|
-
vector_search: "vector_search";
|
|
35
42
|
memory: "memory";
|
|
36
43
|
}>>>>;
|
|
37
44
|
idleTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
package/dist/_run-code.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* run_code built-in tool — executes user JavaScript in a fresh
|
|
3
|
-
*
|
|
2
|
+
* run_code built-in tool — executes user JavaScript in a fresh `node:vm`
|
|
3
|
+
* context with no network, filesystem, or process access.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import type { ToolDef } from "./types.ts";
|
|
@@ -8,22 +8,26 @@ declare const runCodeParams: z.ZodObject<{
|
|
|
8
8
|
code: z.ZodString;
|
|
9
9
|
}, z.core.$strip>;
|
|
10
10
|
/**
|
|
11
|
-
* Execute JavaScript code inside a fresh
|
|
11
|
+
* Execute JavaScript code inside a fresh `node:vm` context.
|
|
12
12
|
*
|
|
13
|
-
* Each invocation
|
|
14
|
-
* - No filesystem
|
|
15
|
-
* - No network access
|
|
13
|
+
* Each invocation creates a disposable VM context with:
|
|
14
|
+
* - No filesystem access (`node:fs` and other built-ins unavailable)
|
|
15
|
+
* - No network access (`fetch`, `http` unavailable)
|
|
16
16
|
* - No child process spawning
|
|
17
|
-
* - No environment variable access
|
|
18
|
-
* -
|
|
19
|
-
* - 5 second execution timeout
|
|
17
|
+
* - No environment variable access (`process` unavailable)
|
|
18
|
+
* - Execution timeout (default 5 s)
|
|
20
19
|
*
|
|
21
|
-
* The
|
|
22
|
-
*
|
|
20
|
+
* The context is discarded after execution, so no state leaks between
|
|
21
|
+
* invocations or across sessions.
|
|
23
22
|
*/
|
|
24
23
|
export declare function createRunCode(): ToolDef<typeof runCodeParams>;
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Execute user code in a fresh `node:vm` context.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* The VM context only exposes standard ECMAScript globals and a console
|
|
29
|
+
* object that captures output. Node.js APIs (`process`, `require`,
|
|
30
|
+
* `import()`) are not available inside the sandbox.
|
|
27
31
|
*/
|
|
28
32
|
export declare function executeInIsolate(code: string): Promise<string | {
|
|
29
33
|
error: string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared runtime conformance tests.
|
|
3
|
+
*
|
|
4
|
+
* Both the self-hosted direct executor and the platform sandbox must satisfy
|
|
5
|
+
* the same behavioral contract. This module defines that contract as a
|
|
6
|
+
* reusable test suite that can be wired to either runtime.
|
|
7
|
+
*
|
|
8
|
+
* Inspired by Nitro's `testNitro()` pattern: one test fixture, many runtimes.
|
|
9
|
+
*
|
|
10
|
+
* @example Direct executor (unit test)
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { testRuntime } from "./_runtime-conformance.ts";
|
|
13
|
+
*
|
|
14
|
+
* testRuntime("direct", () => {
|
|
15
|
+
* const exec = createRuntime({ agent: CONFORMANCE_AGENT, env: { MY_VAR: "test-value" } });
|
|
16
|
+
* return { executeTool: exec.executeTool, hooks: exec.hooks };
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Sandbox (integration test in aai-server)
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { testRuntime } from "@alexkroman1/aai/internal";
|
|
23
|
+
*
|
|
24
|
+
* testRuntime("sandbox", async () => {
|
|
25
|
+
* // ... start isolate with a bundled agent
|
|
26
|
+
* return { executeTool: buildExecuteTool(...), hooks: buildHookInvoker(...) };
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { ExecuteTool } from "./_internal-types.ts";
|
|
31
|
+
import type { AgentHooks } from "./hooks.ts";
|
|
32
|
+
import { type AgentDef } from "./types.ts";
|
|
33
|
+
/**
|
|
34
|
+
* Minimal runtime surface needed for conformance tests.
|
|
35
|
+
*
|
|
36
|
+
* Both `Runtime` and `buildExecuteTool`/`buildHookInvoker` from the
|
|
37
|
+
* sandbox produce objects that satisfy this interface.
|
|
38
|
+
*/
|
|
39
|
+
export type RuntimeTestContext = {
|
|
40
|
+
executeTool: ExecuteTool;
|
|
41
|
+
hooks: AgentHooks;
|
|
42
|
+
};
|
|
43
|
+
/** Agent definition used by the conformance suite (direct executor path). */
|
|
44
|
+
export declare const CONFORMANCE_AGENT: AgentDef;
|
|
45
|
+
/**
|
|
46
|
+
* Run the runtime conformance test suite against a given runtime context.
|
|
47
|
+
*
|
|
48
|
+
* The `getContext` callback is invoked once per test to retrieve the
|
|
49
|
+
* current {@link RuntimeTestContext}. This allows the caller to set up
|
|
50
|
+
* the runtime in a `beforeAll` and return it lazily.
|
|
51
|
+
*
|
|
52
|
+
* All tests assume the runtime was created with {@link CONFORMANCE_AGENT}
|
|
53
|
+
* (or its bundle equivalent) and `env: { MY_VAR: "test-value" }`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function testRuntime(label: string, getContext: () => RuntimeTestContext): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { AgentConfig } from "./_internal-types.ts";
|
|
2
|
+
import type { ClientSink } from "./protocol.ts";
|
|
3
|
+
import type { S2sEvents, S2sHandle } from "./s2s.ts";
|
|
4
|
+
import type { Session } from "./session.ts";
|
|
5
|
+
import { type S2sSessionOptions } from "./session.ts";
|
|
6
|
+
import type { AgentDef, ToolContext, ToolDef } from "./types.ts";
|
|
7
|
+
/** Yield to the microtask queue so pending promises settle. */
|
|
8
|
+
export declare function flush(): Promise<void>;
|
|
9
|
+
export declare function createMockToolContext(overrides?: Partial<ToolContext>): ToolContext;
|
|
10
|
+
export declare function makeTool(overrides?: Partial<ToolDef>): ToolDef;
|
|
11
|
+
export declare function makeAgent(overrides?: Partial<AgentDef>): AgentDef;
|
|
12
|
+
export declare function makeConfig(overrides?: Partial<AgentConfig>): AgentConfig;
|
|
13
|
+
/** Create a stub Session with all methods as vi.fn() spies. */
|
|
14
|
+
export declare function makeStubSession(overrides?: Partial<Session>): Session;
|
|
15
|
+
export type MockS2sHandle = S2sHandle & {
|
|
16
|
+
_fire: <K extends keyof S2sEvents>(type: K, ...args: Parameters<S2sEvents[K]>) => void;
|
|
17
|
+
};
|
|
18
|
+
/** Create a mock S2sHandle backed by nanoevents. */
|
|
19
|
+
export declare function makeMockHandle(): MockS2sHandle;
|
|
20
|
+
/** Minimal client that tracks events and audio. All methods are vi.fn() spies. */
|
|
21
|
+
export declare function makeClient(): ClientSink & {
|
|
22
|
+
events: unknown[];
|
|
23
|
+
audioChunks: Uint8Array[];
|
|
24
|
+
audioDoneCount: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const silentLogger: {
|
|
27
|
+
info: (...args: unknown[]) => void;
|
|
28
|
+
warn: (...args: unknown[]) => void;
|
|
29
|
+
error: (...args: unknown[]) => void;
|
|
30
|
+
debug: (...args: unknown[]) => void;
|
|
31
|
+
};
|
|
32
|
+
export declare function makeSessionOpts(overrides?: Partial<S2sSessionOptions>): S2sSessionOptions;
|
|
33
|
+
/** Load a JSON fixture from __fixtures__/. */
|
|
34
|
+
export declare function loadFixture<T = Record<string, unknown>[]>(name: string): T;
|
|
35
|
+
/**
|
|
36
|
+
* Replay recorded S2S API messages through a MockS2sHandle.
|
|
37
|
+
*
|
|
38
|
+
* Converts raw wire-format JSON (from __fixtures__/) into typed `_fire()` calls.
|
|
39
|
+
* This is the inverse of `dispatchS2sMessage` in s2s.ts — it translates
|
|
40
|
+
* snake_case API fields to camelCase event payloads.
|
|
41
|
+
*
|
|
42
|
+
* Messages that don't map to an event (audio, `reply.content_part.*`) are skipped.
|
|
43
|
+
*/
|
|
44
|
+
export declare function replayFixtureMessages(handle: MockS2sHandle, messages: Record<string, unknown>[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Create a real Runtime-backed session for fixture replay testing.
|
|
47
|
+
*
|
|
48
|
+
* Uses a real `Runtime` (real tool execution, real hooks) but replaces the
|
|
49
|
+
* S2S WebSocket with a mock handle so fixture messages can be replayed
|
|
50
|
+
* through the full orchestration layer.
|
|
51
|
+
*
|
|
52
|
+
* Exercises: defineAgent → toAgentConfig → tool schemas → Zod arg validation
|
|
53
|
+
* → executeToolCall → session orchestration (reply guards, tool buffering,
|
|
54
|
+
* turnPromise chaining).
|
|
55
|
+
*
|
|
56
|
+
* Call `cleanup()` when done to restore the connectS2s spy.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createFixtureSession(agent: AgentDef<any>, opts?: {
|
|
59
|
+
env?: Record<string, string>;
|
|
60
|
+
}): {
|
|
61
|
+
session: Session;
|
|
62
|
+
client: ClientSink & {
|
|
63
|
+
events: unknown[];
|
|
64
|
+
audioChunks: Uint8Array[];
|
|
65
|
+
audioDoneCount: number;
|
|
66
|
+
};
|
|
67
|
+
mockHandle: MockS2sHandle;
|
|
68
|
+
executor: import("./direct-executor.ts").Runtime;
|
|
69
|
+
/** Replay a fixture file through the session's S2S handle. */
|
|
70
|
+
replay(fixtureName: string): void;
|
|
71
|
+
/** Restore the connectS2s spy. Call in afterEach. */
|
|
72
|
+
cleanup(): void;
|
|
73
|
+
};
|
package/dist/_utils.d.ts
CHANGED
|
@@ -3,26 +3,7 @@
|
|
|
3
3
|
export declare function errorMessage(err: unknown): string;
|
|
4
4
|
/** Extract a detailed error string (message + stack) for diagnostic logging. */
|
|
5
5
|
export declare function errorDetail(err: unknown): string;
|
|
6
|
-
/** Filter out undefined values from an env record. */
|
|
7
|
-
export declare function filterEnv(env: Record<string, string | undefined>): Record<string, string>;
|
|
8
6
|
/** Check whether a filesystem operation is a read-only operation. */
|
|
9
7
|
export declare function isReadOnlyFsOp(op: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Safely extract the port from `server.address()`, guarding against the
|
|
12
|
-
* string (pipe/socket) and null return types.
|
|
13
|
-
*/
|
|
14
|
-
export declare function getServerPort(addr: unknown): number;
|
|
15
|
-
/**
|
|
16
|
-
* Lazily initialized per-session state manager.
|
|
17
|
-
*
|
|
18
|
-
* On first access for a given session, calls `initState()` (if provided) to
|
|
19
|
-
* create the initial state. Returns `{}` if no initializer and no prior state.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createSessionStateMap(initState?: () => Record<string, unknown>): {
|
|
22
|
-
get(sessionId: string): Record<string, unknown>;
|
|
23
|
-
/** Explicitly set the state for a session (used by persistence restore). */
|
|
24
|
-
set(sessionId: string, state: Record<string, unknown>): void;
|
|
25
|
-
delete(sessionId: string): boolean;
|
|
26
|
-
};
|
|
27
8
|
/** Return a JSON error string for the LLM: `'{"error":"<message>"}'`. */
|
|
28
9
|
export declare function toolError(message: string): string;
|
package/dist/_utils.js
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region _utils.ts
|
|
2
|
+
/** Shared utility functions. */
|
|
3
|
+
/** Extract an error message from an unknown thrown value. */
|
|
4
|
+
function errorMessage(err) {
|
|
5
|
+
return err instanceof Error ? err.message : String(err);
|
|
6
|
+
}
|
|
7
|
+
/** Extract a detailed error string (message + stack) for diagnostic logging. */
|
|
8
|
+
function errorDetail(err) {
|
|
9
|
+
if (err instanceof Error) return err.stack ?? err.message;
|
|
10
|
+
return String(err);
|
|
11
|
+
}
|
|
12
|
+
/** Set of filesystem operations that are safe for read-only access. */
|
|
13
|
+
const READ_ONLY_FS_OPS = new Set([
|
|
14
|
+
"read",
|
|
15
|
+
"stat",
|
|
16
|
+
"readdir",
|
|
17
|
+
"exists"
|
|
18
|
+
]);
|
|
19
|
+
/** Check whether a filesystem operation is a read-only operation. */
|
|
20
|
+
function isReadOnlyFsOp(op) {
|
|
21
|
+
return READ_ONLY_FS_OPS.has(op);
|
|
22
|
+
}
|
|
23
|
+
/** Return a JSON error string for the LLM: `'{"error":"<message>"}'`. */
|
|
24
|
+
function toolError(message) {
|
|
25
|
+
return JSON.stringify({ error: message });
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { errorDetail, errorMessage, isReadOnlyFsOp, toolError };
|
package/dist/builtin-tools.d.ts
CHANGED
|
@@ -10,19 +10,15 @@ import { type ToolSchema } from "./_internal-types.ts";
|
|
|
10
10
|
import type { ToolDef } from "./types.ts";
|
|
11
11
|
export { executeInIsolate } from "./_run-code.ts";
|
|
12
12
|
export { memoryTools } from "./memory-tools.ts";
|
|
13
|
-
/** Callback for proxying vector search through the host RPC. */
|
|
14
|
-
export type VectorSearchFn = (query: string, topK: number) => Promise<string>;
|
|
15
13
|
/** Options for creating built-in tool definitions. */
|
|
16
14
|
export type BuiltinToolOptions = {
|
|
17
|
-
/** RPC callback for vector_search (proxied through host). */
|
|
18
|
-
vectorSearch?: VectorSearchFn;
|
|
19
15
|
/** Override fetch implementation (defaults to globalThis.fetch). For testing. */
|
|
20
16
|
fetch?: typeof globalThis.fetch;
|
|
21
17
|
};
|
|
22
18
|
type ToolDefRecord = Record<string, ToolDef<z.ZodObject<z.ZodRawShape>>>;
|
|
23
19
|
/**
|
|
24
20
|
* Create built-in tool definitions for the given tool names.
|
|
25
|
-
* For runtime use
|
|
21
|
+
* For runtime use.
|
|
26
22
|
*/
|
|
27
23
|
export declare function getBuiltinToolDefs(names: readonly string[], opts?: BuiltinToolOptions): ToolDefRecord;
|
|
28
24
|
/** Returns JSON tool schemas for the specified builtin tools. */
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Centralised numeric constants — timeouts, size limits, sample rates.
|
|
4
|
+
*
|
|
5
|
+
* Every magic number that controls a timeout, buffer size, or threshold
|
|
6
|
+
* lives here so the values are discoverable in one place.
|
|
7
|
+
*/
|
|
8
|
+
/** Default sample rate for speech-to-text audio in Hz (AssemblyAI). */
|
|
9
|
+
const DEFAULT_STT_SAMPLE_RATE = 16e3;
|
|
10
|
+
/** Default sample rate for text-to-speech audio in Hz. */
|
|
11
|
+
const DEFAULT_TTS_SAMPLE_RATE = 24e3;
|
|
12
|
+
/** Default timeout for agent lifecycle hooks (onConnect, onTurn, etc). */
|
|
13
|
+
const HOOK_TIMEOUT_MS = 5e3;
|
|
14
|
+
/** Default timeout for tool execution in the worker. */
|
|
15
|
+
const TOOL_EXECUTION_TIMEOUT_MS = 3e4;
|
|
16
|
+
/** Timeout for session.start() (S2S connection setup). */
|
|
17
|
+
const DEFAULT_SESSION_START_TIMEOUT_MS = 1e4;
|
|
18
|
+
/** S2S session idle timeout before auto-close. */
|
|
19
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 3e5;
|
|
20
|
+
/** Per-fetch timeout for network tools (web_search, visit_webpage, fetch_json). */
|
|
21
|
+
const FETCH_TIMEOUT_MS = 15e3;
|
|
22
|
+
/** Timeout for sandboxed run_code execution. */
|
|
23
|
+
const RUN_CODE_TIMEOUT_MS = 5e3;
|
|
24
|
+
/** Maximum time to wait for sessions to stop during graceful shutdown. */
|
|
25
|
+
const DEFAULT_SHUTDOWN_TIMEOUT_MS = 3e4;
|
|
26
|
+
/** Maximum length for tool result strings sent to clients. */
|
|
27
|
+
const MAX_TOOL_RESULT_CHARS = 4e3;
|
|
28
|
+
/** Maximum chars for webpage text after HTML-to-text conversion. */
|
|
29
|
+
const MAX_PAGE_CHARS = 1e4;
|
|
30
|
+
/** Maximum bytes to fetch from an HTML page before conversion. */
|
|
31
|
+
const MAX_HTML_BYTES = 2e5;
|
|
32
|
+
/** Maximum value size for KV store entries (bytes). */
|
|
33
|
+
const MAX_VALUE_SIZE = 65536;
|
|
34
|
+
/** Maximum glob pattern length to prevent ReDoS. */
|
|
35
|
+
const MAX_GLOB_PATTERN_LENGTH = 1024;
|
|
36
|
+
/** Maximum conversation messages to retain (sliding window). */
|
|
37
|
+
const DEFAULT_MAX_HISTORY = 200;
|
|
38
|
+
/**
|
|
39
|
+
* Content-Security-Policy applied to agent UI pages (both self-hosted and
|
|
40
|
+
* platform). Single source of truth — used by `secureHeaders` middleware
|
|
41
|
+
* and per-response CSP headers.
|
|
42
|
+
*/
|
|
43
|
+
const AGENT_CSP = "default-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src 'self' wss: ws:; img-src 'self' data:; font-src 'self' https://fonts.gstatic.com; object-src 'none'; base-uri 'self'";
|
|
44
|
+
//#endregion
|
|
45
|
+
export { DEFAULT_SHUTDOWN_TIMEOUT_MS as a, FETCH_TIMEOUT_MS as c, MAX_HTML_BYTES as d, MAX_PAGE_CHARS as f, TOOL_EXECUTION_TIMEOUT_MS as g, RUN_CODE_TIMEOUT_MS as h, DEFAULT_SESSION_START_TIMEOUT_MS as i, HOOK_TIMEOUT_MS as l, MAX_VALUE_SIZE as m, DEFAULT_IDLE_TIMEOUT_MS as n, DEFAULT_STT_SAMPLE_RATE as o, MAX_TOOL_RESULT_CHARS as p, DEFAULT_MAX_HISTORY as r, DEFAULT_TTS_SAMPLE_RATE as s, AGENT_CSP as t, MAX_GLOB_PATTERN_LENGTH as u };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralised numeric constants — timeouts, size limits, sample rates.
|
|
3
|
+
*
|
|
4
|
+
* Every magic number that controls a timeout, buffer size, or threshold
|
|
5
|
+
* lives here so the values are discoverable in one place.
|
|
6
|
+
*/
|
|
7
|
+
/** Default sample rate for speech-to-text audio in Hz (AssemblyAI). */
|
|
8
|
+
export declare const DEFAULT_STT_SAMPLE_RATE = 16000;
|
|
9
|
+
/** Default sample rate for text-to-speech audio in Hz. */
|
|
10
|
+
export declare const DEFAULT_TTS_SAMPLE_RATE = 24000;
|
|
11
|
+
/** Default timeout for agent lifecycle hooks (onConnect, onTurn, etc). */
|
|
12
|
+
export declare const HOOK_TIMEOUT_MS = 5000;
|
|
13
|
+
/** Default timeout for tool execution in the worker. */
|
|
14
|
+
export declare const TOOL_EXECUTION_TIMEOUT_MS = 30000;
|
|
15
|
+
/** Timeout for session.start() (S2S connection setup). */
|
|
16
|
+
export declare const DEFAULT_SESSION_START_TIMEOUT_MS = 10000;
|
|
17
|
+
/** S2S session idle timeout before auto-close. */
|
|
18
|
+
export declare const DEFAULT_IDLE_TIMEOUT_MS = 300000;
|
|
19
|
+
/** Per-fetch timeout for network tools (web_search, visit_webpage, fetch_json). */
|
|
20
|
+
export declare const FETCH_TIMEOUT_MS = 15000;
|
|
21
|
+
/** Timeout for sandboxed run_code execution. */
|
|
22
|
+
export declare const RUN_CODE_TIMEOUT_MS = 5000;
|
|
23
|
+
/** Maximum time to wait for sessions to stop during graceful shutdown. */
|
|
24
|
+
export declare const DEFAULT_SHUTDOWN_TIMEOUT_MS = 30000;
|
|
25
|
+
/** Maximum length for tool result strings sent to clients. */
|
|
26
|
+
export declare const MAX_TOOL_RESULT_CHARS = 4000;
|
|
27
|
+
/** Maximum chars for webpage text after HTML-to-text conversion. */
|
|
28
|
+
export declare const MAX_PAGE_CHARS = 10000;
|
|
29
|
+
/** Maximum bytes to fetch from an HTML page before conversion. */
|
|
30
|
+
export declare const MAX_HTML_BYTES = 200000;
|
|
31
|
+
/** Maximum value size for KV store entries (bytes). */
|
|
32
|
+
export declare const MAX_VALUE_SIZE = 65536;
|
|
33
|
+
/** Maximum glob pattern length to prevent ReDoS. */
|
|
34
|
+
export declare const MAX_GLOB_PATTERN_LENGTH = 1024;
|
|
35
|
+
/** Maximum conversation messages to retain (sliding window). */
|
|
36
|
+
export declare const DEFAULT_MAX_HISTORY = 200;
|
|
37
|
+
/**
|
|
38
|
+
* Content-Security-Policy applied to agent UI pages (both self-hosted and
|
|
39
|
+
* platform). Single source of truth — used by `secureHeaders` middleware
|
|
40
|
+
* and per-response CSP headers.
|
|
41
|
+
*/
|
|
42
|
+
export declare const AGENT_CSP: string;
|