@alexkroman1/aai 0.4.0 → 0.6.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/README.md +0 -6
- package/dist/aai.js +3 -0
- package/dist/cli.js +244 -245
- package/dist/sdk/_internal_types.d.ts +73 -0
- package/dist/sdk/_internal_types.d.ts.map +1 -0
- package/dist/sdk/_internal_types.js +24 -0
- package/dist/sdk/_internal_types.js.map +1 -0
- package/dist/sdk/_mock_ws.d.ts +105 -0
- package/dist/sdk/_mock_ws.d.ts.map +1 -0
- package/dist/sdk/_mock_ws.js +154 -0
- package/dist/sdk/_mock_ws.js.map +1 -0
- package/dist/sdk/_timeout.d.ts +14 -0
- package/dist/sdk/_timeout.d.ts.map +1 -0
- package/{sdk/_timeout.ts → dist/sdk/_timeout.js} +9 -9
- package/dist/sdk/_timeout.js.map +1 -0
- package/dist/sdk/builtin_tools.d.ts +33 -0
- package/dist/sdk/builtin_tools.d.ts.map +1 -0
- package/dist/sdk/builtin_tools.js +263 -0
- package/dist/sdk/builtin_tools.js.map +1 -0
- package/dist/sdk/capnweb.d.ts +69 -0
- package/dist/sdk/capnweb.d.ts.map +1 -0
- package/dist/sdk/capnweb.js +291 -0
- package/dist/sdk/capnweb.js.map +1 -0
- package/dist/sdk/define_agent.d.ts +36 -0
- package/dist/sdk/define_agent.d.ts.map +1 -0
- package/dist/sdk/define_agent.js +63 -0
- package/dist/sdk/define_agent.js.map +1 -0
- package/dist/sdk/direct_executor.d.ts +42 -0
- package/dist/sdk/direct_executor.d.ts.map +1 -0
- package/dist/sdk/direct_executor.js +143 -0
- package/dist/sdk/direct_executor.js.map +1 -0
- package/dist/sdk/kv.d.ts +123 -0
- package/dist/sdk/kv.d.ts.map +1 -0
- package/dist/sdk/kv.js +91 -0
- package/dist/sdk/kv.js.map +1 -0
- package/{sdk/mod.ts → dist/sdk/mod.d.ts} +2 -11
- package/dist/sdk/mod.d.ts.map +1 -0
- package/dist/sdk/mod.js +26 -0
- package/dist/sdk/mod.js.map +1 -0
- package/dist/sdk/protocol.d.ts +218 -0
- package/dist/sdk/protocol.d.ts.map +1 -0
- package/dist/sdk/protocol.js +140 -0
- package/dist/sdk/protocol.js.map +1 -0
- package/dist/sdk/runtime.d.ts +35 -0
- package/dist/sdk/runtime.d.ts.map +1 -0
- package/dist/sdk/runtime.js +46 -0
- package/dist/sdk/runtime.js.map +1 -0
- package/dist/sdk/s2s.d.ts +60 -0
- package/dist/sdk/s2s.d.ts.map +1 -0
- package/dist/sdk/s2s.js +171 -0
- package/dist/sdk/s2s.js.map +1 -0
- package/dist/sdk/server.d.ts +51 -0
- package/dist/sdk/server.d.ts.map +1 -0
- package/dist/sdk/server.js +145 -0
- package/dist/sdk/server.js.map +1 -0
- package/dist/sdk/session.d.ts +66 -0
- package/dist/sdk/session.d.ts.map +1 -0
- package/dist/sdk/session.js +324 -0
- package/dist/sdk/session.js.map +1 -0
- package/dist/sdk/system_prompt.d.ts +6 -0
- package/dist/sdk/system_prompt.d.ts.map +1 -0
- package/dist/sdk/system_prompt.js +35 -0
- package/dist/sdk/system_prompt.js.map +1 -0
- package/dist/sdk/types.d.ts +326 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +38 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/sdk/vector.d.ts +90 -0
- package/dist/sdk/vector.d.ts.map +1 -0
- package/dist/sdk/vector.js +61 -0
- package/dist/sdk/vector.js.map +1 -0
- package/dist/sdk/winterc_server.d.ts +53 -0
- package/dist/sdk/winterc_server.d.ts.map +1 -0
- package/dist/sdk/winterc_server.js +82 -0
- package/dist/sdk/winterc_server.js.map +1 -0
- package/dist/sdk/worker_entry.d.ts +48 -0
- package/dist/sdk/worker_entry.d.ts.map +1 -0
- package/dist/sdk/worker_entry.js +67 -0
- package/dist/sdk/worker_entry.js.map +1 -0
- package/dist/sdk/worker_shim.d.ts +20 -0
- package/dist/sdk/worker_shim.d.ts.map +1 -0
- package/dist/sdk/worker_shim.js +132 -0
- package/dist/sdk/worker_shim.js.map +1 -0
- package/dist/sdk/ws_handler.d.ts +50 -0
- package/dist/sdk/ws_handler.d.ts.map +1 -0
- package/dist/sdk/ws_handler.js +156 -0
- package/dist/sdk/ws_handler.js.map +1 -0
- package/dist/ui/_components/app.d.ts +3 -0
- package/dist/ui/_components/app.d.ts.map +1 -0
- package/dist/ui/_components/app.js +14 -0
- package/dist/ui/_components/app.js.map +1 -0
- package/dist/ui/_components/chat_view.d.ts +3 -0
- package/dist/ui/_components/chat_view.d.ts.map +1 -0
- package/dist/ui/_components/chat_view.js +14 -0
- package/dist/ui/_components/chat_view.js.map +1 -0
- package/dist/ui/_components/controls.d.ts +2 -0
- package/dist/ui/_components/controls.d.ts.map +1 -0
- package/dist/ui/_components/controls.js +11 -0
- package/dist/ui/_components/controls.js.map +1 -0
- package/dist/ui/_components/error_banner.d.ts +7 -0
- package/dist/ui/_components/error_banner.d.ts.map +1 -0
- package/dist/ui/_components/error_banner.js +7 -0
- package/dist/ui/_components/error_banner.js.map +1 -0
- package/dist/ui/_components/message_bubble.d.ts +6 -0
- package/dist/ui/_components/message_bubble.d.ts.map +1 -0
- package/dist/ui/_components/message_bubble.js +9 -0
- package/dist/ui/_components/message_bubble.js.map +1 -0
- package/dist/ui/_components/message_list.d.ts +2 -0
- package/dist/ui/_components/message_list.d.ts.map +1 -0
- package/dist/ui/_components/message_list.js +48 -0
- package/dist/ui/_components/message_list.js.map +1 -0
- package/dist/ui/_components/state_indicator.d.ts +7 -0
- package/dist/ui/_components/state_indicator.d.ts.map +1 -0
- package/dist/ui/_components/state_indicator.js +5 -0
- package/dist/ui/_components/state_indicator.js.map +1 -0
- package/dist/ui/_components/thinking_indicator.d.ts +3 -0
- package/dist/ui/_components/thinking_indicator.d.ts.map +1 -0
- package/dist/ui/_components/thinking_indicator.js +8 -0
- package/dist/ui/_components/thinking_indicator.js.map +1 -0
- package/dist/ui/_components/tool_call_block.d.ts +6 -0
- package/dist/ui/_components/tool_call_block.d.ts.map +1 -0
- package/dist/ui/_components/tool_call_block.js +58 -0
- package/dist/ui/_components/tool_call_block.js.map +1 -0
- package/dist/ui/_components/tool_icons.d.ts +18 -0
- package/dist/ui/_components/tool_icons.d.ts.map +1 -0
- package/dist/ui/_components/tool_icons.js +26 -0
- package/dist/ui/_components/tool_icons.js.map +1 -0
- package/dist/ui/_components/transcript.d.ts +6 -0
- package/dist/ui/_components/transcript.d.ts.map +1 -0
- package/dist/ui/_components/transcript.js +8 -0
- package/dist/ui/_components/transcript.js.map +1 -0
- package/dist/ui/_dom_shim.d.ts +7 -0
- package/dist/ui/_dom_shim.d.ts.map +1 -0
- package/dist/ui/_dom_shim.js +21 -0
- package/dist/ui/_dom_shim.js.map +1 -0
- package/dist/ui/_test_utils.js +272 -0
- package/dist/ui/_test_utils.js.map +1 -0
- package/dist/ui/audio.d.ts +46 -0
- package/dist/ui/audio.d.ts.map +1 -0
- package/dist/ui/audio.js +130 -0
- package/dist/ui/audio.js.map +1 -0
- package/dist/ui/components.d.ts +36 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js +32 -0
- package/dist/ui/components.js.map +1 -0
- package/{ui/components_mod.ts → dist/ui/components_mod.d.ts} +3 -18
- package/dist/ui/components_mod.d.ts.map +1 -0
- package/dist/ui/components_mod.js +20 -0
- package/dist/ui/components_mod.js.map +1 -0
- package/dist/ui/mod.d.ts +21 -0
- package/dist/ui/mod.d.ts.map +1 -0
- package/{ui/mod.ts → dist/ui/mod.js} +3 -29
- package/dist/ui/mod.js.map +1 -0
- package/dist/ui/mount.d.ts +56 -0
- package/dist/ui/mount.d.ts.map +1 -0
- package/dist/ui/mount.js +60 -0
- package/dist/ui/mount.js.map +1 -0
- package/dist/ui/mount_context.d.ts +10 -0
- package/dist/ui/mount_context.d.ts.map +1 -0
- package/dist/ui/mount_context.js +10 -0
- package/dist/ui/mount_context.js.map +1 -0
- package/dist/ui/session.d.ts +91 -0
- package/dist/ui/session.d.ts.map +1 -0
- package/dist/ui/session.js +366 -0
- package/dist/ui/session.js.map +1 -0
- package/{ui/session_mod.ts → dist/ui/session_mod.d.ts} +2 -10
- package/dist/ui/session_mod.d.ts.map +1 -0
- package/dist/ui/session_mod.js +18 -0
- package/dist/ui/session_mod.js.map +1 -0
- package/dist/ui/signals.d.ts +61 -0
- package/dist/ui/signals.d.ts.map +1 -0
- package/dist/ui/signals.js +74 -0
- package/dist/ui/signals.js.map +1 -0
- package/dist/ui/types.d.ts +36 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +4 -0
- package/dist/ui/types.js.map +1 -0
- package/package.json +103 -28
- package/sdk/_internal_types.ts +0 -89
- package/sdk/_mock_ws.ts +0 -172
- package/sdk/builtin_tools.ts +0 -309
- package/sdk/capnweb.ts +0 -341
- package/sdk/define_agent.ts +0 -70
- package/sdk/direct_executor.ts +0 -195
- package/sdk/kv.ts +0 -183
- package/sdk/protocol.ts +0 -313
- package/sdk/runtime.ts +0 -65
- package/sdk/s2s.ts +0 -271
- package/sdk/server.ts +0 -198
- package/sdk/session.ts +0 -438
- package/sdk/system_prompt.ts +0 -47
- package/sdk/types.ts +0 -406
- package/sdk/vector.ts +0 -133
- package/sdk/winterc_server.ts +0 -141
- package/sdk/worker_entry.ts +0 -99
- package/sdk/worker_shim.ts +0 -170
- package/sdk/ws_handler.ts +0 -190
- package/templates/_shared/.env.example +0 -5
- package/templates/_shared/package.json +0 -17
- package/templates/code-interpreter/agent.ts +0 -27
- package/templates/code-interpreter/client.tsx +0 -2
- package/templates/dispatch-center/agent.ts +0 -1536
- package/templates/dispatch-center/client.tsx +0 -504
- package/templates/embedded-assets/agent.ts +0 -49
- package/templates/embedded-assets/client.tsx +0 -2
- package/templates/embedded-assets/knowledge.json +0 -20
- package/templates/health-assistant/agent.ts +0 -160
- package/templates/health-assistant/client.tsx +0 -2
- package/templates/infocom-adventure/agent.ts +0 -164
- package/templates/infocom-adventure/client.tsx +0 -299
- package/templates/math-buddy/agent.ts +0 -21
- package/templates/math-buddy/client.tsx +0 -2
- package/templates/memory-agent/agent.ts +0 -74
- package/templates/memory-agent/client.tsx +0 -2
- package/templates/night-owl/agent.ts +0 -98
- package/templates/night-owl/client.tsx +0 -28
- package/templates/personal-finance/agent.ts +0 -26
- package/templates/personal-finance/client.tsx +0 -2
- package/templates/simple/agent.ts +0 -6
- package/templates/simple/client.tsx +0 -2
- package/templates/smart-research/agent.ts +0 -164
- package/templates/smart-research/client.tsx +0 -2
- package/templates/support/README.md +0 -62
- package/templates/support/agent.ts +0 -19
- package/templates/support/client.tsx +0 -2
- package/templates/travel-concierge/agent.ts +0 -29
- package/templates/travel-concierge/client.tsx +0 -2
- package/templates/web-researcher/agent.ts +0 -17
- package/templates/web-researcher/client.tsx +0 -2
- package/ui/_components/app.tsx +0 -37
- package/ui/_components/chat_view.tsx +0 -36
- package/ui/_components/controls.tsx +0 -32
- package/ui/_components/error_banner.tsx +0 -18
- package/ui/_components/message_bubble.tsx +0 -21
- package/ui/_components/message_list.tsx +0 -61
- package/ui/_components/state_indicator.tsx +0 -17
- package/ui/_components/thinking_indicator.tsx +0 -19
- package/ui/_components/tool_call_block.tsx +0 -110
- package/ui/_components/tool_icons.tsx +0 -101
- package/ui/_components/transcript.tsx +0 -20
- package/ui/audio.ts +0 -170
- package/ui/components.ts +0 -49
- package/ui/mount.tsx +0 -112
- package/ui/mount_context.ts +0 -19
- package/ui/session.ts +0 -456
- package/ui/signals.ts +0 -111
- package/ui/types.ts +0 -50
- package/ui/worklets/capture-processor.js +0 -62
- package/ui/worklets/playback-processor.js +0 -110
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal type definitions shared by server and CLI.
|
|
3
|
+
*
|
|
4
|
+
* Note: this module is for internal use only and should not be used directly.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { JSONSchema7 } from "json-schema";
|
|
9
|
+
import type { BuiltinTool, ToolChoice, ToolDef, Transport } from "./types.ts";
|
|
10
|
+
/**
|
|
11
|
+
* Serializable agent configuration sent over the wire.
|
|
12
|
+
*
|
|
13
|
+
* This is the JSON-safe subset of the agent definition that can be
|
|
14
|
+
* transmitted between the worker and the host process via structured clone.
|
|
15
|
+
*/
|
|
16
|
+
export type AgentConfig = {
|
|
17
|
+
name: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
greeting: string;
|
|
20
|
+
voice: string;
|
|
21
|
+
mode?: "s2s" | undefined;
|
|
22
|
+
sttPrompt?: string | undefined;
|
|
23
|
+
maxSteps?: number | undefined;
|
|
24
|
+
toolChoice?: ToolChoice | undefined;
|
|
25
|
+
transport?: readonly Transport[] | undefined;
|
|
26
|
+
builtinTools?: readonly BuiltinTool[] | undefined;
|
|
27
|
+
/** Default set of active tools. Can be overridden per-turn via `onBeforeStep`. */
|
|
28
|
+
activeTools?: readonly string[] | undefined;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Serialized tool schema sent over the wire.
|
|
32
|
+
* `parameters` must be a valid JSON Schema object (with `type`, `properties`,
|
|
33
|
+
* etc.) — the Vercel AI SDK wraps it via `jsonSchema()`.
|
|
34
|
+
*/
|
|
35
|
+
export type ToolSchema = {
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
parameters: JSONSchema7;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Request body for the deploy endpoint.
|
|
42
|
+
*
|
|
43
|
+
* Sent by the CLI to the server when deploying a bundled agent.
|
|
44
|
+
*/
|
|
45
|
+
export type DeployBody = {
|
|
46
|
+
/** Env vars are optional at deploy time — set separately via `aai env add`. */
|
|
47
|
+
env?: Readonly<Record<string, string>> | undefined;
|
|
48
|
+
worker: string;
|
|
49
|
+
html: string;
|
|
50
|
+
transport?: readonly Transport[] | undefined;
|
|
51
|
+
/** Agent configuration extracted at build time. */
|
|
52
|
+
config: AgentConfig;
|
|
53
|
+
/** Tool schemas extracted at build time. */
|
|
54
|
+
toolSchemas: ToolSchema[];
|
|
55
|
+
};
|
|
56
|
+
/** Environment variables required by the agent runtime. */
|
|
57
|
+
export type AgentEnv = {
|
|
58
|
+
ASSEMBLYAI_API_KEY: string;
|
|
59
|
+
[key: string]: string | undefined;
|
|
60
|
+
};
|
|
61
|
+
/** Configuration + tool schemas bundle returned by the worker's getConfig RPC. */
|
|
62
|
+
export type WorkerConfig = {
|
|
63
|
+
config: AgentConfig;
|
|
64
|
+
toolSchemas: ToolSchema[];
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Convert agent tool definitions to JSON Schema format for wire transport.
|
|
68
|
+
*
|
|
69
|
+
* Transforms the Zod-based `parameters` of each tool into a plain JSON Schema
|
|
70
|
+
* object suitable for structured clone / JSON serialization.
|
|
71
|
+
*/
|
|
72
|
+
export declare function agentToolsToSchemas(tools: Readonly<Record<string, ToolDef>>): ToolSchema[];
|
|
73
|
+
//# sourceMappingURL=_internal_types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_internal_types.d.ts","sourceRoot":"","sources":["../../sdk/_internal_types.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,GA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IT license.
|
|
2
|
+
/**
|
|
3
|
+
* Internal type definitions shared by server and CLI.
|
|
4
|
+
*
|
|
5
|
+
* Note: this module is for internal use only and should not be used directly.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
const EMPTY_PARAMS = z.object({});
|
|
11
|
+
/**
|
|
12
|
+
* Convert agent tool definitions to JSON Schema format for wire transport.
|
|
13
|
+
*
|
|
14
|
+
* Transforms the Zod-based `parameters` of each tool into a plain JSON Schema
|
|
15
|
+
* object suitable for structured clone / JSON serialization.
|
|
16
|
+
*/
|
|
17
|
+
export function agentToolsToSchemas(tools) {
|
|
18
|
+
return Object.entries(tools).map(([name, def]) => ({
|
|
19
|
+
name,
|
|
20
|
+
description: def.description,
|
|
21
|
+
parameters: z.toJSONSchema(def.parameters ?? EMPTY_PARAMS),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=_internal_types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_internal_types.js","sourceRoot":"","sources":["../../sdk/_internal_types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;;;;;;GAMG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgExB,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAElC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAwC;IAC1E,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QACjD,IAAI;QACJ,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,UAAU,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,IAAI,YAAY,CAAgB;KAC1E,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mock WebSocket implementation for testing.
|
|
3
|
+
*
|
|
4
|
+
* Extends `EventTarget` to simulate WebSocket behavior without a real
|
|
5
|
+
* network connection. Records all sent messages in the {@linkcode sent}
|
|
6
|
+
* array and provides helper methods to simulate incoming messages,
|
|
7
|
+
* connection events, and errors.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const ws = new MockWebSocket("wss://example.com");
|
|
12
|
+
* ws.send(JSON.stringify({ type: "ping" }));
|
|
13
|
+
* ws.simulateMessage(JSON.stringify({ type: "pong" }));
|
|
14
|
+
* assertEquals(ws.sentJson(), [{ type: "ping" }]);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class MockWebSocket extends EventTarget {
|
|
18
|
+
static readonly CONNECTING = 0;
|
|
19
|
+
static readonly OPEN = 1;
|
|
20
|
+
static readonly CLOSING = 2;
|
|
21
|
+
static readonly CLOSED = 3;
|
|
22
|
+
readyState: number;
|
|
23
|
+
binaryType: string;
|
|
24
|
+
/** All messages passed to {@linkcode send}, in order. */
|
|
25
|
+
sent: (string | ArrayBuffer | Uint8Array)[];
|
|
26
|
+
url: string;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new MockWebSocket.
|
|
29
|
+
*
|
|
30
|
+
* Automatically transitions to `OPEN` state on the next microtask,
|
|
31
|
+
* dispatching an `"open"` event.
|
|
32
|
+
*
|
|
33
|
+
* @param url - The WebSocket URL.
|
|
34
|
+
* @param _protocols - Ignored; accepted for API compatibility.
|
|
35
|
+
*/
|
|
36
|
+
constructor(url: string | URL, _protocols?: string | string[] | Record<string, unknown>);
|
|
37
|
+
/**
|
|
38
|
+
* Record a sent message without transmitting it.
|
|
39
|
+
*
|
|
40
|
+
* @param data - The message data to record.
|
|
41
|
+
*/
|
|
42
|
+
send(data: string | ArrayBuffer | Uint8Array): void;
|
|
43
|
+
/**
|
|
44
|
+
* Transition to `CLOSED` state and dispatch a `"close"` event.
|
|
45
|
+
*
|
|
46
|
+
* @param code - The close code (defaults to 1000).
|
|
47
|
+
* @param _reason - Ignored; accepted for API compatibility.
|
|
48
|
+
*/
|
|
49
|
+
close(code?: number, _reason?: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Simulate receiving a message from the server.
|
|
52
|
+
*
|
|
53
|
+
* @param data - The message data (string or binary).
|
|
54
|
+
*/
|
|
55
|
+
simulateMessage(data: string | ArrayBuffer): void;
|
|
56
|
+
/** Transition to `OPEN` state and dispatch an `"open"` event. */
|
|
57
|
+
open(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Shorthand for {@linkcode simulateMessage}.
|
|
60
|
+
*
|
|
61
|
+
* @param data - The message data to dispatch.
|
|
62
|
+
*/
|
|
63
|
+
msg(data: string | ArrayBuffer): void;
|
|
64
|
+
/**
|
|
65
|
+
* Simulate a connection close from the server.
|
|
66
|
+
*
|
|
67
|
+
* @param code - The close code (defaults to 1000).
|
|
68
|
+
*/
|
|
69
|
+
disconnect(code?: number): void;
|
|
70
|
+
/** Dispatch an `"error"` event on this socket. */
|
|
71
|
+
error(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Return all sent string messages parsed as JSON objects.
|
|
74
|
+
*
|
|
75
|
+
* Binary messages are filtered out.
|
|
76
|
+
*
|
|
77
|
+
* @returns An array of parsed JSON objects from sent string messages.
|
|
78
|
+
*/
|
|
79
|
+
sentJson(): Record<string, unknown>[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Replace `globalThis.WebSocket` with {@linkcode MockWebSocket} for testing.
|
|
83
|
+
*
|
|
84
|
+
* Returns a handle that tracks all created mock sockets and can restore the
|
|
85
|
+
* original `WebSocket` constructor. Supports the `using` declaration via
|
|
86
|
+
* `Symbol.dispose` for automatic cleanup.
|
|
87
|
+
*
|
|
88
|
+
* @returns An object with `created` array, `lastWs` getter, `restore()`, and `[Symbol.dispose]()`.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* using mock = installMockWebSocket();
|
|
93
|
+
* const session = new Session("wss://example.com");
|
|
94
|
+
* const ws = mock.lastWs!;
|
|
95
|
+
* ws.simulateMessage(JSON.stringify({ type: "ready" }));
|
|
96
|
+
* // mock automatically restores WebSocket when disposed
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function installMockWebSocket(): {
|
|
100
|
+
restore: () => void;
|
|
101
|
+
created: MockWebSocket[];
|
|
102
|
+
get lastWs(): MockWebSocket | null;
|
|
103
|
+
[Symbol.dispose]: () => void;
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=_mock_ws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_mock_ws.d.ts","sourceRoot":"","sources":["../../sdk/_mock_ws.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAE5C,MAAM,CAAC,QAAQ,CAAC,UAAU,KAAK;IAE/B,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK;IAEzB,MAAM,CAAC,QAAQ,CAAC,OAAO,KAAK;IAE5B,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK;IAE3B,UAAU,SAA4B;IACtC,UAAU,SAAiB;IAC3B,yDAAyD;IACzD,IAAI,EAAE,CAAC,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,EAAE,CAAM;IACjD,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;;;;;OAQG;gBACS,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAWvF;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU;IAI5C;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAKrC;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAI1C,iEAAiE;IACjE,IAAI;IAKJ;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAI9B;;;;OAIG;IACH,UAAU,CAAC,IAAI,SAAO;IAItB,kDAAkD;IAClD,KAAK;IAIL;;;;;;OAMG;IACH,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;CAGtC;AAID;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,IAAI;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,IAAI,MAAM,IAAI,aAAa,GAAG,IAAI,CAAC;IACnC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CAC9B,CAuBA"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* A mock WebSocket implementation for testing.
|
|
4
|
+
*
|
|
5
|
+
* Extends `EventTarget` to simulate WebSocket behavior without a real
|
|
6
|
+
* network connection. Records all sent messages in the {@linkcode sent}
|
|
7
|
+
* array and provides helper methods to simulate incoming messages,
|
|
8
|
+
* connection events, and errors.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const ws = new MockWebSocket("wss://example.com");
|
|
13
|
+
* ws.send(JSON.stringify({ type: "ping" }));
|
|
14
|
+
* ws.simulateMessage(JSON.stringify({ type: "pong" }));
|
|
15
|
+
* assertEquals(ws.sentJson(), [{ type: "ping" }]);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class MockWebSocket extends EventTarget {
|
|
19
|
+
// mirrors the WebSocket API
|
|
20
|
+
static CONNECTING = 0;
|
|
21
|
+
// mirrors the WebSocket API
|
|
22
|
+
static OPEN = 1;
|
|
23
|
+
// mirrors the WebSocket API
|
|
24
|
+
static CLOSING = 2;
|
|
25
|
+
// mirrors the WebSocket API
|
|
26
|
+
static CLOSED = 3;
|
|
27
|
+
readyState = MockWebSocket.CONNECTING;
|
|
28
|
+
binaryType = "arraybuffer";
|
|
29
|
+
/** All messages passed to {@linkcode send}, in order. */
|
|
30
|
+
sent = [];
|
|
31
|
+
url;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new MockWebSocket.
|
|
34
|
+
*
|
|
35
|
+
* Automatically transitions to `OPEN` state on the next microtask,
|
|
36
|
+
* dispatching an `"open"` event.
|
|
37
|
+
*
|
|
38
|
+
* @param url - The WebSocket URL.
|
|
39
|
+
* @param _protocols - Ignored; accepted for API compatibility.
|
|
40
|
+
*/
|
|
41
|
+
constructor(url, _protocols) {
|
|
42
|
+
super();
|
|
43
|
+
this.url = typeof url === "string" ? url : url.toString();
|
|
44
|
+
queueMicrotask(() => {
|
|
45
|
+
if (this.readyState === MockWebSocket.CONNECTING) {
|
|
46
|
+
this.readyState = MockWebSocket.OPEN;
|
|
47
|
+
this.dispatchEvent(new Event("open"));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Record a sent message without transmitting it.
|
|
53
|
+
*
|
|
54
|
+
* @param data - The message data to record.
|
|
55
|
+
*/
|
|
56
|
+
send(data) {
|
|
57
|
+
this.sent.push(data);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Transition to `CLOSED` state and dispatch a `"close"` event.
|
|
61
|
+
*
|
|
62
|
+
* @param code - The close code (defaults to 1000).
|
|
63
|
+
* @param _reason - Ignored; accepted for API compatibility.
|
|
64
|
+
*/
|
|
65
|
+
close(code, _reason) {
|
|
66
|
+
this.readyState = MockWebSocket.CLOSED;
|
|
67
|
+
this.dispatchEvent(new CloseEvent("close", { code: code ?? 1000 }));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Simulate receiving a message from the server.
|
|
71
|
+
*
|
|
72
|
+
* @param data - The message data (string or binary).
|
|
73
|
+
*/
|
|
74
|
+
simulateMessage(data) {
|
|
75
|
+
this.dispatchEvent(new MessageEvent("message", { data }));
|
|
76
|
+
}
|
|
77
|
+
/** Transition to `OPEN` state and dispatch an `"open"` event. */
|
|
78
|
+
open() {
|
|
79
|
+
this.readyState = MockWebSocket.OPEN;
|
|
80
|
+
this.dispatchEvent(new Event("open"));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Shorthand for {@linkcode simulateMessage}.
|
|
84
|
+
*
|
|
85
|
+
* @param data - The message data to dispatch.
|
|
86
|
+
*/
|
|
87
|
+
msg(data) {
|
|
88
|
+
this.dispatchEvent(new MessageEvent("message", { data }));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Simulate a connection close from the server.
|
|
92
|
+
*
|
|
93
|
+
* @param code - The close code (defaults to 1000).
|
|
94
|
+
*/
|
|
95
|
+
disconnect(code = 1000) {
|
|
96
|
+
this.dispatchEvent(new CloseEvent("close", { code }));
|
|
97
|
+
}
|
|
98
|
+
/** Dispatch an `"error"` event on this socket. */
|
|
99
|
+
error() {
|
|
100
|
+
this.dispatchEvent(new Event("error"));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Return all sent string messages parsed as JSON objects.
|
|
104
|
+
*
|
|
105
|
+
* Binary messages are filtered out.
|
|
106
|
+
*
|
|
107
|
+
* @returns An array of parsed JSON objects from sent string messages.
|
|
108
|
+
*/
|
|
109
|
+
sentJson() {
|
|
110
|
+
return this.sent.filter((d) => typeof d === "string").map((s) => JSON.parse(s));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const g = globalThis;
|
|
114
|
+
/**
|
|
115
|
+
* Replace `globalThis.WebSocket` with {@linkcode MockWebSocket} for testing.
|
|
116
|
+
*
|
|
117
|
+
* Returns a handle that tracks all created mock sockets and can restore the
|
|
118
|
+
* original `WebSocket` constructor. Supports the `using` declaration via
|
|
119
|
+
* `Symbol.dispose` for automatic cleanup.
|
|
120
|
+
*
|
|
121
|
+
* @returns An object with `created` array, `lastWs` getter, `restore()`, and `[Symbol.dispose]()`.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* using mock = installMockWebSocket();
|
|
126
|
+
* const session = new Session("wss://example.com");
|
|
127
|
+
* const ws = mock.lastWs!;
|
|
128
|
+
* ws.simulateMessage(JSON.stringify({ type: "ready" }));
|
|
129
|
+
* // mock automatically restores WebSocket when disposed
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function installMockWebSocket() {
|
|
133
|
+
const saved = globalThis.WebSocket;
|
|
134
|
+
const created = [];
|
|
135
|
+
g.WebSocket = class extends MockWebSocket {
|
|
136
|
+
constructor(url, protocols) {
|
|
137
|
+
super(url, protocols);
|
|
138
|
+
created.push(this);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
created,
|
|
143
|
+
get lastWs() {
|
|
144
|
+
return created.length > 0 ? created[created.length - 1] : null;
|
|
145
|
+
},
|
|
146
|
+
restore() {
|
|
147
|
+
globalThis.WebSocket = saved;
|
|
148
|
+
},
|
|
149
|
+
[Symbol.dispose]() {
|
|
150
|
+
globalThis.WebSocket = saved;
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=_mock_ws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_mock_ws.js","sourceRoot":"","sources":["../../sdk/_mock_ws.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,aAAc,SAAQ,WAAW;IAC5C,4BAA4B;IAC5B,MAAM,CAAU,UAAU,GAAG,CAAC,CAAC;IAC/B,4BAA4B;IAC5B,MAAM,CAAU,IAAI,GAAG,CAAC,CA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O;QACP,IAAI,MAAM;YACR,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAClE,CAAC;QACD,OAAO;YACL,UAAU,CAAC,SAAS,GAAG,KAAK,CAAC;QAC/B,CAAC;QACD,CAAC,MAAM,CAAC,OAAO,CAAC;YACd,UAAU,CAAC,SAAS,GAAG,KAAK,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeout wrapper for promises, used by both worker-side and host-side RPC.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Wrap a promise with a timeout. Rejects with `Error` if the promise
|
|
8
|
+
* does not settle within `timeoutMs` milliseconds.
|
|
9
|
+
*
|
|
10
|
+
* If `timeoutMs` is `undefined` or `0`, the original promise is returned
|
|
11
|
+
* unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs?: number): Promise<T>;
|
|
14
|
+
//# sourceMappingURL=_timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_timeout.d.ts","sourceRoot":"","sources":["../../sdk/_timeout.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAIH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAOlF"}
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import pTimeout from "p-timeout";
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Wrap a promise with a timeout. Rejects with `Error` if the promise
|
|
12
10
|
* does not settle within `timeoutMs` milliseconds.
|
|
@@ -14,11 +12,13 @@ import pTimeout from "p-timeout";
|
|
|
14
12
|
* If `timeoutMs` is `undefined` or `0`, the original promise is returned
|
|
15
13
|
* unchanged.
|
|
16
14
|
*/
|
|
17
|
-
export function withTimeout
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
export function withTimeout(promise, timeoutMs) {
|
|
16
|
+
const normalized = Promise.resolve(promise);
|
|
17
|
+
if (!timeoutMs)
|
|
18
|
+
return normalized;
|
|
19
|
+
return pTimeout(normalized, {
|
|
20
|
+
milliseconds: timeoutMs,
|
|
21
|
+
message: `RPC timed out after ${timeoutMs}ms`,
|
|
22
|
+
});
|
|
24
23
|
}
|
|
24
|
+
//# sourceMappingURL=_timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_timeout.js","sourceRoot":"","sources":["../../sdk/_timeout.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;;;;GAIG;AAEH,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAI,OAAmB,EAAE,SAAkB;IACpE,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,CAAC,SAAS;QAAE,OAAO,UAAU,CAAC;IAClC,OAAO,QAAQ,CAAC,UAAU,EAAE;QAC1B,YAAY,EAAE,SAAS;QACvB,OAAO,EAAE,uBAAuB,SAAS,IAAI;KAC9C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in tool definitions for the AAI agent SDK.
|
|
3
|
+
*
|
|
4
|
+
* These tools run inside the sandboxed worker alongside custom tools.
|
|
5
|
+
* Network requests go through the host's fetch proxy (with SSRF protection).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolSchema } from "./_internal_types.ts";
|
|
10
|
+
import type { ToolDef } from "./types.ts";
|
|
11
|
+
/** Callback for proxying vector search through the host RPC. */
|
|
12
|
+
export type VectorSearchFn = (query: string, topK: number) => Promise<string>;
|
|
13
|
+
/** Options for creating built-in tool definitions. */
|
|
14
|
+
export type BuiltinToolOptions = {
|
|
15
|
+
/** RPC callback for vector_search (proxied through host). */
|
|
16
|
+
vectorSearch?: VectorSearchFn;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Create built-in tool definitions for the given tool names.
|
|
20
|
+
*
|
|
21
|
+
* @param names - Built-in tool names from the agent config.
|
|
22
|
+
* @param opts - Options including RPC callbacks for host-proxied tools.
|
|
23
|
+
* @returns A record of tool name → ToolDef.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getBuiltinToolDefs(names: readonly string[], opts?: BuiltinToolOptions): Record<string, ToolDef>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns JSON tool schemas for the specified builtin tools.
|
|
28
|
+
*
|
|
29
|
+
* Used by both the worker (to report schemas) and the server (to
|
|
30
|
+
* assemble tool lists for the LLM).
|
|
31
|
+
*/
|
|
32
|
+
export declare function getBuiltinToolSchemas(names: readonly string[]): ToolSchema[];
|
|
33
|
+
//# sourceMappingURL=builtin_tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtin_tools.d.ts","sourceRoot":"","sources":["../../sdk/builtin_tools.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAgN1C,gEAAgE;AAChE,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAgB9E,sDAAsD;AACtD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6DAA6D;IAC7D,YAAY,CAAC,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,CAAC,EAAE,kBAAkB,GACxB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwBzB;AAYD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,EAAE,CAa5E"}
|