@signalwire/sdk 2.0.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/.github/workflows/publish.yml +27 -0
- package/.github/workflows/test.yml +17 -0
- package/CLAUDE.md +112 -0
- package/README.md +254 -0
- package/docs/MIGRATION-2.0.md +81 -0
- package/docs/agent-guide.md +869 -0
- package/docs/agent_guide.md +1026 -0
- package/docs/api-reference.md +2420 -0
- package/docs/api_reference.md +1301 -0
- package/docs/architecture.md +843 -0
- package/docs/cli-guide.md +579 -0
- package/docs/cli_guide.md +448 -0
- package/docs/cloud_functions_guide.md +474 -0
- package/docs/configuration.md +422 -0
- package/docs/contexts-guide.md +787 -0
- package/docs/contexts_guide.md +511 -0
- package/docs/datamap-guide.md +1141 -0
- package/docs/datamap_guide.md +595 -0
- package/docs/llm_parameters.md +239 -0
- package/docs/mcp_gateway_reference.md +648 -0
- package/docs/mcp_integration.md +108 -0
- package/docs/prefabs-guide.md +800 -0
- package/docs/sdk_features.md +477 -0
- package/docs/security.md +436 -0
- package/docs/serverless-guide.md +513 -0
- package/docs/skills-guide.md +857 -0
- package/docs/skills-system.md +301 -0
- package/docs/skills_parameter_schema.md +392 -0
- package/docs/skills_system.md +467 -0
- package/docs/swaig-reference.md +1627 -0
- package/docs/swaig_reference.md +910 -0
- package/docs/swml_service_guide.md +600 -0
- package/docs/third_party_skills.md +533 -0
- package/docs/web_service.md +677 -0
- package/examples/README.md +131 -0
- package/examples/advanced-datamap.ts +100 -0
- package/examples/advanced-dynamic-config.ts +70 -0
- package/examples/auto-vivified.ts +94 -0
- package/examples/call-flow.ts +63 -0
- package/examples/comprehensive-dynamic.ts +125 -0
- package/examples/contexts-steps.ts +65 -0
- package/examples/custom-path.ts +45 -0
- package/examples/datamap-tools.ts +55 -0
- package/examples/datasphere-multi-instance.ts +63 -0
- package/examples/datasphere-serverless-env.ts +68 -0
- package/examples/datasphere-webhook-env.ts +66 -0
- package/examples/datasphere.ts +37 -0
- package/examples/declarative.ts +100 -0
- package/examples/dynamic-config.ts +54 -0
- package/examples/dynamic-info-gatherer.ts +69 -0
- package/examples/dynamic-swml-service.ts +67 -0
- package/examples/gather-info.ts +71 -0
- package/examples/gather-per-question-functions-demo.ts +140 -0
- package/examples/joke-agent.ts +34 -0
- package/examples/kubernetes-agent.ts +45 -0
- package/examples/llm-params.ts +69 -0
- package/examples/mcp-agent.ts +84 -0
- package/examples/mcp-gateway.ts +35 -0
- package/examples/multi-agent.ts +73 -0
- package/examples/multi-endpoint.ts +79 -0
- package/examples/pom-prompt.ts +71 -0
- package/examples/prefab-concierge.ts +47 -0
- package/examples/prefab-faq.ts +54 -0
- package/examples/prefab-info-gatherer.ts +33 -0
- package/examples/prefab-receptionist.ts +36 -0
- package/examples/prefab-survey.ts +68 -0
- package/examples/record-call.ts +67 -0
- package/examples/relay-demo.ts +33 -0
- package/examples/room-and-sip.ts +94 -0
- package/examples/serverless-lambda.ts +35 -0
- package/examples/session-state.ts +83 -0
- package/examples/simple-agent.ts +36 -0
- package/examples/simple-static.ts +29 -0
- package/examples/skills-demo.ts +38 -0
- package/examples/step-function-inheritance-demo.ts +124 -0
- package/examples/swaig-features.ts +187 -0
- package/examples/swml-service-routing.ts +66 -0
- package/examples/swml-service.ts +38 -0
- package/examples/tap.ts +68 -0
- package/examples/verb-methods.ts +45 -0
- package/examples/web-search-multi-instance.ts +72 -0
- package/examples/web-search.ts +38 -0
- package/examples/wikipedia.ts +36 -0
- package/livewire/README.md +140 -0
- package/livewire/docs/migration-guide.md +228 -0
- package/livewire/examples/livewire-basic-agent.ts +74 -0
- package/livewire/examples/livewire-handoff.ts +197 -0
- package/livewire/examples/livewire-multi-tool.ts +117 -0
- package/package.json +38 -0
- package/relay/README.md +70 -0
- package/relay/RELAY_IMPLEMENTATION_GUIDE.md +1257 -0
- package/relay/docs/call-methods.md +474 -0
- package/relay/docs/client-reference.md +142 -0
- package/relay/docs/events.md +134 -0
- package/relay/docs/getting-started.md +134 -0
- package/relay/docs/guide.md +306 -0
- package/relay/docs/messaging.md +182 -0
- package/relay/examples/relay-inbound.ts +66 -0
- package/relay/examples/relay-messaging.ts +71 -0
- package/relay/examples/relay-outbound.ts +76 -0
- package/rest/README.md +95 -0
- package/rest/docs/calling.md +273 -0
- package/rest/docs/client-reference.md +107 -0
- package/rest/docs/compat.md +204 -0
- package/rest/docs/fabric.md +183 -0
- package/rest/docs/getting-started.md +110 -0
- package/rest/docs/guide.md +351 -0
- package/rest/docs/namespaces.md +285 -0
- package/rest/examples/rest-10dlc-registration.ts +161 -0
- package/rest/examples/rest-calling-ivr-and-ai.ts +102 -0
- package/rest/examples/rest-calling-play-and-record.ts +91 -0
- package/rest/examples/rest-client.ts +65 -0
- package/rest/examples/rest-compat-laml.ts +210 -0
- package/rest/examples/rest-datasphere-search.ts +82 -0
- package/rest/examples/rest-fabric-conferences-and-routing.ts +144 -0
- package/rest/examples/rest-fabric-subscribers-and-sip.ts +108 -0
- package/rest/examples/rest-fabric-swml-and-callflows.ts +99 -0
- package/rest/examples/rest-manage-resources.ts +65 -0
- package/rest/examples/rest-phone-number-management.ts +197 -0
- package/rest/examples/rest-queues-mfa-and-recordings.ts +143 -0
- package/rest/examples/rest-video-rooms.ts +186 -0
- package/src/AgentBase.ts +2489 -0
- package/src/AgentServer.ts +415 -0
- package/src/AuthHandler.ts +256 -0
- package/src/ConfigLoader.ts +447 -0
- package/src/ContextBuilder.ts +1150 -0
- package/src/DataMap.ts +449 -0
- package/src/FunctionResult.ts +866 -0
- package/src/Logger.ts +337 -0
- package/src/PomBuilder.ts +439 -0
- package/src/PromptManager.ts +133 -0
- package/src/SWMLHandler.ts +298 -0
- package/src/SWMLService.ts +717 -0
- package/src/SchemaUtils.ts +361 -0
- package/src/SecurityUtils.ts +153 -0
- package/src/ServerlessAdapter.ts +221 -0
- package/src/SessionManager.ts +311 -0
- package/src/SslConfig.ts +118 -0
- package/src/SwaigFunction.ts +276 -0
- package/src/SwmlBuilder.ts +258 -0
- package/src/SwmlVerbMethods.generated.ts +234 -0
- package/src/TypeInference.ts +181 -0
- package/src/WebService.ts +619 -0
- package/src/cli/agent-loader.ts +166 -0
- package/src/cli/mock-data.ts +111 -0
- package/src/cli/swaig-test.ts +452 -0
- package/src/generateVerbTypes.ts +322 -0
- package/src/index.ts +167 -0
- package/src/livewire/index.ts +950 -0
- package/src/prefabs/ConciergeAgent.ts +287 -0
- package/src/prefabs/FAQBotAgent.ts +384 -0
- package/src/prefabs/InfoGathererAgent.ts +339 -0
- package/src/prefabs/ReceptionistAgent.ts +366 -0
- package/src/prefabs/SurveyAgent.ts +646 -0
- package/src/prefabs/index.ts +27 -0
- package/src/relay/Action.ts +314 -0
- package/src/relay/Call.ts +854 -0
- package/src/relay/Deferred.ts +71 -0
- package/src/relay/Message.ts +148 -0
- package/src/relay/RelayClient.ts +1036 -0
- package/src/relay/RelayError.ts +14 -0
- package/src/relay/RelayEvent.ts +892 -0
- package/src/relay/constants.ts +132 -0
- package/src/relay/index.ts +123 -0
- package/src/relay/types.ts +149 -0
- package/src/rest/HttpClient.ts +103 -0
- package/src/rest/RestError.ts +31 -0
- package/src/rest/base/BaseResource.ts +19 -0
- package/src/rest/base/CrudResource.ts +51 -0
- package/src/rest/base/CrudWithAddresses.ts +26 -0
- package/src/rest/index.ts +200 -0
- package/src/rest/namespaces/addresses.ts +32 -0
- package/src/rest/namespaces/calling.ts +187 -0
- package/src/rest/namespaces/chat.ts +20 -0
- package/src/rest/namespaces/compat.ts +352 -0
- package/src/rest/namespaces/datasphere.ts +45 -0
- package/src/rest/namespaces/fabric.ts +222 -0
- package/src/rest/namespaces/imported-numbers.ts +20 -0
- package/src/rest/namespaces/logs.ts +84 -0
- package/src/rest/namespaces/lookup.ts +21 -0
- package/src/rest/namespaces/mfa.ts +30 -0
- package/src/rest/namespaces/number-groups.ts +38 -0
- package/src/rest/namespaces/phone-numbers.ts +44 -0
- package/src/rest/namespaces/project.ts +36 -0
- package/src/rest/namespaces/pubsub.ts +20 -0
- package/src/rest/namespaces/queues.ts +33 -0
- package/src/rest/namespaces/recordings.ts +28 -0
- package/src/rest/namespaces/registry.ts +101 -0
- package/src/rest/namespaces/short-codes.ts +28 -0
- package/src/rest/namespaces/sip-profile.ts +25 -0
- package/src/rest/namespaces/verified-callers.ts +27 -0
- package/src/rest/namespaces/video.ts +165 -0
- package/src/rest/pagination.ts +84 -0
- package/src/rest/types.ts +61 -0
- package/src/schema.json +12250 -0
- package/src/skills/SkillBase.ts +547 -0
- package/src/skills/SkillManager.ts +415 -0
- package/src/skills/SkillRegistry.ts +367 -0
- package/src/skills/builtin/api_ninjas_trivia.ts +280 -0
- package/src/skills/builtin/ask_claude.ts +241 -0
- package/src/skills/builtin/claude_skills.ts +978 -0
- package/src/skills/builtin/custom_skills.ts +312 -0
- package/src/skills/builtin/datasphere.ts +438 -0
- package/src/skills/builtin/datasphere_serverless.ts +339 -0
- package/src/skills/builtin/datetime.ts +130 -0
- package/src/skills/builtin/google_maps.ts +651 -0
- package/src/skills/builtin/index.ts +88 -0
- package/src/skills/builtin/info_gatherer.ts +405 -0
- package/src/skills/builtin/joke.ts +191 -0
- package/src/skills/builtin/math.ts +142 -0
- package/src/skills/builtin/mcp_gateway.ts +677 -0
- package/src/skills/builtin/native_vector_search.ts +901 -0
- package/src/skills/builtin/play_background_file.ts +358 -0
- package/src/skills/builtin/spider.ts +869 -0
- package/src/skills/builtin/swml_transfer.ts +635 -0
- package/src/skills/builtin/weather_api.ts +248 -0
- package/src/skills/builtin/web_search.ts +1074 -0
- package/src/skills/builtin/wikipedia_search.ts +299 -0
- package/src/skills/index.ts +12 -0
- package/src/types.ts +132 -0
- package/tests/AgentBase.test.ts +1093 -0
- package/tests/AgentServer.test.ts +126 -0
- package/tests/AuthHandler.test.ts +133 -0
- package/tests/ConfigLoader.test.ts +151 -0
- package/tests/ContextBuilder.test.ts +108 -0
- package/tests/DataMap.test.ts +367 -0
- package/tests/EphemeralSkillCopy.test.ts +107 -0
- package/tests/FunctionResult.test.ts +298 -0
- package/tests/GracefulShutdown.test.ts +46 -0
- package/tests/Logger.test.ts +420 -0
- package/tests/PomBuilder.test.ts +228 -0
- package/tests/ProxyDetection.test.ts +228 -0
- package/tests/SWMLService.test.ts +320 -0
- package/tests/SWMLVerbHandler.test.ts +523 -0
- package/tests/SchemaUtils.test.ts +106 -0
- package/tests/SchemaUtils.verb.test.ts +206 -0
- package/tests/SecurityUtils.test.ts +192 -0
- package/tests/ServerlessAdapter.test.ts +222 -0
- package/tests/SessionManager.test.ts +257 -0
- package/tests/SkillBaseFeatures.test.ts +130 -0
- package/tests/SkillMultiInstance.test.ts +102 -0
- package/tests/SkillParameterSchemas.test.ts +134 -0
- package/tests/SkillRegistrySchema.test.ts +84 -0
- package/tests/SslConfig.test.ts +97 -0
- package/tests/SwmlBuilder.test.ts +400 -0
- package/tests/TypeInference.test.ts +165 -0
- package/tests/VerbHandlerRegistry.test.ts +128 -0
- package/tests/cli/mock-data.test.ts +113 -0
- package/tests/cli/swaig-test.test.ts +108 -0
- package/tests/examples.test.ts +194 -0
- package/tests/fixtures/scrape-parity/README.md +53 -0
- package/tests/fixtures/scrape-parity/expected/01_simple_article.json +5 -0
- package/tests/fixtures/scrape-parity/expected/02_class_based_noise.json +5 -0
- package/tests/fixtures/scrape-parity/expected/03_nested_containers.json +5 -0
- package/tests/fixtures/scrape-parity/expected/04_bare_body.json +5 -0
- package/tests/fixtures/scrape-parity/expected/05_malformed.json +5 -0
- package/tests/fixtures/scrape-parity/expected/06_multi_class.json +5 -0
- package/tests/fixtures/scrape-parity/expected/07_anchor_pattern.json +5 -0
- package/tests/fixtures/scrape-parity/expected/08_inline_script.json +5 -0
- package/tests/fixtures/scrape-parity/expected/09_whitespace_nbsp.json +5 -0
- package/tests/fixtures/scrape-parity/expected/10_entity_unicode.json +5 -0
- package/tests/fixtures/scrape-parity/expected/11_cdata_comments.json +5 -0
- package/tests/fixtures/scrape-parity/expected/12_deep_nested_removals.json +5 -0
- package/tests/fixtures/scrape-parity/html/01_simple_article.html +18 -0
- package/tests/fixtures/scrape-parity/html/02_class_based_noise.html +18 -0
- package/tests/fixtures/scrape-parity/html/03_nested_containers.html +13 -0
- package/tests/fixtures/scrape-parity/html/04_bare_body.html +9 -0
- package/tests/fixtures/scrape-parity/html/05_malformed.html +11 -0
- package/tests/fixtures/scrape-parity/html/06_multi_class.html +18 -0
- package/tests/fixtures/scrape-parity/html/07_anchor_pattern.html +12 -0
- package/tests/fixtures/scrape-parity/html/08_inline_script.html +17 -0
- package/tests/fixtures/scrape-parity/html/09_whitespace_nbsp.html +21 -0
- package/tests/fixtures/scrape-parity/html/10_entity_unicode.html +10 -0
- package/tests/fixtures/scrape-parity/html/11_cdata_comments.html +13 -0
- package/tests/fixtures/scrape-parity/html/12_deep_nested_removals.html +24 -0
- package/tests/fixtures/scrape-parity/python_extract.py +109 -0
- package/tests/livewire/livewire.test.ts +780 -0
- package/tests/mcp.test.ts +221 -0
- package/tests/prefabs/prefabs.test.ts +1093 -0
- package/tests/relay/Action.test.ts +392 -0
- package/tests/relay/Call.test.ts +535 -0
- package/tests/relay/Deferred.test.ts +71 -0
- package/tests/relay/Message.test.ts +164 -0
- package/tests/relay/RelayClient.test.ts +779 -0
- package/tests/relay/RelayEvent.test.ts +463 -0
- package/tests/relay/helpers.ts +79 -0
- package/tests/rest/HttpClient.test.ts +274 -0
- package/tests/rest/RestError.test.ts +53 -0
- package/tests/rest/calling.test.ts +156 -0
- package/tests/rest/client.test.ts +197 -0
- package/tests/rest/compat.test.ts +335 -0
- package/tests/rest/datasphere.test.ts +71 -0
- package/tests/rest/fabric.test.ts +186 -0
- package/tests/rest/helpers.ts +95 -0
- package/tests/rest/logs.test.ts +68 -0
- package/tests/rest/pagination.test.ts +133 -0
- package/tests/rest/registry.test.ts +94 -0
- package/tests/rest/relay-rest.test.ts +290 -0
- package/tests/rest/video.test.ts +173 -0
- package/tests/setup.ts +6 -0
- package/tests/skills/SkillBase.test.ts +108 -0
- package/tests/skills/SkillManager.test.ts +268 -0
- package/tests/skills/SkillRegistry.test.ts +176 -0
- package/tests/skills/builtin.test.ts +1472 -0
- package/tests/skills/claude-skills.test.ts +54 -0
- package/tests/skills/custom-skills.test.ts +53 -0
- package/tests/skills/datasphere-serverless.test.ts +70 -0
- package/tests/skills/datasphere.test.ts +107 -0
- package/tests/skills/datetime.test.ts +101 -0
- package/tests/skills/google-maps.test.ts +78 -0
- package/tests/skills/info-gatherer.test.ts +411 -0
- package/tests/skills/joke.test.ts +81 -0
- package/tests/skills/math.test.ts +68 -0
- package/tests/skills/mcp-gateway.test.ts +101 -0
- package/tests/skills/play-background.test.ts +54 -0
- package/tests/skills/spider.test.ts +108 -0
- package/tests/skills/swml-transfer.test.ts +178 -0
- package/tests/skills/trivia.test.ts +54 -0
- package/tests/skills/vector-search.test.ts +135 -0
- package/tests/skills/weather-api.test.ts +77 -0
- package/tests/skills/web-search-parity.test.ts +59 -0
- package/tests/skills/web-search.test.ts +103 -0
- package/tests/skills/wikipedia.test.ts +63 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
Agent,
|
|
4
|
+
AgentSession,
|
|
5
|
+
ChatContext,
|
|
6
|
+
tool,
|
|
7
|
+
handoff,
|
|
8
|
+
RunContext,
|
|
9
|
+
defineAgent,
|
|
10
|
+
JobContext,
|
|
11
|
+
JobProcess,
|
|
12
|
+
WorkerOptions,
|
|
13
|
+
ServerOptions,
|
|
14
|
+
StopResponse,
|
|
15
|
+
ToolError,
|
|
16
|
+
AgentHandoff,
|
|
17
|
+
NoopTracker,
|
|
18
|
+
globalNoop,
|
|
19
|
+
plugins,
|
|
20
|
+
inference,
|
|
21
|
+
tips,
|
|
22
|
+
banner,
|
|
23
|
+
printBanner,
|
|
24
|
+
voice,
|
|
25
|
+
llm,
|
|
26
|
+
cli,
|
|
27
|
+
type FunctionTool,
|
|
28
|
+
} from '../../src/livewire/index.js';
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Agent
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
describe('Agent', () => {
|
|
35
|
+
it('creates with instructions and no tools', () => {
|
|
36
|
+
const agent = new Agent({ instructions: 'You are a helpful assistant.' });
|
|
37
|
+
expect(agent.instructions).toBe('You are a helpful assistant.');
|
|
38
|
+
expect(Object.keys(agent.tools)).toHaveLength(0);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('creates with instructions and tools', () => {
|
|
42
|
+
const myTool = tool({
|
|
43
|
+
description: 'Get weather',
|
|
44
|
+
execute: () => 'sunny',
|
|
45
|
+
});
|
|
46
|
+
const agent = new Agent({
|
|
47
|
+
instructions: 'Weather bot',
|
|
48
|
+
tools: [{ ...myTool, name: 'get_weather' }],
|
|
49
|
+
});
|
|
50
|
+
expect(agent.instructions).toBe('Weather bot');
|
|
51
|
+
expect(agent.tools['get_weather']).toBeDefined();
|
|
52
|
+
expect(agent.tools['get_weather'].description).toBe('Get weather');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('accepts userData generic', () => {
|
|
56
|
+
const agent = new Agent<{ sessionId: string }>({
|
|
57
|
+
instructions: 'test',
|
|
58
|
+
userData: { sessionId: 'abc' },
|
|
59
|
+
});
|
|
60
|
+
expect(agent.userData?.sessionId).toBe('abc');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// AgentSession
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
describe('AgentSession', () => {
|
|
69
|
+
it('creates with all options without throwing', () => {
|
|
70
|
+
const session = new AgentSession({
|
|
71
|
+
stt: 'deepgram',
|
|
72
|
+
tts: 'elevenlabs',
|
|
73
|
+
llm: 'openai/gpt-4',
|
|
74
|
+
vad: 'silero',
|
|
75
|
+
turnDetection: 'server_vad',
|
|
76
|
+
userData: { id: 1 },
|
|
77
|
+
});
|
|
78
|
+
expect(session).toBeDefined();
|
|
79
|
+
expect(session.userData).toEqual({ id: 1 });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('creates with no options', () => {
|
|
83
|
+
const session = new AgentSession();
|
|
84
|
+
expect(session).toBeDefined();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('start() binds agent to SignalWire AgentBase', async () => {
|
|
88
|
+
const session = new AgentSession({ llm: 'openai/gpt-4' });
|
|
89
|
+
const agent = new Agent({ instructions: 'Test instructions' });
|
|
90
|
+
await session.start({ agent });
|
|
91
|
+
const sw = session.getSwAgent();
|
|
92
|
+
expect(sw).toBeDefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('start() registers tools from agent', async () => {
|
|
96
|
+
const session = new AgentSession();
|
|
97
|
+
const weatherTool = tool({
|
|
98
|
+
description: 'Get weather',
|
|
99
|
+
parameters: {
|
|
100
|
+
type: 'object',
|
|
101
|
+
properties: {
|
|
102
|
+
location: { type: 'string', description: 'City name' },
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
execute: (params: any) => `Weather in ${params.location}: sunny`,
|
|
106
|
+
});
|
|
107
|
+
const agent = new Agent({
|
|
108
|
+
instructions: 'Weather assistant',
|
|
109
|
+
tools: [{ ...weatherTool, name: 'get_weather' }],
|
|
110
|
+
});
|
|
111
|
+
await session.start({ agent });
|
|
112
|
+
const sw = session.getSwAgent();
|
|
113
|
+
expect(sw).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('say() does not throw', async () => {
|
|
117
|
+
const session = new AgentSession();
|
|
118
|
+
const agent = new Agent({ instructions: 'test' });
|
|
119
|
+
await session.start({ agent });
|
|
120
|
+
expect(() => session.say('Hello there')).not.toThrow();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('generateReply() does not throw', async () => {
|
|
124
|
+
const session = new AgentSession();
|
|
125
|
+
const agent = new Agent({ instructions: 'test' });
|
|
126
|
+
await session.start({ agent });
|
|
127
|
+
expect(() => session.generateReply()).not.toThrow();
|
|
128
|
+
expect(() => session.generateReply({ instructions: 'Greet the user' })).not.toThrow();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('interrupt() is a noop that does not throw', () => {
|
|
132
|
+
const session = new AgentSession();
|
|
133
|
+
expect(() => session.interrupt()).not.toThrow();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('updateAgent() changes the bound agent', async () => {
|
|
137
|
+
const session = new AgentSession();
|
|
138
|
+
const agent1 = new Agent({ instructions: 'First agent' });
|
|
139
|
+
await session.start({ agent: agent1 });
|
|
140
|
+
|
|
141
|
+
const agent2 = new Agent({ instructions: 'Second agent' });
|
|
142
|
+
session.updateAgent(agent2);
|
|
143
|
+
// Should not throw -- internally updates the prompt
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('userData getter/setter works', () => {
|
|
147
|
+
const session = new AgentSession({ userData: { key: 'val' } });
|
|
148
|
+
expect(session.userData).toEqual({ key: 'val' });
|
|
149
|
+
session.userData = { key: 'updated' };
|
|
150
|
+
expect(session.userData).toEqual({ key: 'updated' });
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// tool()
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
describe('tool()', () => {
|
|
159
|
+
it('creates a valid tool definition', () => {
|
|
160
|
+
const t = tool({
|
|
161
|
+
description: 'Look up a word',
|
|
162
|
+
parameters: {
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
word: { type: 'string', description: 'The word to look up' },
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
execute: (params: any) => `Definition of ${params.word}`,
|
|
169
|
+
});
|
|
170
|
+
expect(t.description).toBe('Look up a word');
|
|
171
|
+
expect(t.parameters).toBeDefined();
|
|
172
|
+
expect(t.execute).toBeTypeOf('function');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('creates a tool without parameters', () => {
|
|
176
|
+
const t = tool({
|
|
177
|
+
description: 'Get time',
|
|
178
|
+
execute: () => '12:00 PM',
|
|
179
|
+
});
|
|
180
|
+
expect(t.description).toBe('Get time');
|
|
181
|
+
expect(t.parameters).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('execute function receives params and context', async () => {
|
|
185
|
+
const session = new AgentSession();
|
|
186
|
+
const ctx = new RunContext(session);
|
|
187
|
+
|
|
188
|
+
const t = tool({
|
|
189
|
+
description: 'test',
|
|
190
|
+
execute: (params: any, context: { ctx: RunContext }) => {
|
|
191
|
+
return `${params.name} via ${context.ctx.constructor.name}`;
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const result = t.execute({ name: 'Alice' }, { ctx });
|
|
196
|
+
expect(result).toBe('Alice via RunContext');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// handoff()
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
describe('handoff()', () => {
|
|
205
|
+
it('creates a handoff object', () => {
|
|
206
|
+
const agent = new Agent({ instructions: 'Sales agent' });
|
|
207
|
+
const h = handoff({ agent, returns: 'transfer_complete' });
|
|
208
|
+
expect(h).toBeInstanceOf(AgentHandoff);
|
|
209
|
+
expect(h.agent).toBe(agent);
|
|
210
|
+
expect(h.returns).toBe('transfer_complete');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('creates a handoff without returns', () => {
|
|
214
|
+
const agent = new Agent({ instructions: 'Support agent' });
|
|
215
|
+
const h = handoff({ agent });
|
|
216
|
+
expect(h.agent.instructions).toBe('Support agent');
|
|
217
|
+
expect(h.returns).toBeUndefined();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
// RunContext
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
|
|
225
|
+
describe('RunContext', () => {
|
|
226
|
+
it('has session and userData', () => {
|
|
227
|
+
const session = new AgentSession({ userData: { role: 'admin' } });
|
|
228
|
+
const ctx = new RunContext(session);
|
|
229
|
+
expect(ctx.session).toBe(session);
|
|
230
|
+
expect(ctx.userData).toEqual({ role: 'admin' });
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('userData reflects session userData changes', () => {
|
|
234
|
+
const session = new AgentSession({ userData: { count: 0 } });
|
|
235
|
+
const ctx = new RunContext(session);
|
|
236
|
+
expect(ctx.userData).toEqual({ count: 0 });
|
|
237
|
+
session.userData = { count: 5 };
|
|
238
|
+
expect(ctx.userData).toEqual({ count: 5 });
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
// defineAgent
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
describe('defineAgent()', () => {
|
|
247
|
+
it('accepts entry and prewarm', () => {
|
|
248
|
+
const def = defineAgent({
|
|
249
|
+
entry: async (ctx: JobContext) => {
|
|
250
|
+
await ctx.connect();
|
|
251
|
+
},
|
|
252
|
+
prewarm: (proc: JobProcess) => {
|
|
253
|
+
proc.userData['ready'] = true;
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
expect(def.entry).toBeTypeOf('function');
|
|
257
|
+
expect(def.prewarm).toBeTypeOf('function');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('accepts entry only', () => {
|
|
261
|
+
const def = defineAgent({
|
|
262
|
+
entry: async () => {},
|
|
263
|
+
});
|
|
264
|
+
expect(def.entry).toBeTypeOf('function');
|
|
265
|
+
expect(def.prewarm).toBeUndefined();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
// JobContext
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
|
|
273
|
+
describe('JobContext', () => {
|
|
274
|
+
it('connect() is a noop that resolves', async () => {
|
|
275
|
+
const ctx = new JobContext();
|
|
276
|
+
await expect(ctx.connect()).resolves.toBeUndefined();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('waitForParticipant() resolves', async () => {
|
|
280
|
+
const ctx = new JobContext();
|
|
281
|
+
const participant = await ctx.waitForParticipant();
|
|
282
|
+
expect(participant).toBeDefined();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('has room and proc', () => {
|
|
286
|
+
const ctx = new JobContext();
|
|
287
|
+
expect(ctx.room).toBeDefined();
|
|
288
|
+
expect(ctx.proc).toBeInstanceOf(JobProcess);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// ---------------------------------------------------------------------------
|
|
293
|
+
// JobProcess
|
|
294
|
+
// ---------------------------------------------------------------------------
|
|
295
|
+
|
|
296
|
+
describe('JobProcess', () => {
|
|
297
|
+
it('has userData map', () => {
|
|
298
|
+
const proc = new JobProcess();
|
|
299
|
+
expect(proc.userData).toEqual({});
|
|
300
|
+
proc.userData['key'] = 'value';
|
|
301
|
+
expect(proc.userData['key']).toBe('value');
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// ---------------------------------------------------------------------------
|
|
306
|
+
// Plugin stubs
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
|
|
309
|
+
describe('Plugin stubs', () => {
|
|
310
|
+
it('DeepgramSTT constructs without error', () => {
|
|
311
|
+
expect(() => new plugins.DeepgramSTT()).not.toThrow();
|
|
312
|
+
expect(() => new plugins.DeepgramSTT({ model: 'nova-2' })).not.toThrow();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('OpenAILLM constructs without error', () => {
|
|
316
|
+
expect(() => new plugins.OpenAILLM()).not.toThrow();
|
|
317
|
+
expect(() => new plugins.OpenAILLM({ model: 'gpt-4' })).not.toThrow();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('CartesiaTTS constructs without error', () => {
|
|
321
|
+
expect(() => new plugins.CartesiaTTS()).not.toThrow();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('ElevenLabsTTS constructs without error', () => {
|
|
325
|
+
expect(() => new plugins.ElevenLabsTTS()).not.toThrow();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('SileroVAD.load() returns instance', () => {
|
|
329
|
+
const vad = plugins.SileroVAD.load();
|
|
330
|
+
expect(vad).toBeInstanceOf(plugins.SileroVAD);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// ---------------------------------------------------------------------------
|
|
335
|
+
// Inference stubs
|
|
336
|
+
// ---------------------------------------------------------------------------
|
|
337
|
+
|
|
338
|
+
describe('Inference stubs', () => {
|
|
339
|
+
it('STT constructs without error', () => {
|
|
340
|
+
expect(() => new inference.STT('deepgram')).not.toThrow();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('LLM constructs without error', () => {
|
|
344
|
+
expect(() => new inference.LLM('gpt-4')).not.toThrow();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('TTS constructs without error', () => {
|
|
348
|
+
expect(() => new inference.TTS('elevenlabs')).not.toThrow();
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
// Noop logging
|
|
354
|
+
// ---------------------------------------------------------------------------
|
|
355
|
+
|
|
356
|
+
describe('Noop logging', () => {
|
|
357
|
+
it('fires once per feature key', () => {
|
|
358
|
+
const tracker = new NoopTracker();
|
|
359
|
+
tracker.once('stt', 'STT message');
|
|
360
|
+
tracker.once('stt', 'STT message again');
|
|
361
|
+
tracker.once('stt', 'STT message third');
|
|
362
|
+
|
|
363
|
+
expect(tracker.hasLogged('stt')).toBe(true);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('tracks different keys independently', () => {
|
|
367
|
+
const tracker = new NoopTracker();
|
|
368
|
+
tracker.once('stt', 'stt msg');
|
|
369
|
+
tracker.once('vad', 'vad msg');
|
|
370
|
+
|
|
371
|
+
expect(tracker.hasLogged('stt')).toBe(true);
|
|
372
|
+
expect(tracker.hasLogged('vad')).toBe(true);
|
|
373
|
+
expect(tracker.hasLogged('tts')).toBe(false);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// ---------------------------------------------------------------------------
|
|
378
|
+
// Tips
|
|
379
|
+
// ---------------------------------------------------------------------------
|
|
380
|
+
|
|
381
|
+
describe('Tips', () => {
|
|
382
|
+
it('has entries', () => {
|
|
383
|
+
expect(tips.length).toBeGreaterThan(0);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it('has at least 5 tips', () => {
|
|
387
|
+
expect(tips.length).toBeGreaterThanOrEqual(5);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('all tips are non-empty strings', () => {
|
|
391
|
+
for (const tip of tips) {
|
|
392
|
+
expect(typeof tip).toBe('string');
|
|
393
|
+
expect(tip.length).toBeGreaterThan(0);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// ---------------------------------------------------------------------------
|
|
399
|
+
// Banner
|
|
400
|
+
// ---------------------------------------------------------------------------
|
|
401
|
+
|
|
402
|
+
describe('Banner', () => {
|
|
403
|
+
it('contains LiveKit-compatible', () => {
|
|
404
|
+
expect(banner).toContain('LiveKit-compatible');
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('contains SignalWire', () => {
|
|
408
|
+
expect(banner).toContain('SignalWire');
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('contains ASCII art', () => {
|
|
412
|
+
expect(banner).toContain('/ / (_)');
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
// ---------------------------------------------------------------------------
|
|
417
|
+
// StopResponse / ToolError / AgentHandoff
|
|
418
|
+
// ---------------------------------------------------------------------------
|
|
419
|
+
|
|
420
|
+
describe('StopResponse', () => {
|
|
421
|
+
it('is an Error', () => {
|
|
422
|
+
const sr = new StopResponse();
|
|
423
|
+
expect(sr).toBeInstanceOf(Error);
|
|
424
|
+
expect(sr.name).toBe('StopResponse');
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
describe('ToolError', () => {
|
|
429
|
+
it('is an Error', () => {
|
|
430
|
+
const te = new ToolError('bad input');
|
|
431
|
+
expect(te).toBeInstanceOf(Error);
|
|
432
|
+
expect(te.name).toBe('ToolError');
|
|
433
|
+
expect(te.message).toBe('bad input');
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe('AgentHandoff', () => {
|
|
438
|
+
it('holds agent reference', () => {
|
|
439
|
+
const h = new AgentHandoff();
|
|
440
|
+
const agent = new Agent({ instructions: 'test' });
|
|
441
|
+
h.agent = agent;
|
|
442
|
+
expect(h.agent).toBe(agent);
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// ---------------------------------------------------------------------------
|
|
447
|
+
// WorkerOptions / ServerOptions
|
|
448
|
+
// ---------------------------------------------------------------------------
|
|
449
|
+
|
|
450
|
+
describe('WorkerOptions', () => {
|
|
451
|
+
it('constructs without error', () => {
|
|
452
|
+
expect(() => new WorkerOptions()).not.toThrow();
|
|
453
|
+
expect(() => new WorkerOptions({ port: 3000 })).not.toThrow();
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
describe('ServerOptions', () => {
|
|
458
|
+
it('constructs without error', () => {
|
|
459
|
+
expect(() => new ServerOptions()).not.toThrow();
|
|
460
|
+
expect(() => new ServerOptions({ host: '0.0.0.0' })).not.toThrow();
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// ---------------------------------------------------------------------------
|
|
465
|
+
// Namespace re-exports
|
|
466
|
+
// ---------------------------------------------------------------------------
|
|
467
|
+
|
|
468
|
+
describe('Namespace re-exports', () => {
|
|
469
|
+
it('voice namespace has Agent and AgentSession', () => {
|
|
470
|
+
expect(voice.Agent).toBe(Agent);
|
|
471
|
+
expect(voice.AgentSession).toBe(AgentSession);
|
|
472
|
+
expect(voice.AgentSessionEventTypes).toBeDefined();
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('llm namespace has tool, handoff, ToolError, ChatContext', () => {
|
|
476
|
+
expect(llm.tool).toBe(tool);
|
|
477
|
+
expect(llm.handoff).toBe(handoff);
|
|
478
|
+
expect(llm.ToolError).toBeDefined();
|
|
479
|
+
expect(llm.ChatContext).toBe(ChatContext);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it('cli namespace has runApp', () => {
|
|
483
|
+
expect(cli.runApp).toBeTypeOf('function');
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// ---------------------------------------------------------------------------
|
|
488
|
+
// Agent alignment gaps (P1 + P2 fixes)
|
|
489
|
+
// ---------------------------------------------------------------------------
|
|
490
|
+
|
|
491
|
+
describe('Agent alignment gaps', () => {
|
|
492
|
+
it('creates with no arguments (instructions defaults to empty string)', () => {
|
|
493
|
+
const agent = new Agent();
|
|
494
|
+
expect(agent.instructions).toBe('');
|
|
495
|
+
expect(Object.keys(agent.tools)).toHaveLength(0);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('instructions defaults to empty string when omitted', () => {
|
|
499
|
+
const agent = new Agent({});
|
|
500
|
+
expect(agent.instructions).toBe('');
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('accepts all Python-aligned constructor params', () => {
|
|
504
|
+
const agent = new Agent({
|
|
505
|
+
instructions: 'test',
|
|
506
|
+
chatCtx: { messages: [] },
|
|
507
|
+
stt: 'deepgram',
|
|
508
|
+
tts: 'elevenlabs',
|
|
509
|
+
llm: 'openai/gpt-4',
|
|
510
|
+
vad: 'silero',
|
|
511
|
+
turnDetection: 'server_vad',
|
|
512
|
+
mcpServers: ['server1'],
|
|
513
|
+
allowInterruptions: false,
|
|
514
|
+
minEndpointingDelay: 0.3,
|
|
515
|
+
maxEndpointingDelay: 5.0,
|
|
516
|
+
});
|
|
517
|
+
expect(agent.instructions).toBe('test');
|
|
518
|
+
expect(agent._llmHint).toBe('openai/gpt-4');
|
|
519
|
+
expect(agent._allowInterruptions).toBe(false);
|
|
520
|
+
expect(agent._minEndpointingDelay).toBe(0.3);
|
|
521
|
+
expect(agent._maxEndpointingDelay).toBe(5.0);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('has session property (get/set)', () => {
|
|
525
|
+
const agent = new Agent({ instructions: 'test' });
|
|
526
|
+
expect(agent.session).toBeUndefined();
|
|
527
|
+
const session = new AgentSession();
|
|
528
|
+
agent.session = session;
|
|
529
|
+
expect(agent.session).toBe(session);
|
|
530
|
+
agent.session = undefined;
|
|
531
|
+
expect(agent.session).toBeUndefined();
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it('onEnter lifecycle hook is overridable', async () => {
|
|
535
|
+
let called = false;
|
|
536
|
+
class MyAgent extends Agent {
|
|
537
|
+
override async onEnter(): Promise<void> {
|
|
538
|
+
called = true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const agent = new MyAgent({ instructions: 'test' });
|
|
542
|
+
await agent.onEnter();
|
|
543
|
+
expect(called).toBe(true);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it('onExit lifecycle hook is overridable', async () => {
|
|
547
|
+
let called = false;
|
|
548
|
+
class MyAgent extends Agent {
|
|
549
|
+
override async onExit(): Promise<void> {
|
|
550
|
+
called = true;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const agent = new MyAgent({ instructions: 'test' });
|
|
554
|
+
await agent.onExit();
|
|
555
|
+
expect(called).toBe(true);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it('onUserTurnCompleted lifecycle hook is overridable', async () => {
|
|
559
|
+
let receivedTurnCtx: unknown;
|
|
560
|
+
let receivedNewMessage: unknown;
|
|
561
|
+
class MyAgent extends Agent {
|
|
562
|
+
override async onUserTurnCompleted(turnCtx?: unknown, newMessage?: unknown): Promise<void> {
|
|
563
|
+
receivedTurnCtx = turnCtx;
|
|
564
|
+
receivedNewMessage = newMessage;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
const agent = new MyAgent({ instructions: 'test' });
|
|
568
|
+
await agent.onUserTurnCompleted('ctx', 'msg');
|
|
569
|
+
expect(receivedTurnCtx).toBe('ctx');
|
|
570
|
+
expect(receivedNewMessage).toBe('msg');
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it('sttNode is a noop that resolves', async () => {
|
|
574
|
+
const agent = new Agent({ instructions: 'test' });
|
|
575
|
+
await expect(agent.sttNode()).resolves.toBeUndefined();
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it('llmNode is a noop that resolves', async () => {
|
|
579
|
+
const agent = new Agent({ instructions: 'test' });
|
|
580
|
+
await expect(agent.llmNode()).resolves.toBeUndefined();
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it('ttsNode is a noop that resolves', async () => {
|
|
584
|
+
const agent = new Agent({ instructions: 'test' });
|
|
585
|
+
await expect(agent.ttsNode()).resolves.toBeUndefined();
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('updateInstructions changes instructions', async () => {
|
|
589
|
+
const agent = new Agent({ instructions: 'old' });
|
|
590
|
+
await agent.updateInstructions('new');
|
|
591
|
+
expect(agent.instructions).toBe('new');
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it('updateTools replaces tools record from array', async () => {
|
|
595
|
+
const t1 = { ...tool({ description: 'Tool 1', execute: () => 'a' }), name: 'tool1' };
|
|
596
|
+
const t2 = { ...tool({ description: 'Tool 2', execute: () => 'b' }), name: 'tool2' };
|
|
597
|
+
const agent = new Agent({ instructions: 'test' });
|
|
598
|
+
await agent.updateTools([t1, t2]);
|
|
599
|
+
expect(Object.keys(agent.tools)).toHaveLength(2);
|
|
600
|
+
expect(agent.tools['tool1'].description).toBe('Tool 1');
|
|
601
|
+
expect(agent.tools['tool2'].description).toBe('Tool 2');
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// ---------------------------------------------------------------------------
|
|
606
|
+
// AgentSession alignment gaps (P1 + P2 fixes)
|
|
607
|
+
// ---------------------------------------------------------------------------
|
|
608
|
+
|
|
609
|
+
describe('AgentSession alignment gaps', () => {
|
|
610
|
+
it('accepts all Python-aligned constructor params', () => {
|
|
611
|
+
const session = new AgentSession({
|
|
612
|
+
tools: [],
|
|
613
|
+
mcpServers: ['server1'],
|
|
614
|
+
allowInterruptions: false,
|
|
615
|
+
minInterruptionDuration: 1.0,
|
|
616
|
+
minEndpointingDelay: 0.3,
|
|
617
|
+
maxEndpointingDelay: 5.0,
|
|
618
|
+
maxToolSteps: 5,
|
|
619
|
+
preemptiveGeneration: true,
|
|
620
|
+
});
|
|
621
|
+
expect(session).toBeDefined();
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('has history property', () => {
|
|
625
|
+
const session = new AgentSession();
|
|
626
|
+
expect(session.history).toEqual([]);
|
|
627
|
+
expect(Array.isArray(session.history)).toBe(true);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
it('start() accepts record param', async () => {
|
|
631
|
+
const session = new AgentSession();
|
|
632
|
+
const agent = new Agent({ instructions: 'test' });
|
|
633
|
+
await session.start({ agent, record: true });
|
|
634
|
+
expect(session.getSwAgent()).toBeDefined();
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
it('start() sets agent.session back-reference', async () => {
|
|
638
|
+
const session = new AgentSession();
|
|
639
|
+
const agent = new Agent({ instructions: 'test' });
|
|
640
|
+
expect(agent.session).toBeUndefined();
|
|
641
|
+
await session.start({ agent });
|
|
642
|
+
expect(agent.session).toBe(session);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it('updateAgent() sets agent.session back-reference', async () => {
|
|
646
|
+
const session = new AgentSession();
|
|
647
|
+
const agent1 = new Agent({ instructions: 'First' });
|
|
648
|
+
await session.start({ agent: agent1 });
|
|
649
|
+
const agent2 = new Agent({ instructions: 'Second' });
|
|
650
|
+
session.updateAgent(agent2);
|
|
651
|
+
expect(agent2.session).toBe(session);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
it('session-level tools are registered alongside agent tools', async () => {
|
|
655
|
+
const sessionTool: FunctionTool = {
|
|
656
|
+
name: 'session_tool',
|
|
657
|
+
description: 'A session tool',
|
|
658
|
+
execute: () => 'ok',
|
|
659
|
+
};
|
|
660
|
+
const session = new AgentSession({ tools: [sessionTool] });
|
|
661
|
+
const agent = new Agent({ instructions: 'test' });
|
|
662
|
+
await session.start({ agent });
|
|
663
|
+
expect(session.getSwAgent()).toBeDefined();
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it('maps agent-level llm hint through start()', async () => {
|
|
667
|
+
const session = new AgentSession();
|
|
668
|
+
const agent = new Agent({ instructions: 'test', llm: 'openai/gpt-4o' });
|
|
669
|
+
await session.start({ agent });
|
|
670
|
+
// The swAgent should have been created and the model param set
|
|
671
|
+
expect(session.getSwAgent()).toBeDefined();
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
it('maps allowInterruptions=false to barge_confidence', async () => {
|
|
675
|
+
const session = new AgentSession({ allowInterruptions: false });
|
|
676
|
+
const agent = new Agent({ instructions: 'test' });
|
|
677
|
+
await session.start({ agent });
|
|
678
|
+
expect(session.getSwAgent()).toBeDefined();
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
// ---------------------------------------------------------------------------
|
|
683
|
+
// RunContext alignment gaps (P1 fixes)
|
|
684
|
+
// ---------------------------------------------------------------------------
|
|
685
|
+
|
|
686
|
+
describe('RunContext alignment gaps', () => {
|
|
687
|
+
it('accepts speechHandle and functionCall', () => {
|
|
688
|
+
const session = new AgentSession();
|
|
689
|
+
const ctx = new RunContext(session, {
|
|
690
|
+
speechHandle: 'handle-123',
|
|
691
|
+
functionCall: { name: 'test' },
|
|
692
|
+
});
|
|
693
|
+
expect(ctx.speechHandle).toBe('handle-123');
|
|
694
|
+
expect(ctx.functionCall).toEqual({ name: 'test' });
|
|
695
|
+
expect(ctx.session).toBe(session);
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it('speechHandle and functionCall default to undefined', () => {
|
|
699
|
+
const session = new AgentSession();
|
|
700
|
+
const ctx = new RunContext(session);
|
|
701
|
+
expect(ctx.speechHandle).toBeUndefined();
|
|
702
|
+
expect(ctx.functionCall).toBeUndefined();
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
// ---------------------------------------------------------------------------
|
|
707
|
+
// ChatContext alignment gaps (P1 fixes)
|
|
708
|
+
// ---------------------------------------------------------------------------
|
|
709
|
+
|
|
710
|
+
describe('ChatContext', () => {
|
|
711
|
+
it('has messages array', () => {
|
|
712
|
+
const ctx = new ChatContext();
|
|
713
|
+
expect(ctx.messages).toEqual([]);
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
it('append adds messages and returns this', () => {
|
|
717
|
+
const ctx = new ChatContext();
|
|
718
|
+
const result = ctx.append({ role: 'user', text: 'Hello' });
|
|
719
|
+
expect(result).toBe(ctx);
|
|
720
|
+
expect(ctx.messages).toHaveLength(1);
|
|
721
|
+
expect(ctx.messages[0]).toEqual({ role: 'user', content: 'Hello' });
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
it('append uses defaults (role=user, text=empty)', () => {
|
|
725
|
+
const ctx = new ChatContext();
|
|
726
|
+
ctx.append({});
|
|
727
|
+
expect(ctx.messages[0]).toEqual({ role: 'user', content: '' });
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
it('chains multiple appends', () => {
|
|
731
|
+
const ctx = new ChatContext();
|
|
732
|
+
ctx.append({ role: 'system', text: 'You are a bot' })
|
|
733
|
+
.append({ role: 'user', text: 'Hello' })
|
|
734
|
+
.append({ role: 'assistant', text: 'Hi there' });
|
|
735
|
+
expect(ctx.messages).toHaveLength(3);
|
|
736
|
+
expect(ctx.messages[0].role).toBe('system');
|
|
737
|
+
expect(ctx.messages[1].role).toBe('user');
|
|
738
|
+
expect(ctx.messages[2].role).toBe('assistant');
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it('is accessible via llm.ChatContext', () => {
|
|
742
|
+
const ctx = new llm.ChatContext();
|
|
743
|
+
ctx.append({ role: 'user', text: 'test' });
|
|
744
|
+
expect(ctx.messages).toHaveLength(1);
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// ---------------------------------------------------------------------------
|
|
749
|
+
// JobContext alignment gaps (P2 fixes)
|
|
750
|
+
// ---------------------------------------------------------------------------
|
|
751
|
+
|
|
752
|
+
describe('JobContext alignment gaps', () => {
|
|
753
|
+
it('waitForParticipant accepts identity option', async () => {
|
|
754
|
+
const ctx = new JobContext();
|
|
755
|
+
const participant = await ctx.waitForParticipant({ identity: 'user-42' });
|
|
756
|
+
expect(participant.identity).toBe('user-42');
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
it('waitForParticipant defaults identity to caller', async () => {
|
|
760
|
+
const ctx = new JobContext();
|
|
761
|
+
const participant = await ctx.waitForParticipant();
|
|
762
|
+
expect(participant.identity).toBe('caller');
|
|
763
|
+
});
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
// ---------------------------------------------------------------------------
|
|
767
|
+
// Plugin alignment gaps (P2 fixes)
|
|
768
|
+
// ---------------------------------------------------------------------------
|
|
769
|
+
|
|
770
|
+
describe('Plugin alignment gaps', () => {
|
|
771
|
+
it('OpenAILLM stores model property from opts', () => {
|
|
772
|
+
const llmPlugin = new plugins.OpenAILLM({ model: 'gpt-4' });
|
|
773
|
+
expect(llmPlugin.model).toBe('gpt-4');
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
it('OpenAILLM model defaults to empty string when not provided', () => {
|
|
777
|
+
const llmPlugin = new plugins.OpenAILLM();
|
|
778
|
+
expect(llmPlugin.model).toBe('');
|
|
779
|
+
});
|
|
780
|
+
});
|