signalwire-agents 0.1.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/CLAUDE.md +112 -0
- package/README.md +417 -0
- package/dist/AgentBase.d.ts +481 -0
- package/dist/AgentBase.js +1155 -0
- package/dist/AgentBase.js.map +1 -0
- package/dist/AgentServer.d.ts +60 -0
- package/dist/AgentServer.js +128 -0
- package/dist/AgentServer.js.map +1 -0
- package/dist/AuthHandler.d.ts +56 -0
- package/dist/AuthHandler.js +119 -0
- package/dist/AuthHandler.js.map +1 -0
- package/dist/ConfigLoader.d.ts +68 -0
- package/dist/ConfigLoader.js +150 -0
- package/dist/ConfigLoader.js.map +1 -0
- package/dist/ContextBuilder.d.ts +431 -0
- package/dist/ContextBuilder.js +751 -0
- package/dist/ContextBuilder.js.map +1 -0
- package/dist/DataMap.d.ts +179 -0
- package/dist/DataMap.js +321 -0
- package/dist/DataMap.js.map +1 -0
- package/dist/Logger.d.ts +91 -0
- package/dist/Logger.js +191 -0
- package/dist/Logger.js.map +1 -0
- package/dist/PomBuilder.d.ts +144 -0
- package/dist/PomBuilder.js +249 -0
- package/dist/PomBuilder.js.map +1 -0
- package/dist/PromptManager.d.ts +85 -0
- package/dist/PromptManager.js +108 -0
- package/dist/PromptManager.js.map +1 -0
- package/dist/SchemaUtils.d.ts +42 -0
- package/dist/SchemaUtils.js +148 -0
- package/dist/SchemaUtils.js.map +1 -0
- package/dist/ServerlessAdapter.d.ts +100 -0
- package/dist/ServerlessAdapter.js +166 -0
- package/dist/ServerlessAdapter.js.map +1 -0
- package/dist/SessionManager.d.ts +86 -0
- package/dist/SessionManager.js +155 -0
- package/dist/SessionManager.js.map +1 -0
- package/dist/SslConfig.d.ts +77 -0
- package/dist/SslConfig.js +100 -0
- package/dist/SslConfig.js.map +1 -0
- package/dist/SwaigFunction.d.ts +88 -0
- package/dist/SwaigFunction.js +125 -0
- package/dist/SwaigFunction.js.map +1 -0
- package/dist/SwaigFunctionResult.d.ts +442 -0
- package/dist/SwaigFunctionResult.js +735 -0
- package/dist/SwaigFunctionResult.js.map +1 -0
- package/dist/SwmlBuilder.d.ts +37 -0
- package/dist/SwmlBuilder.js +55 -0
- package/dist/SwmlBuilder.js.map +1 -0
- package/dist/cli/agent-loader.d.ts +22 -0
- package/dist/cli/agent-loader.js +106 -0
- package/dist/cli/agent-loader.js.map +1 -0
- package/dist/cli/mock-data.d.ts +37 -0
- package/dist/cli/mock-data.js +79 -0
- package/dist/cli/mock-data.js.map +1 -0
- package/dist/cli/swaig-test.d.ts +32 -0
- package/dist/cli/swaig-test.js +405 -0
- package/dist/cli/swaig-test.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/prefabs/ConciergeAgent.d.ts +64 -0
- package/dist/prefabs/ConciergeAgent.js +188 -0
- package/dist/prefabs/ConciergeAgent.js.map +1 -0
- package/dist/prefabs/FAQBotAgent.d.ts +68 -0
- package/dist/prefabs/FAQBotAgent.js +206 -0
- package/dist/prefabs/FAQBotAgent.js.map +1 -0
- package/dist/prefabs/InfoGathererAgent.d.ts +73 -0
- package/dist/prefabs/InfoGathererAgent.js +202 -0
- package/dist/prefabs/InfoGathererAgent.js.map +1 -0
- package/dist/prefabs/ReceptionistAgent.d.ts +65 -0
- package/dist/prefabs/ReceptionistAgent.js +205 -0
- package/dist/prefabs/ReceptionistAgent.js.map +1 -0
- package/dist/prefabs/SurveyAgent.d.ts +84 -0
- package/dist/prefabs/SurveyAgent.js +324 -0
- package/dist/prefabs/SurveyAgent.js.map +1 -0
- package/dist/prefabs/index.d.ts +13 -0
- package/dist/prefabs/index.js +14 -0
- package/dist/prefabs/index.js.map +1 -0
- package/dist/skills/SkillBase.d.ts +134 -0
- package/dist/skills/SkillBase.js +105 -0
- package/dist/skills/SkillBase.js.map +1 -0
- package/dist/skills/SkillManager.d.ts +83 -0
- package/dist/skills/SkillManager.js +159 -0
- package/dist/skills/SkillManager.js.map +1 -0
- package/dist/skills/SkillRegistry.d.ts +105 -0
- package/dist/skills/SkillRegistry.js +195 -0
- package/dist/skills/SkillRegistry.js.map +1 -0
- package/dist/skills/builtin/api_ninjas_trivia.d.ts +35 -0
- package/dist/skills/builtin/api_ninjas_trivia.js +161 -0
- package/dist/skills/builtin/api_ninjas_trivia.js.map +1 -0
- package/dist/skills/builtin/claude_skills.d.ts +34 -0
- package/dist/skills/builtin/claude_skills.js +156 -0
- package/dist/skills/builtin/claude_skills.js.map +1 -0
- package/dist/skills/builtin/custom_skills.d.ts +59 -0
- package/dist/skills/builtin/custom_skills.js +231 -0
- package/dist/skills/builtin/custom_skills.js.map +1 -0
- package/dist/skills/builtin/datasphere.d.ts +34 -0
- package/dist/skills/builtin/datasphere.js +163 -0
- package/dist/skills/builtin/datasphere.js.map +1 -0
- package/dist/skills/builtin/datasphere_serverless.d.ts +54 -0
- package/dist/skills/builtin/datasphere_serverless.js +155 -0
- package/dist/skills/builtin/datasphere_serverless.js.map +1 -0
- package/dist/skills/builtin/datetime.d.ts +31 -0
- package/dist/skills/builtin/datetime.js +95 -0
- package/dist/skills/builtin/datetime.js.map +1 -0
- package/dist/skills/builtin/google_maps.d.ts +33 -0
- package/dist/skills/builtin/google_maps.js +233 -0
- package/dist/skills/builtin/google_maps.js.map +1 -0
- package/dist/skills/builtin/index.d.ts +28 -0
- package/dist/skills/builtin/index.js +75 -0
- package/dist/skills/builtin/index.js.map +1 -0
- package/dist/skills/builtin/info_gatherer.d.ts +52 -0
- package/dist/skills/builtin/info_gatherer.js +237 -0
- package/dist/skills/builtin/info_gatherer.js.map +1 -0
- package/dist/skills/builtin/joke.d.ts +32 -0
- package/dist/skills/builtin/joke.js +142 -0
- package/dist/skills/builtin/joke.js.map +1 -0
- package/dist/skills/builtin/math.d.ts +33 -0
- package/dist/skills/builtin/math.js +120 -0
- package/dist/skills/builtin/math.js.map +1 -0
- package/dist/skills/builtin/mcp_gateway.d.ts +35 -0
- package/dist/skills/builtin/mcp_gateway.js +85 -0
- package/dist/skills/builtin/mcp_gateway.js.map +1 -0
- package/dist/skills/builtin/native_vector_search.d.ts +44 -0
- package/dist/skills/builtin/native_vector_search.js +248 -0
- package/dist/skills/builtin/native_vector_search.js.map +1 -0
- package/dist/skills/builtin/play_background_file.d.ts +34 -0
- package/dist/skills/builtin/play_background_file.js +135 -0
- package/dist/skills/builtin/play_background_file.js.map +1 -0
- package/dist/skills/builtin/spider.d.ts +34 -0
- package/dist/skills/builtin/spider.js +164 -0
- package/dist/skills/builtin/spider.js.map +1 -0
- package/dist/skills/builtin/swml_transfer.d.ts +44 -0
- package/dist/skills/builtin/swml_transfer.js +204 -0
- package/dist/skills/builtin/swml_transfer.js.map +1 -0
- package/dist/skills/builtin/weather_api.d.ts +34 -0
- package/dist/skills/builtin/weather_api.js +136 -0
- package/dist/skills/builtin/weather_api.js.map +1 -0
- package/dist/skills/builtin/web_search.d.ts +34 -0
- package/dist/skills/builtin/web_search.js +141 -0
- package/dist/skills/builtin/web_search.js.map +1 -0
- package/dist/skills/builtin/wikipedia_search.d.ts +34 -0
- package/dist/skills/builtin/wikipedia_search.js +166 -0
- package/dist/skills/builtin/wikipedia_search.js.map +1 -0
- package/dist/skills/index.d.ts +11 -0
- package/dist/skills/index.js +10 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/docs/agent-guide.md +869 -0
- package/docs/api-reference.md +2419 -0
- package/docs/architecture.md +843 -0
- package/docs/cli-guide.md +579 -0
- package/docs/configuration.md +422 -0
- package/docs/contexts-guide.md +787 -0
- package/docs/datamap-guide.md +1141 -0
- package/docs/prefabs-guide.md +830 -0
- package/docs/security.md +436 -0
- package/docs/serverless-guide.md +513 -0
- package/docs/skills-guide.md +845 -0
- package/docs/swaig-reference.md +1627 -0
- package/examples/call-flow.ts +60 -0
- package/examples/contexts-steps.ts +62 -0
- package/examples/datamap-tools.ts +52 -0
- package/examples/dynamic-config.ts +51 -0
- package/examples/multi-agent.ts +67 -0
- package/examples/pom-prompt.ts +68 -0
- package/examples/simple-agent.ts +33 -0
- package/package.json +35 -0
- package/src/AgentBase.ts +1279 -0
- package/src/AgentServer.ts +149 -0
- package/src/AuthHandler.ts +141 -0
- package/src/ConfigLoader.ts +165 -0
- package/src/ContextBuilder.ts +796 -0
- package/src/DataMap.ts +365 -0
- package/src/Logger.ts +197 -0
- package/src/PomBuilder.ts +298 -0
- package/src/PromptManager.ts +133 -0
- package/src/SchemaUtils.ts +170 -0
- package/src/ServerlessAdapter.ts +218 -0
- package/src/SessionManager.ts +161 -0
- package/src/SslConfig.ts +118 -0
- package/src/SwaigFunction.ts +168 -0
- package/src/SwaigFunctionResult.ts +864 -0
- package/src/SwmlBuilder.ts +62 -0
- package/src/cli/agent-loader.ts +122 -0
- package/src/cli/mock-data.ts +110 -0
- package/src/cli/swaig-test.ts +440 -0
- package/src/index.ts +99 -0
- package/src/prefabs/ConciergeAgent.ts +251 -0
- package/src/prefabs/FAQBotAgent.ts +263 -0
- package/src/prefabs/InfoGathererAgent.ts +276 -0
- package/src/prefabs/ReceptionistAgent.ts +277 -0
- package/src/prefabs/SurveyAgent.ts +413 -0
- package/src/prefabs/index.ts +23 -0
- package/src/skills/SkillBase.ts +184 -0
- package/src/skills/SkillManager.ts +177 -0
- package/src/skills/SkillRegistry.ts +231 -0
- package/src/skills/builtin/api_ninjas_trivia.ts +230 -0
- package/src/skills/builtin/claude_skills.ts +239 -0
- package/src/skills/builtin/custom_skills.ts +326 -0
- package/src/skills/builtin/datasphere.ts +225 -0
- package/src/skills/builtin/datasphere_serverless.ts +194 -0
- package/src/skills/builtin/datetime.ts +115 -0
- package/src/skills/builtin/google_maps.ts +347 -0
- package/src/skills/builtin/index.ts +79 -0
- package/src/skills/builtin/info_gatherer.ts +331 -0
- package/src/skills/builtin/joke.ts +180 -0
- package/src/skills/builtin/math.ts +150 -0
- package/src/skills/builtin/mcp_gateway.ts +99 -0
- package/src/skills/builtin/native_vector_search.ts +327 -0
- package/src/skills/builtin/play_background_file.ts +189 -0
- package/src/skills/builtin/spider.ts +232 -0
- package/src/skills/builtin/swml_transfer.ts +285 -0
- package/src/skills/builtin/weather_api.ts +193 -0
- package/src/skills/builtin/web_search.ts +212 -0
- package/src/skills/builtin/wikipedia_search.ts +248 -0
- package/src/skills/index.ts +12 -0
- package/src/types.ts +99 -0
- package/tests/AgentBase.test.ts +693 -0
- package/tests/AgentServer.test.ts +102 -0
- package/tests/AuthHandler.test.ts +121 -0
- package/tests/ConfigLoader.test.ts +121 -0
- package/tests/DataMap.test.ts +286 -0
- package/tests/Logger.test.ts +218 -0
- package/tests/PomBuilder.test.ts +164 -0
- package/tests/ProxyDetection.test.ts +185 -0
- package/tests/SchemaUtils.test.ts +106 -0
- package/tests/ServerlessAdapter.test.ts +200 -0
- package/tests/SessionManager.test.ts +139 -0
- package/tests/SslConfig.test.ts +97 -0
- package/tests/SwaigFunctionResult.test.ts +298 -0
- package/tests/cli/mock-data.test.ts +94 -0
- package/tests/cli/swaig-test.test.ts +96 -0
- package/tests/prefabs/prefabs.test.ts +854 -0
- package/tests/setup.ts +6 -0
- package/tests/skills/SkillBase.test.ts +118 -0
- package/tests/skills/SkillManager.test.ts +164 -0
- package/tests/skills/SkillRegistry.test.ts +124 -0
- package/tests/skills/builtin.test.ts +924 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Maps Skill - Provides directions and place search via Google Maps APIs.
|
|
3
|
+
*
|
|
4
|
+
* Tier 3 built-in skill: requires GOOGLE_MAPS_API_KEY environment variable.
|
|
5
|
+
* Uses Google Directions API for route information and Google Places API
|
|
6
|
+
* for place search and discovery.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { SkillBase } from '../SkillBase.js';
|
|
10
|
+
import type {
|
|
11
|
+
SkillManifest,
|
|
12
|
+
SkillToolDefinition,
|
|
13
|
+
SkillPromptSection,
|
|
14
|
+
SkillConfig,
|
|
15
|
+
} from '../SkillBase.js';
|
|
16
|
+
import { SwaigFunctionResult } from '../../SwaigFunctionResult.js';
|
|
17
|
+
|
|
18
|
+
/** A single leg of a route from the Google Directions API. */
|
|
19
|
+
interface DirectionsLeg {
|
|
20
|
+
distance: { text: string; value: number };
|
|
21
|
+
duration: { text: string; value: number };
|
|
22
|
+
start_address: string;
|
|
23
|
+
end_address: string;
|
|
24
|
+
steps: Array<{
|
|
25
|
+
html_instructions: string;
|
|
26
|
+
distance: { text: string };
|
|
27
|
+
duration: { text: string };
|
|
28
|
+
travel_mode: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A single route option from the Google Directions API response. */
|
|
33
|
+
interface DirectionsRoute {
|
|
34
|
+
summary: string;
|
|
35
|
+
legs: DirectionsLeg[];
|
|
36
|
+
warnings: string[];
|
|
37
|
+
copyrights: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Response shape from the Google Directions API. */
|
|
41
|
+
interface DirectionsResponse {
|
|
42
|
+
status: string;
|
|
43
|
+
routes: DirectionsRoute[];
|
|
44
|
+
error_message?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A place candidate result from the Google Places Find Place API. */
|
|
48
|
+
interface PlaceCandidate {
|
|
49
|
+
name: string;
|
|
50
|
+
formatted_address: string;
|
|
51
|
+
geometry?: { location: { lat: number; lng: number } };
|
|
52
|
+
rating?: number;
|
|
53
|
+
user_ratings_total?: number;
|
|
54
|
+
opening_hours?: { open_now: boolean };
|
|
55
|
+
business_status?: string;
|
|
56
|
+
types?: string[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Response shape from the Google Places Find Place API. */
|
|
60
|
+
interface PlacesResponse {
|
|
61
|
+
candidates: PlaceCandidate[];
|
|
62
|
+
status: string;
|
|
63
|
+
error_message?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Provides driving/walking/transit directions and place search via Google Maps APIs.
|
|
68
|
+
*
|
|
69
|
+
* Tier 3 built-in skill. Requires the `GOOGLE_MAPS_API_KEY` environment variable.
|
|
70
|
+
* Supports a `default_mode` config option ("driving"|"walking"|"bicycling"|"transit").
|
|
71
|
+
*/
|
|
72
|
+
export class GoogleMapsSkill extends SkillBase {
|
|
73
|
+
/**
|
|
74
|
+
* @param config - Optional configuration; supports `default_mode` for travel mode.
|
|
75
|
+
*/
|
|
76
|
+
constructor(config?: SkillConfig) {
|
|
77
|
+
super('google_maps', config);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @returns Manifest declaring GOOGLE_MAPS_API_KEY as required and config schema for default_mode. */
|
|
81
|
+
getManifest(): SkillManifest {
|
|
82
|
+
return {
|
|
83
|
+
name: 'google_maps',
|
|
84
|
+
description:
|
|
85
|
+
'Provides driving/walking/transit directions and place search via Google Maps APIs.',
|
|
86
|
+
version: '1.0.0',
|
|
87
|
+
author: 'SignalWire',
|
|
88
|
+
tags: ['maps', 'directions', 'places', 'google', 'navigation', 'external'],
|
|
89
|
+
requiredEnvVars: ['GOOGLE_MAPS_API_KEY'],
|
|
90
|
+
configSchema: {
|
|
91
|
+
default_mode: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description:
|
|
94
|
+
'Default travel mode: "driving", "walking", "bicycling", or "transit". Defaults to "driving".',
|
|
95
|
+
default: 'driving',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @returns Two tools: `get_directions` for route info and `find_place` for place discovery. */
|
|
102
|
+
getTools(): SkillToolDefinition[] {
|
|
103
|
+
const defaultMode = this.getConfig<string>('default_mode', 'driving');
|
|
104
|
+
|
|
105
|
+
return [
|
|
106
|
+
{
|
|
107
|
+
name: 'get_directions',
|
|
108
|
+
description:
|
|
109
|
+
'Get directions between two locations. Returns distance, duration, and step-by-step directions summary.',
|
|
110
|
+
parameters: {
|
|
111
|
+
origin: {
|
|
112
|
+
type: 'string',
|
|
113
|
+
description:
|
|
114
|
+
'Starting location (address, city name, or place name).',
|
|
115
|
+
},
|
|
116
|
+
destination: {
|
|
117
|
+
type: 'string',
|
|
118
|
+
description:
|
|
119
|
+
'Destination location (address, city name, or place name).',
|
|
120
|
+
},
|
|
121
|
+
mode: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
description:
|
|
124
|
+
`Travel mode: "driving", "walking", "bicycling", or "transit". Defaults to "${defaultMode}".`,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
required: ['origin', 'destination'],
|
|
128
|
+
handler: async (args: Record<string, unknown>) => {
|
|
129
|
+
const origin = args.origin as string | undefined;
|
|
130
|
+
const destination = args.destination as string | undefined;
|
|
131
|
+
const mode = (args.mode as string | undefined) ?? defaultMode;
|
|
132
|
+
|
|
133
|
+
if (!origin || typeof origin !== 'string' || origin.trim().length === 0) {
|
|
134
|
+
return new SwaigFunctionResult('Please provide a starting location (origin).');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!destination || typeof destination !== 'string' || destination.trim().length === 0) {
|
|
138
|
+
return new SwaigFunctionResult('Please provide a destination.');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const apiKey = process.env['GOOGLE_MAPS_API_KEY'];
|
|
142
|
+
if (!apiKey) {
|
|
143
|
+
return new SwaigFunctionResult(
|
|
144
|
+
'Google Maps is not configured. The GOOGLE_MAPS_API_KEY environment variable is required.',
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const validModes = ['driving', 'walking', 'bicycling', 'transit'];
|
|
149
|
+
const travelMode = validModes.includes(mode) ? mode : defaultMode;
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const url =
|
|
153
|
+
`https://maps.googleapis.com/maps/api/directions/json` +
|
|
154
|
+
`?origin=${encodeURIComponent(origin.trim())}` +
|
|
155
|
+
`&destination=${encodeURIComponent(destination.trim())}` +
|
|
156
|
+
`&mode=${travelMode}` +
|
|
157
|
+
`&key=${apiKey}`;
|
|
158
|
+
|
|
159
|
+
const response = await fetch(url);
|
|
160
|
+
const data = (await response.json()) as DirectionsResponse;
|
|
161
|
+
|
|
162
|
+
if (data.status !== 'OK') {
|
|
163
|
+
const errorMsg = data.error_message ?? data.status;
|
|
164
|
+
return new SwaigFunctionResult(
|
|
165
|
+
`Could not get directions from "${origin}" to "${destination}": ${errorMsg}`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (data.routes.length === 0) {
|
|
170
|
+
return new SwaigFunctionResult(
|
|
171
|
+
`No routes found from "${origin}" to "${destination}".`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const route = data.routes[0];
|
|
176
|
+
const leg = route.legs[0];
|
|
177
|
+
|
|
178
|
+
const parts: string[] = [
|
|
179
|
+
`Directions from ${leg.start_address} to ${leg.end_address}:`,
|
|
180
|
+
`Mode: ${travelMode}`,
|
|
181
|
+
`Distance: ${leg.distance.text}`,
|
|
182
|
+
`Estimated duration: ${leg.duration.text}`,
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
if (route.summary) {
|
|
186
|
+
parts.push(`Route: via ${route.summary}`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
parts.push('');
|
|
190
|
+
parts.push('Steps:');
|
|
191
|
+
|
|
192
|
+
const maxSteps = Math.min(leg.steps.length, 10);
|
|
193
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
194
|
+
const step = leg.steps[i];
|
|
195
|
+
const instruction = step.html_instructions
|
|
196
|
+
.replace(/<[^>]*>/g, '')
|
|
197
|
+
.replace(/ /g, ' ')
|
|
198
|
+
.trim();
|
|
199
|
+
parts.push(`${i + 1}. ${instruction} (${step.distance.text}, ${step.duration.text})`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (leg.steps.length > maxSteps) {
|
|
203
|
+
parts.push(`... and ${leg.steps.length - maxSteps} more steps.`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (route.warnings.length > 0) {
|
|
207
|
+
parts.push('');
|
|
208
|
+
parts.push(`Note: ${route.warnings.join(' ')}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return new SwaigFunctionResult(parts.join('\n'));
|
|
212
|
+
} catch (err) {
|
|
213
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
214
|
+
return new SwaigFunctionResult(
|
|
215
|
+
`Failed to get directions: ${message}`,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
name: 'find_place',
|
|
222
|
+
description:
|
|
223
|
+
'Search for a place by name or description. Returns the place name, address, rating, and whether it is currently open.',
|
|
224
|
+
parameters: {
|
|
225
|
+
query: {
|
|
226
|
+
type: 'string',
|
|
227
|
+
description:
|
|
228
|
+
'The place to search for (e.g., "pizza near Times Square", "Eiffel Tower", "pharmacy in Chicago").',
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
required: ['query'],
|
|
232
|
+
handler: async (args: Record<string, unknown>) => {
|
|
233
|
+
const query = args.query as string | undefined;
|
|
234
|
+
|
|
235
|
+
if (!query || typeof query !== 'string' || query.trim().length === 0) {
|
|
236
|
+
return new SwaigFunctionResult('Please provide a place to search for.');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const apiKey = process.env['GOOGLE_MAPS_API_KEY'];
|
|
240
|
+
if (!apiKey) {
|
|
241
|
+
return new SwaigFunctionResult(
|
|
242
|
+
'Google Maps is not configured. The GOOGLE_MAPS_API_KEY environment variable is required.',
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
const fields = 'name,formatted_address,geometry,rating,user_ratings_total,opening_hours,business_status,types';
|
|
248
|
+
const url =
|
|
249
|
+
`https://maps.googleapis.com/maps/api/place/findplacefromtext/json` +
|
|
250
|
+
`?input=${encodeURIComponent(query.trim())}` +
|
|
251
|
+
`&inputtype=textquery` +
|
|
252
|
+
`&fields=${fields}` +
|
|
253
|
+
`&key=${apiKey}`;
|
|
254
|
+
|
|
255
|
+
const response = await fetch(url);
|
|
256
|
+
const data = (await response.json()) as PlacesResponse;
|
|
257
|
+
|
|
258
|
+
if (data.status !== 'OK' && data.status !== 'ZERO_RESULTS') {
|
|
259
|
+
const errorMsg = data.error_message ?? data.status;
|
|
260
|
+
return new SwaigFunctionResult(
|
|
261
|
+
`Place search failed: ${errorMsg}`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!data.candidates || data.candidates.length === 0) {
|
|
266
|
+
return new SwaigFunctionResult(
|
|
267
|
+
`No places found for "${query}". Try a different search term.`,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const place = data.candidates[0];
|
|
272
|
+
const parts: string[] = [
|
|
273
|
+
`Place found: ${place.name}`,
|
|
274
|
+
`Address: ${place.formatted_address}`,
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
if (place.rating !== undefined) {
|
|
278
|
+
const ratingInfo = place.user_ratings_total
|
|
279
|
+
? `${place.rating}/5 (${place.user_ratings_total} reviews)`
|
|
280
|
+
: `${place.rating}/5`;
|
|
281
|
+
parts.push(`Rating: ${ratingInfo}`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (place.opening_hours?.open_now !== undefined) {
|
|
285
|
+
parts.push(`Currently open: ${place.opening_hours.open_now ? 'Yes' : 'No'}`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (place.business_status && place.business_status !== 'OPERATIONAL') {
|
|
289
|
+
parts.push(`Status: ${place.business_status.toLowerCase().replace(/_/g, ' ')}`);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (place.types && place.types.length > 0) {
|
|
293
|
+
const readableTypes = place.types
|
|
294
|
+
.filter((t) => !t.startsWith('point_of_interest') && !t.startsWith('establishment'))
|
|
295
|
+
.slice(0, 5)
|
|
296
|
+
.map((t) => t.replace(/_/g, ' '));
|
|
297
|
+
if (readableTypes.length > 0) {
|
|
298
|
+
parts.push(`Type: ${readableTypes.join(', ')}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (place.geometry?.location) {
|
|
303
|
+
const { lat, lng } = place.geometry.location;
|
|
304
|
+
parts.push(`Coordinates: ${lat}, ${lng}`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return new SwaigFunctionResult(parts.join('\n'));
|
|
308
|
+
} catch (err) {
|
|
309
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
310
|
+
return new SwaigFunctionResult(
|
|
311
|
+
`Failed to search for place "${query}": ${message}`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** @returns Prompt section describing directions and place search capabilities. */
|
|
320
|
+
getPromptSections(): SkillPromptSection[] {
|
|
321
|
+
const defaultMode = this.getConfig<string>('default_mode', 'driving');
|
|
322
|
+
|
|
323
|
+
return [
|
|
324
|
+
{
|
|
325
|
+
title: 'Google Maps & Directions',
|
|
326
|
+
body: 'You can look up directions between locations and search for places.',
|
|
327
|
+
bullets: [
|
|
328
|
+
'Use the get_directions tool to provide driving, walking, bicycling, or transit directions between two locations.',
|
|
329
|
+
`The default travel mode is ${defaultMode}. The user can request a different mode.`,
|
|
330
|
+
'Directions include total distance, estimated duration, and step-by-step navigation.',
|
|
331
|
+
'Use the find_place tool to search for businesses, landmarks, or any point of interest.',
|
|
332
|
+
'Place results include address, rating, and whether the place is currently open.',
|
|
333
|
+
'Summarize directions naturally rather than reading each step verbatim unless the user asks for details.',
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Factory function for creating GoogleMapsSkill instances.
|
|
342
|
+
* @param config - Optional skill configuration.
|
|
343
|
+
* @returns A new GoogleMapsSkill instance.
|
|
344
|
+
*/
|
|
345
|
+
export function createSkill(config?: SkillConfig): GoogleMapsSkill {
|
|
346
|
+
return new GoogleMapsSkill(config);
|
|
347
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in skills registry for SignalWire AI Agents.
|
|
3
|
+
*
|
|
4
|
+
* Import this module to register all built-in skills with the global SkillRegistry.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { DateTimeSkill, createSkill as createDateTimeSkill } from './datetime.js';
|
|
8
|
+
export { MathSkill, createSkill as createMathSkill } from './math.js';
|
|
9
|
+
export { JokeSkill, createSkill as createJokeSkill } from './joke.js';
|
|
10
|
+
export { WeatherApiSkill, createSkill as createWeatherApiSkill } from './weather_api.js';
|
|
11
|
+
export { PlayBackgroundFileSkill, createSkill as createPlayBackgroundFileSkill } from './play_background_file.js';
|
|
12
|
+
export { SwmlTransferSkill, createSkill as createSwmlTransferSkill } from './swml_transfer.js';
|
|
13
|
+
export { ApiNinjasTriviaSkill, createSkill as createApiNinjasTriviaSkill } from './api_ninjas_trivia.js';
|
|
14
|
+
export { InfoGathererSkill, createSkill as createInfoGathererSkill } from './info_gatherer.js';
|
|
15
|
+
export { CustomSkillsSkill, createSkill as createCustomSkillsSkill } from './custom_skills.js';
|
|
16
|
+
export { WebSearchSkill, createSkill as createWebSearchSkill } from './web_search.js';
|
|
17
|
+
export { WikipediaSearchSkill, createSkill as createWikipediaSearchSkill } from './wikipedia_search.js';
|
|
18
|
+
export { GoogleMapsSkill, createSkill as createGoogleMapsSkill } from './google_maps.js';
|
|
19
|
+
export { DataSphereSkill, createSkill as createDataSphereSkill } from './datasphere.js';
|
|
20
|
+
export { DataSphereServerlessSkill, createSkill as createDataSphereServerlessSkill } from './datasphere_serverless.js';
|
|
21
|
+
export { NativeVectorSearchSkill, createSkill as createNativeVectorSearchSkill } from './native_vector_search.js';
|
|
22
|
+
export { SpiderSkill, createSkill as createSpiderSkill } from './spider.js';
|
|
23
|
+
export { ClaudeSkill, createSkill as createClaudeSkill } from './claude_skills.js';
|
|
24
|
+
export { McpGatewaySkill, createSkill as createMcpGatewaySkill } from './mcp_gateway.js';
|
|
25
|
+
|
|
26
|
+
import { SkillRegistry } from '../SkillRegistry.js';
|
|
27
|
+
import { createSkill as createDateTimeSkill } from './datetime.js';
|
|
28
|
+
import { createSkill as createMathSkill } from './math.js';
|
|
29
|
+
import { createSkill as createJokeSkill } from './joke.js';
|
|
30
|
+
import { createSkill as createWeatherApiSkill } from './weather_api.js';
|
|
31
|
+
import { createSkill as createPlayBackgroundFileSkill } from './play_background_file.js';
|
|
32
|
+
import { createSkill as createSwmlTransferSkill } from './swml_transfer.js';
|
|
33
|
+
import { createSkill as createApiNinjasTriviaSkill } from './api_ninjas_trivia.js';
|
|
34
|
+
import { createSkill as createInfoGathererSkill } from './info_gatherer.js';
|
|
35
|
+
import { createSkill as createCustomSkillsSkill } from './custom_skills.js';
|
|
36
|
+
import { createSkill as createWebSearchSkill } from './web_search.js';
|
|
37
|
+
import { createSkill as createWikipediaSearchSkill } from './wikipedia_search.js';
|
|
38
|
+
import { createSkill as createGoogleMapsSkill } from './google_maps.js';
|
|
39
|
+
import { createSkill as createDataSphereSkill } from './datasphere.js';
|
|
40
|
+
import { createSkill as createDataSphereServerlessSkill } from './datasphere_serverless.js';
|
|
41
|
+
import { createSkill as createNativeVectorSearchSkill } from './native_vector_search.js';
|
|
42
|
+
import { createSkill as createSpiderSkill } from './spider.js';
|
|
43
|
+
import { createSkill as createClaudeSkill } from './claude_skills.js';
|
|
44
|
+
import { createSkill as createMcpGatewaySkill } from './mcp_gateway.js';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Register all 18 built-in skills with the global SkillRegistry singleton.
|
|
48
|
+
* Skips registration for any skill name already present in the registry.
|
|
49
|
+
*/
|
|
50
|
+
export function registerBuiltinSkills(): void {
|
|
51
|
+
const registry = SkillRegistry.getInstance();
|
|
52
|
+
|
|
53
|
+
const skills: [string, (config?: Record<string, unknown>) => any][] = [
|
|
54
|
+
['datetime', createDateTimeSkill],
|
|
55
|
+
['math', createMathSkill],
|
|
56
|
+
['joke', createJokeSkill],
|
|
57
|
+
['weather_api', createWeatherApiSkill],
|
|
58
|
+
['play_background_file', createPlayBackgroundFileSkill],
|
|
59
|
+
['swml_transfer', createSwmlTransferSkill],
|
|
60
|
+
['api_ninjas_trivia', createApiNinjasTriviaSkill],
|
|
61
|
+
['info_gatherer', createInfoGathererSkill],
|
|
62
|
+
['custom_skills', createCustomSkillsSkill],
|
|
63
|
+
['web_search', createWebSearchSkill],
|
|
64
|
+
['wikipedia_search', createWikipediaSearchSkill],
|
|
65
|
+
['google_maps', createGoogleMapsSkill],
|
|
66
|
+
['datasphere', createDataSphereSkill],
|
|
67
|
+
['datasphere_serverless', createDataSphereServerlessSkill],
|
|
68
|
+
['native_vector_search', createNativeVectorSearchSkill],
|
|
69
|
+
['spider', createSpiderSkill],
|
|
70
|
+
['claude_skills', createClaudeSkill],
|
|
71
|
+
['mcp_gateway', createMcpGatewaySkill],
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
for (const [name, factory] of skills) {
|
|
75
|
+
if (!registry.has(name)) {
|
|
76
|
+
registry.register(name, factory);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|