@alexkroman1/aai 0.11.0 → 0.12.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/{direct-executor-DAGCZOAN.js → direct-executor-ZUU0Ke4j.js} +146 -276
- package/dist/{_run-code.d.ts → host/_run-code.d.ts} +1 -1
- package/dist/{_runtime-conformance.d.ts → host/_runtime-conformance.d.ts} +4 -4
- package/dist/{_test-utils.d.ts → host/_test-utils.d.ts} +3 -3
- package/dist/{builtin-tools.d.ts → host/builtin-tools.d.ts} +2 -3
- package/dist/{direct-executor.d.ts → host/direct-executor.d.ts} +7 -7
- package/dist/{internal.d.ts → host/index.d.ts} +5 -6
- package/dist/{internal.js → host/index.js} +10 -9
- package/dist/{matchers.js → host/matchers.js} +2 -2
- package/dist/{server.d.ts → host/server.d.ts} +1 -17
- package/dist/{server.js → host/server.js} +37 -28
- package/dist/{session.d.ts → host/session.d.ts} +7 -7
- package/dist/{testing.d.ts → host/testing.d.ts} +2 -2
- package/dist/{testing.js → host/testing.js} +1 -1
- package/dist/{unstorage-kv.d.ts → host/unstorage-kv.d.ts} +1 -1
- package/dist/{vite-plugin.js → host/vite-plugin.js} +2 -1
- package/dist/{ws-handler.d.ts → host/ws-handler.d.ts} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{_internal-types.d.ts → isolate/_internal-types.d.ts} +0 -1
- package/dist/isolate/_kv-utils.d.ts +10 -0
- package/dist/{_utils.d.ts → isolate/_utils.d.ts} +0 -2
- package/dist/{_utils.js → isolate/_utils.js} +2 -13
- package/dist/{hooks.js → isolate/hooks.js} +1 -1
- package/dist/isolate/index.d.ts +18 -0
- package/dist/isolate/index.js +6 -0
- package/dist/{kv.d.ts → isolate/kv.d.ts} +0 -10
- package/dist/isolate/kv.js +1 -0
- package/dist/isolate/protocol.js +2 -0
- package/dist/{types.d.ts → isolate/types.d.ts} +1 -2
- package/dist/{types.js → isolate/types.js} +2 -3
- package/dist/{protocol.js → protocol-rcOrz7T3.js} +46 -3
- package/dist/system-prompt-CVJSQJiA.js +91 -0
- package/dist/{testing-Dmx-dudh.js → testing-Bb2B5Uob.js} +7 -7
- package/package.json +39 -34
- package/dist/constants-CwotjpJR.js +0 -45
- package/dist/kv.js +0 -33
- package/dist/memory-tools.d.ts +0 -39
- package/dist/{_mock-ws.d.ts → host/_mock-ws.d.ts} +0 -0
- package/dist/{matchers.d.ts → host/matchers.d.ts} +0 -0
- package/dist/{runtime.d.ts → host/runtime.d.ts} +0 -0
- package/dist/{s2s.d.ts → host/s2s.d.ts} +0 -0
- package/dist/{vite-plugin.d.ts → host/vite-plugin.d.ts} +0 -0
- package/dist/{constants.d.ts → isolate/constants.d.ts} +0 -0
- package/dist/{hooks.d.ts → isolate/hooks.d.ts} +0 -0
- package/dist/{protocol.d.ts → isolate/protocol.d.ts} +3 -3
- /package/dist/{system-prompt.d.ts → isolate/system-prompt.d.ts} +0 -0
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* {@link createServer} wraps a {@link Runtime} with an HTTP + WebSocket
|
|
5
5
|
* server using only `node:http` and `ws` (no framework dependencies).
|
|
6
6
|
*/
|
|
7
|
+
import type { Kv } from "../isolate/kv.ts";
|
|
7
8
|
import type { Runtime } from "./direct-executor.ts";
|
|
8
|
-
import type { Kv } from "./kv.ts";
|
|
9
9
|
import type { Logger } from "./runtime.ts";
|
|
10
10
|
export { createRuntime, type Runtime, type RuntimeOptions } from "./direct-executor.ts";
|
|
11
11
|
/**
|
|
@@ -29,20 +29,4 @@ export type AgentServer = {
|
|
|
29
29
|
close(): Promise<void>;
|
|
30
30
|
port: number | undefined;
|
|
31
31
|
};
|
|
32
|
-
/**
|
|
33
|
-
* Create an HTTP + WebSocket server for self-hosted agent deployments.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { defineAgent } from "@alexkroman1/aai";
|
|
38
|
-
* import { createRuntime, createServer } from "@alexkroman1/aai/server";
|
|
39
|
-
*
|
|
40
|
-
* const agent = defineAgent({ name: "my-agent" });
|
|
41
|
-
* const runtime = createRuntime({ agent, env: process.env });
|
|
42
|
-
* const server = createServer({ runtime, name: agent.name });
|
|
43
|
-
* await server.listen(3000);
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
32
|
export declare function createServer(options: ServerOptions): AgentServer;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { u as AGENT_CSP } from "../protocol-rcOrz7T3.js";
|
|
2
|
+
import { d as consoleLogger, t as createRuntime } from "../direct-executor-ZUU0Ke4j.js";
|
|
3
|
+
import { WebSocketServer } from "ws";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import http from "node:http";
|
|
5
6
|
import path from "node:path";
|
|
6
|
-
|
|
7
|
-
//#region server.ts
|
|
7
|
+
//#region host/server.ts
|
|
8
8
|
/**
|
|
9
9
|
* Self-hostable agent server.
|
|
10
10
|
*
|
|
@@ -59,6 +59,26 @@ function serveStatic(dir, req, res) {
|
|
|
59
59
|
*
|
|
60
60
|
* @public
|
|
61
61
|
*/
|
|
62
|
+
function handleKvGet(kv, req, res) {
|
|
63
|
+
const key = new URL(req.url ?? "/", "http://localhost").searchParams.get("key");
|
|
64
|
+
if (!key) {
|
|
65
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
66
|
+
res.end(JSON.stringify({ error: "Missing key query parameter" }));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
kv.get(key).then((value) => {
|
|
70
|
+
if (value === null) {
|
|
71
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
72
|
+
res.end("null");
|
|
73
|
+
} else {
|
|
74
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
75
|
+
res.end(JSON.stringify(value));
|
|
76
|
+
}
|
|
77
|
+
}).catch(() => {
|
|
78
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
79
|
+
res.end(JSON.stringify({ error: "KV error" }));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
62
82
|
function createServer(options) {
|
|
63
83
|
const { runtime, clientHtml, clientDir, logger = consoleLogger, kv } = options;
|
|
64
84
|
const name = options.name ?? "agent";
|
|
@@ -78,24 +98,7 @@ function createServer(options) {
|
|
|
78
98
|
return;
|
|
79
99
|
}
|
|
80
100
|
if (kv && method === "GET" && url === "/kv") {
|
|
81
|
-
|
|
82
|
-
if (!key) {
|
|
83
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
84
|
-
res.end(JSON.stringify({ error: "Missing key query parameter" }));
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
kv.get(key).then((value) => {
|
|
88
|
-
if (value === null) {
|
|
89
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
90
|
-
res.end("null");
|
|
91
|
-
} else {
|
|
92
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
93
|
-
res.end(JSON.stringify(value));
|
|
94
|
-
}
|
|
95
|
-
}).catch(() => {
|
|
96
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
97
|
-
res.end(JSON.stringify({ error: "KV error" }));
|
|
98
|
-
});
|
|
101
|
+
handleKvGet(kv, req, res);
|
|
99
102
|
return;
|
|
100
103
|
}
|
|
101
104
|
if (clientDir && serveStatic(clientDir, req, res)) return;
|
|
@@ -142,12 +145,18 @@ function createServer(options) {
|
|
|
142
145
|
});
|
|
143
146
|
},
|
|
144
147
|
async close() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
try {
|
|
149
|
+
await runtime.shutdown();
|
|
150
|
+
} finally {
|
|
151
|
+
try {
|
|
152
|
+
wss.close();
|
|
153
|
+
} finally {
|
|
154
|
+
if (listenPort !== void 0) await new Promise((resolve, reject) => {
|
|
155
|
+
httpServer.close((err) => err ? reject(err) : resolve());
|
|
156
|
+
});
|
|
157
|
+
listenPort = void 0;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
151
160
|
}
|
|
152
161
|
};
|
|
153
162
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** S2S session — relays audio between client and AssemblyAI S2S API. */
|
|
2
|
-
import type { AgentConfig, ExecuteTool, ToolSchema } from "
|
|
3
|
-
import type { AgentHookMap, AgentHooks } from "
|
|
4
|
-
import type { ClientSink } from "
|
|
2
|
+
import type { AgentConfig, ExecuteTool, ToolSchema } from "../isolate/_internal-types.ts";
|
|
3
|
+
import type { AgentHookMap, AgentHooks } from "../isolate/hooks.ts";
|
|
4
|
+
import type { ClientSink } from "../isolate/protocol.ts";
|
|
5
|
+
import type { Message } from "../isolate/types.ts";
|
|
5
6
|
import type { Logger, S2SConfig } from "./runtime.ts";
|
|
6
7
|
import { type CreateS2sWebSocket, connectS2s, type S2sHandle } from "./s2s.ts";
|
|
7
|
-
import type { Message } from "./types.ts";
|
|
8
8
|
export type { S2sHandle } from "./s2s.ts";
|
|
9
9
|
type PendingTool = {
|
|
10
10
|
callId: string;
|
|
@@ -63,9 +63,9 @@ export declare function buildCtx(opts: {
|
|
|
63
63
|
log: Logger;
|
|
64
64
|
maxHistory?: number | undefined;
|
|
65
65
|
}): S2sSessionCtx;
|
|
66
|
-
export type { AgentHookMap, AgentHooks } from "
|
|
67
|
-
export { callResolveTurnConfig, createAgentHooks } from "
|
|
68
|
-
export { buildSystemPrompt } from "
|
|
66
|
+
export type { AgentHookMap, AgentHooks } from "../isolate/hooks.ts";
|
|
67
|
+
export { callResolveTurnConfig, createAgentHooks } from "../isolate/hooks.ts";
|
|
68
|
+
export { buildSystemPrompt } from "../isolate/system-prompt.ts";
|
|
69
69
|
/**
|
|
70
70
|
* A voice session managing the Speech-to-Speech connection for one client.
|
|
71
71
|
*
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
*
|
|
36
36
|
* @packageDocumentation
|
|
37
37
|
*/
|
|
38
|
+
import type { Kv } from "../isolate/kv.ts";
|
|
39
|
+
import type { AgentDef, Message } from "../isolate/types.ts";
|
|
38
40
|
import { type Runtime } from "./direct-executor.ts";
|
|
39
|
-
import type { Kv } from "./kv.ts";
|
|
40
|
-
import type { AgentDef, Message } from "./types.ts";
|
|
41
41
|
export { installMockWebSocket, MockWebSocket } from "./_mock-ws.ts";
|
|
42
42
|
export { flush, makeStubSession } from "./_test-utils.ts";
|
|
43
43
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as makeStubSession, i as flush, n as TurnResult, o as MockWebSocket, r as createTestHarness, s as installMockWebSocket, t as TestHarness } from "
|
|
1
|
+
import { a as makeStubSession, i as flush, n as TurnResult, o as MockWebSocket, r as createTestHarness, s as installMockWebSocket, t as TestHarness } from "../testing-Bb2B5Uob.js";
|
|
2
2
|
export { MockWebSocket, TestHarness, TurnResult, createTestHarness, flush, installMockWebSocket, makeStubSession };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
|
-
//#region vite-plugin.ts
|
|
3
|
+
//#region host/vite-plugin.ts
|
|
4
4
|
/**
|
|
5
5
|
* Vite plugin for AAI agent development.
|
|
6
6
|
*
|
|
@@ -66,6 +66,7 @@ function aai(options) {
|
|
|
66
66
|
}),
|
|
67
67
|
name: agentDef.name
|
|
68
68
|
});
|
|
69
|
+
if (backendPort == null) throw new Error("backendPort was not resolved during config phase");
|
|
69
70
|
await agentServer.listen(backendPort);
|
|
70
71
|
server = agentServer;
|
|
71
72
|
viteServer.config.logger.info(`Agent backend on port ${backendPort}`);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Audio validation is handled at the host transport layer (see server.ts).
|
|
5
5
|
*/
|
|
6
|
-
import type { ClientSink, ReadyConfig } from "
|
|
6
|
+
import type { ClientSink, ReadyConfig } from "../isolate/protocol.ts";
|
|
7
7
|
import type { Logger } from "./runtime.ts";
|
|
8
8
|
import type { Session } from "./session.ts";
|
|
9
9
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
* });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export type { Kv, KvEntry, KvListOptions } from "./kv.ts";
|
|
23
|
-
export { type AgentDef, type AgentOptions, type BuiltinTool, defineAgent, defineTool, defineToolFactory, type HookContext, type Message, type ToolChoice, type ToolContext, type ToolDef, type ToolResultMap, tool, } from "./types.ts";
|
|
22
|
+
export type { Kv, KvEntry, KvListOptions } from "./isolate/kv.ts";
|
|
23
|
+
export { type AgentDef, type AgentOptions, type BuiltinTool, defineAgent, defineTool, defineToolFactory, type HookContext, type Message, type ToolChoice, type ToolContext, type ToolDef, type ToolResultMap, tool, } from "./isolate/types.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { defineAgent, defineTool, defineToolFactory } from "./types.js";
|
|
1
|
+
import { defineAgent, defineTool, defineToolFactory } from "./isolate/types.js";
|
|
2
2
|
export { defineAgent, defineTool, defineTool as tool, defineToolFactory };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Internal KV helpers shared by kv.ts and unstorage-kv.ts. */
|
|
2
|
+
/** Sort entries by key and apply reverse/limit options. Mutates the array. */
|
|
3
|
+
export declare function sortAndPaginate<T extends {
|
|
4
|
+
key: string;
|
|
5
|
+
}>(entries: T[], options?: {
|
|
6
|
+
limit?: number;
|
|
7
|
+
reverse?: boolean;
|
|
8
|
+
}): T[];
|
|
9
|
+
/** Simple glob matcher — supports `*` as a wildcard for any characters. */
|
|
10
|
+
export declare function matchGlob(key: string, pattern: string): boolean;
|
|
@@ -3,7 +3,5 @@
|
|
|
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
|
-
/** Check whether a filesystem operation is a read-only operation. */
|
|
7
|
-
export declare function isReadOnlyFsOp(op: string): boolean;
|
|
8
6
|
/** Return a JSON error string for the LLM: `'{"error":"<message>"}'`. */
|
|
9
7
|
export declare function toolError(message: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region _utils.ts
|
|
1
|
+
//#region isolate/_utils.ts
|
|
2
2
|
/** Shared utility functions. */
|
|
3
3
|
/** Extract an error message from an unknown thrown value. */
|
|
4
4
|
function errorMessage(err) {
|
|
@@ -9,20 +9,9 @@ function errorDetail(err) {
|
|
|
9
9
|
if (err instanceof Error) return err.stack ?? err.message;
|
|
10
10
|
return String(err);
|
|
11
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
12
|
/** Return a JSON error string for the LLM: `'{"error":"<message>"}'`. */
|
|
24
13
|
function toolError(message) {
|
|
25
14
|
return JSON.stringify({ error: message });
|
|
26
15
|
}
|
|
27
16
|
//#endregion
|
|
28
|
-
export { errorDetail, errorMessage,
|
|
17
|
+
export { errorDetail, errorMessage, toolError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolate-safe barrel — re-exports all SDK modules that are guaranteed to
|
|
3
|
+
* run inside secure-exec V8 isolates (no `node:*` dependencies).
|
|
4
|
+
*
|
|
5
|
+
* This directory is compiled under a restricted `tsconfig.json` that excludes
|
|
6
|
+
* `@types/node`. Any accidental `node:*` import becomes a type error.
|
|
7
|
+
*
|
|
8
|
+
* Host-only code (server, executor, S2S, etc.) lives at the package root
|
|
9
|
+
* and is re-exported via `./host`.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./_internal-types.ts";
|
|
12
|
+
export * from "./_utils.ts";
|
|
13
|
+
export * from "./constants.ts";
|
|
14
|
+
export * from "./hooks.ts";
|
|
15
|
+
export * from "./kv.ts";
|
|
16
|
+
export * from "./protocol.ts";
|
|
17
|
+
export * from "./system-prompt.ts";
|
|
18
|
+
export * from "./types.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BuiltinToolSchema, DEFAULT_GREETING, DEFAULT_INSTRUCTIONS, ToolChoiceSchema, defineAgent, defineTool, defineToolFactory } from "./types.js";
|
|
2
|
+
import { a as agentToolsToSchemas, i as ToolSchemaSchema, n as AgentConfigSchema, o as toAgentConfig, r as EMPTY_PARAMS, t as buildSystemPrompt } from "../system-prompt-CVJSQJiA.js";
|
|
3
|
+
import { errorDetail, errorMessage, toolError } from "./_utils.js";
|
|
4
|
+
import { C as MAX_VALUE_SIZE, S as MAX_TOOL_RESULT_CHARS, T as TOOL_EXECUTION_TIMEOUT_MS, _ as FETCH_TIMEOUT_MS, a as ReadyConfigSchema, b as MAX_HTML_BYTES, c as TurnConfigSchema, d as DEFAULT_IDLE_TIMEOUT_MS, f as DEFAULT_MAX_HISTORY, g as DEFAULT_TTS_SAMPLE_RATE, h as DEFAULT_STT_SAMPLE_RATE, i as KvRequestSchema, l as buildReadyConfig, m as DEFAULT_SHUTDOWN_TIMEOUT_MS, n as ClientEventSchema, o as ServerMessageSchema, p as DEFAULT_SESSION_START_TIMEOUT_MS, r as ClientMessageSchema, s as SessionErrorCodeSchema, t as AUDIO_FORMAT, u as AGENT_CSP, v as HOOK_TIMEOUT_MS, w as RUN_CODE_TIMEOUT_MS, x as MAX_PAGE_CHARS, y as MAX_GLOB_PATTERN_LENGTH } from "../protocol-rcOrz7T3.js";
|
|
5
|
+
import { callResolveTurnConfig, createAgentHooks } from "./hooks.js";
|
|
6
|
+
export { AGENT_CSP, AUDIO_FORMAT, AgentConfigSchema, BuiltinToolSchema, ClientEventSchema, ClientMessageSchema, DEFAULT_GREETING, DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_INSTRUCTIONS, DEFAULT_MAX_HISTORY, DEFAULT_SESSION_START_TIMEOUT_MS, DEFAULT_SHUTDOWN_TIMEOUT_MS, DEFAULT_STT_SAMPLE_RATE, DEFAULT_TTS_SAMPLE_RATE, EMPTY_PARAMS, FETCH_TIMEOUT_MS, HOOK_TIMEOUT_MS, KvRequestSchema, MAX_GLOB_PATTERN_LENGTH, MAX_HTML_BYTES, MAX_PAGE_CHARS, MAX_TOOL_RESULT_CHARS, MAX_VALUE_SIZE, RUN_CODE_TIMEOUT_MS, ReadyConfigSchema, ServerMessageSchema, SessionErrorCodeSchema, TOOL_EXECUTION_TIMEOUT_MS, ToolChoiceSchema, ToolSchemaSchema, TurnConfigSchema, agentToolsToSchemas, buildReadyConfig, buildSystemPrompt, callResolveTurnConfig, createAgentHooks, defineAgent, defineTool, defineTool as tool, defineToolFactory, errorDetail, errorMessage, toAgentConfig, toolError };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Key-value storage interface and shared utilities.
|
|
3
3
|
*/
|
|
4
|
-
export { MAX_VALUE_SIZE } from "./constants.ts";
|
|
5
4
|
/**
|
|
6
5
|
* A single key-value entry returned by {@link Kv.list}.
|
|
7
6
|
*
|
|
@@ -107,12 +106,3 @@ export type Kv = {
|
|
|
107
106
|
*/
|
|
108
107
|
close?(): void;
|
|
109
108
|
};
|
|
110
|
-
/** Sort entries by key and apply reverse/limit options. Mutates the array. */
|
|
111
|
-
export declare function sortAndPaginate<T extends {
|
|
112
|
-
key: string;
|
|
113
|
-
}>(entries: T[], options?: {
|
|
114
|
-
limit?: number;
|
|
115
|
-
reverse?: boolean;
|
|
116
|
-
}): T[];
|
|
117
|
-
/** Simple glob matcher — supports `*` as a wildcard for any characters. */
|
|
118
|
-
export declare function matchGlob(key: string, pattern: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ReadyConfigSchema, c as TurnConfigSchema, i as KvRequestSchema, l as buildReadyConfig, n as ClientEventSchema, o as ServerMessageSchema, r as ClientMessageSchema, s as SessionErrorCodeSchema, t as AUDIO_FORMAT } from "../protocol-rcOrz7T3.js";
|
|
2
|
+
export { AUDIO_FORMAT, ClientEventSchema, ClientMessageSchema, KvRequestSchema, ReadyConfigSchema, ServerMessageSchema, SessionErrorCodeSchema, TurnConfigSchema, buildReadyConfig };
|
|
@@ -17,7 +17,7 @@ import type { Kv } from "./kv.ts";
|
|
|
17
17
|
*
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
-
export type BuiltinTool = "web_search" | "visit_webpage" | "fetch_json" | "run_code"
|
|
20
|
+
export type BuiltinTool = "web_search" | "visit_webpage" | "fetch_json" | "run_code";
|
|
21
21
|
/**
|
|
22
22
|
* How the LLM should select tools during a turn.
|
|
23
23
|
*
|
|
@@ -375,7 +375,6 @@ export declare const BuiltinToolSchema: z.ZodEnum<{
|
|
|
375
375
|
visit_webpage: "visit_webpage";
|
|
376
376
|
fetch_json: "fetch_json";
|
|
377
377
|
run_code: "run_code";
|
|
378
|
-
memory: "memory";
|
|
379
378
|
}>;
|
|
380
379
|
/** @internal Zod schema for {@link ToolChoice}. Exported for reuse in internal schemas. */
|
|
381
380
|
export declare const ToolChoiceSchema: z.ZodUnion<readonly [z.ZodEnum<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
//#region types.ts
|
|
2
|
+
//#region isolate/types.ts
|
|
3
3
|
/**
|
|
4
4
|
* Core type definitions for the AAI agent SDK.
|
|
5
5
|
*/
|
|
@@ -99,8 +99,7 @@ const BuiltinToolSchema = z.enum([
|
|
|
99
99
|
"web_search",
|
|
100
100
|
"visit_webpage",
|
|
101
101
|
"fetch_json",
|
|
102
|
-
"run_code"
|
|
103
|
-
"memory"
|
|
102
|
+
"run_code"
|
|
104
103
|
]);
|
|
105
104
|
/** @internal Zod schema for {@link ToolChoice}. Exported for reuse in internal schemas. */
|
|
106
105
|
const ToolChoiceSchema = z.union([z.enum([
|
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
import { p as MAX_TOOL_RESULT_CHARS } from "./constants-CwotjpJR.js";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
//#region
|
|
2
|
+
//#region isolate/constants.ts
|
|
3
|
+
/**
|
|
4
|
+
* Centralised numeric constants — timeouts, size limits, sample rates.
|
|
5
|
+
*
|
|
6
|
+
* Every magic number that controls a timeout, buffer size, or threshold
|
|
7
|
+
* lives here so the values are discoverable in one place.
|
|
8
|
+
*/
|
|
9
|
+
/** Default sample rate for speech-to-text audio in Hz (AssemblyAI). */
|
|
10
|
+
const DEFAULT_STT_SAMPLE_RATE = 16e3;
|
|
11
|
+
/** Default sample rate for text-to-speech audio in Hz. */
|
|
12
|
+
const DEFAULT_TTS_SAMPLE_RATE = 24e3;
|
|
13
|
+
/** Default timeout for agent lifecycle hooks (onConnect, onTurn, etc). */
|
|
14
|
+
const HOOK_TIMEOUT_MS = 5e3;
|
|
15
|
+
/** Default timeout for tool execution in the worker. */
|
|
16
|
+
const TOOL_EXECUTION_TIMEOUT_MS = 3e4;
|
|
17
|
+
/** Timeout for session.start() (S2S connection setup). */
|
|
18
|
+
const DEFAULT_SESSION_START_TIMEOUT_MS = 1e4;
|
|
19
|
+
/** S2S session idle timeout before auto-close. */
|
|
20
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 3e5;
|
|
21
|
+
/** Per-fetch timeout for network tools (web_search, visit_webpage, fetch_json). */
|
|
22
|
+
const FETCH_TIMEOUT_MS = 15e3;
|
|
23
|
+
/** Timeout for sandboxed run_code execution. */
|
|
24
|
+
const RUN_CODE_TIMEOUT_MS = 5e3;
|
|
25
|
+
/** Maximum time to wait for sessions to stop during graceful shutdown. */
|
|
26
|
+
const DEFAULT_SHUTDOWN_TIMEOUT_MS = 3e4;
|
|
27
|
+
/** Maximum length for tool result strings sent to clients. */
|
|
28
|
+
const MAX_TOOL_RESULT_CHARS = 4e3;
|
|
29
|
+
/** Maximum chars for webpage text after HTML-to-text conversion. */
|
|
30
|
+
const MAX_PAGE_CHARS = 1e4;
|
|
31
|
+
/** Maximum bytes to fetch from an HTML page before conversion. */
|
|
32
|
+
const MAX_HTML_BYTES = 2e5;
|
|
33
|
+
/** Maximum value size for KV store entries (bytes). */
|
|
34
|
+
const MAX_VALUE_SIZE = 65536;
|
|
35
|
+
/** Maximum glob pattern length to prevent ReDoS. */
|
|
36
|
+
const MAX_GLOB_PATTERN_LENGTH = 1024;
|
|
37
|
+
/** Maximum conversation messages to retain (sliding window). */
|
|
38
|
+
const DEFAULT_MAX_HISTORY = 200;
|
|
39
|
+
/**
|
|
40
|
+
* Content-Security-Policy applied to agent UI pages (both self-hosted and
|
|
41
|
+
* platform). Single source of truth — used by `secureHeaders` middleware
|
|
42
|
+
* and per-response CSP headers.
|
|
43
|
+
*/
|
|
44
|
+
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'";
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region isolate/protocol.ts
|
|
4
47
|
/**
|
|
5
48
|
* WebSocket wire-format types shared by server and client.
|
|
6
49
|
*
|
|
@@ -137,4 +180,4 @@ function buildReadyConfig(s2sConfig) {
|
|
|
137
180
|
/** Zod schema for {@link TurnConfig}. */
|
|
138
181
|
const TurnConfigSchema = z.object({ maxSteps: z.number().int().positive().optional() });
|
|
139
182
|
//#endregion
|
|
140
|
-
export {
|
|
183
|
+
export { MAX_VALUE_SIZE as C, MAX_TOOL_RESULT_CHARS as S, TOOL_EXECUTION_TIMEOUT_MS as T, FETCH_TIMEOUT_MS as _, ReadyConfigSchema as a, MAX_HTML_BYTES as b, TurnConfigSchema as c, DEFAULT_IDLE_TIMEOUT_MS as d, DEFAULT_MAX_HISTORY as f, DEFAULT_TTS_SAMPLE_RATE as g, DEFAULT_STT_SAMPLE_RATE as h, KvRequestSchema as i, buildReadyConfig as l, DEFAULT_SHUTDOWN_TIMEOUT_MS as m, ClientEventSchema as n, ServerMessageSchema as o, DEFAULT_SESSION_START_TIMEOUT_MS as p, ClientMessageSchema as r, SessionErrorCodeSchema as s, AUDIO_FORMAT as t, AGENT_CSP as u, HOOK_TIMEOUT_MS as v, RUN_CODE_TIMEOUT_MS as w, MAX_PAGE_CHARS as x, MAX_GLOB_PATTERN_LENGTH as y };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BuiltinToolSchema, DEFAULT_INSTRUCTIONS, ToolChoiceSchema } from "./isolate/types.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region isolate/_internal-types.ts
|
|
4
|
+
/**
|
|
5
|
+
* Zod schema for serializable agent configuration sent over the wire.
|
|
6
|
+
*
|
|
7
|
+
* This is the JSON-safe subset of the agent definition that can be
|
|
8
|
+
* transmitted between the worker and the host process via structured clone.
|
|
9
|
+
*/
|
|
10
|
+
const AgentConfigSchema = z.object({
|
|
11
|
+
name: z.string().min(1),
|
|
12
|
+
instructions: z.string(),
|
|
13
|
+
greeting: z.string(),
|
|
14
|
+
sttPrompt: z.string().optional(),
|
|
15
|
+
maxSteps: z.number().int().positive().optional(),
|
|
16
|
+
toolChoice: ToolChoiceSchema.optional(),
|
|
17
|
+
builtinTools: z.array(BuiltinToolSchema).readonly().optional(),
|
|
18
|
+
idleTimeoutMs: z.number().nonnegative().optional()
|
|
19
|
+
});
|
|
20
|
+
/** Extract the serializable {@link AgentConfig} subset from a source object. */
|
|
21
|
+
function toAgentConfig(src) {
|
|
22
|
+
const config = {
|
|
23
|
+
name: src.name,
|
|
24
|
+
instructions: src.instructions,
|
|
25
|
+
greeting: src.greeting
|
|
26
|
+
};
|
|
27
|
+
if (src.sttPrompt !== void 0) config.sttPrompt = src.sttPrompt;
|
|
28
|
+
if (typeof src.maxSteps !== "function" && src.maxSteps !== void 0) config.maxSteps = src.maxSteps;
|
|
29
|
+
if (src.toolChoice !== void 0) config.toolChoice = src.toolChoice;
|
|
30
|
+
if (src.builtinTools) config.builtinTools = [...src.builtinTools];
|
|
31
|
+
if (src.idleTimeoutMs !== void 0) config.idleTimeoutMs = src.idleTimeoutMs;
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Zod schema for serialized tool definitions sent over the wire.
|
|
36
|
+
*
|
|
37
|
+
* `parameters` must be a valid JSON Schema object (with `type`, `properties`,
|
|
38
|
+
* etc.) — the Vercel AI SDK wraps it via `jsonSchema()`.
|
|
39
|
+
*/
|
|
40
|
+
const ToolSchemaSchema = z.object({
|
|
41
|
+
name: z.string().min(1),
|
|
42
|
+
description: z.string().min(1),
|
|
43
|
+
parameters: z.record(z.string(), z.unknown())
|
|
44
|
+
});
|
|
45
|
+
/** Empty Zod object schema used as default when tools have no parameters. */
|
|
46
|
+
const EMPTY_PARAMS = z.object({});
|
|
47
|
+
/**
|
|
48
|
+
* Convert agent tool definitions to JSON Schema format for wire transport.
|
|
49
|
+
*
|
|
50
|
+
* Transforms the Zod-based `parameters` of each tool into a plain JSON Schema
|
|
51
|
+
* object suitable for structured clone / JSON serialization.
|
|
52
|
+
*/
|
|
53
|
+
function agentToolsToSchemas(tools) {
|
|
54
|
+
return Object.entries(tools).map(([name, def]) => ({
|
|
55
|
+
name,
|
|
56
|
+
description: def.description,
|
|
57
|
+
parameters: z.toJSONSchema(def.parameters ?? EMPTY_PARAMS)
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region isolate/system-prompt.ts
|
|
62
|
+
function getFormattedDate() {
|
|
63
|
+
return (/* @__PURE__ */ new Date()).toLocaleDateString("en-US", {
|
|
64
|
+
weekday: "long",
|
|
65
|
+
year: "numeric",
|
|
66
|
+
month: "long",
|
|
67
|
+
day: "numeric"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const VOICE_RULES = "\n\nCRITICAL OUTPUT RULES — you MUST follow these for EVERY response:\nYour response will be spoken aloud by a TTS system and displayed as plain text.\n- NEVER use markdown: no **, no *, no _, no #, no `, no [](), no ---\n- NEVER use bullet points (-, *, •) or numbered lists (1., 2.)\n- NEVER use code blocks or inline code\n- NEVER mention tools, search, APIs, or technical failures to the user. If a tool returns no results, just answer naturally without explaining why.\n- Write exactly as you would say it out loud to a friend\n- Use short conversational sentences. To list things, say \"First,\" \"Next,\" \"Finally,\"\n- Keep responses concise — 1 to 3 sentences max";
|
|
71
|
+
/**
|
|
72
|
+
* Build the system prompt sent to the LLM from the agent configuration.
|
|
73
|
+
*
|
|
74
|
+
* Assembles the default instructions, today's date, agent-specific instructions,
|
|
75
|
+
* and optional sections for tool usage preamble and voice output rules.
|
|
76
|
+
*
|
|
77
|
+
* @param config - The serializable agent configuration (name, instructions, etc.).
|
|
78
|
+
* @param opts.hasTools - When `true`, appends a preamble instructing the LLM to
|
|
79
|
+
* speak a brief phrase before each tool call to fill silence.
|
|
80
|
+
* @param opts.voice - When `true`, appends strict voice-specific output rules
|
|
81
|
+
* (no markdown, no bullet points, conversational tone, concise responses).
|
|
82
|
+
* @returns The assembled system prompt string.
|
|
83
|
+
*/
|
|
84
|
+
function buildSystemPrompt(config, opts) {
|
|
85
|
+
const { hasTools } = opts;
|
|
86
|
+
const agentInstructions = config.instructions && config.instructions !== DEFAULT_INSTRUCTIONS ? `\n\nAgent-Specific Instructions:\n${config.instructions}` : "";
|
|
87
|
+
const toolPreamble = hasTools ? "\n\nWhen you decide to use a tool, ALWAYS say a brief natural phrase BEFORE the tool call (e.g. \"Let me look that up\" or \"One moment while I check\"). This fills silence while the tool executes. Keep preambles to one short sentence." : "";
|
|
88
|
+
return DEFAULT_INSTRUCTIONS + `\n\nToday's date is ${getFormattedDate()}.` + agentInstructions + toolPreamble + (opts.voice ? VOICE_RULES : "");
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { agentToolsToSchemas as a, ToolSchemaSchema as i, AgentConfigSchema as n, toAgentConfig as o, EMPTY_PARAMS as r, buildSystemPrompt as t };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./types.js";
|
|
2
|
-
import { i as createUnstorageKv, t as createRuntime } from "./direct-executor-
|
|
3
|
-
import {
|
|
1
|
+
import "./isolate/types.js";
|
|
2
|
+
import { i as createUnstorageKv, t as createRuntime } from "./direct-executor-ZUU0Ke4j.js";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
4
|
import { createStorage } from "unstorage";
|
|
5
5
|
import "nanoevents";
|
|
6
|
-
import {
|
|
7
|
-
//#region _mock-ws.ts
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
//#region host/_mock-ws.ts
|
|
8
8
|
/**
|
|
9
9
|
* A mock WebSocket implementation for testing.
|
|
10
10
|
*
|
|
@@ -157,7 +157,7 @@ function installMockWebSocket() {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
//#endregion
|
|
160
|
-
//#region _test-utils.ts
|
|
160
|
+
//#region host/_test-utils.ts
|
|
161
161
|
/** Yield to the microtask queue so pending promises settle. */
|
|
162
162
|
function flush() {
|
|
163
163
|
return new Promise((r) => queueMicrotask(r));
|
|
@@ -179,7 +179,7 @@ function makeStubSession(overrides) {
|
|
|
179
179
|
vi.fn(), vi.fn(), vi.fn(), vi.fn();
|
|
180
180
|
resolve(import.meta.dirname, "__fixtures__");
|
|
181
181
|
//#endregion
|
|
182
|
-
//#region testing.ts
|
|
182
|
+
//#region host/testing.ts
|
|
183
183
|
/**
|
|
184
184
|
* Testing utilities for AAI agents.
|
|
185
185
|
*
|