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,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DataSphere Skill - Searches SignalWire DataSphere for knowledge base content.
|
|
3
|
+
*
|
|
4
|
+
* Tier 3 built-in skill: requires SIGNALWIRE_PROJECT_ID, SIGNALWIRE_TOKEN,
|
|
5
|
+
* and SIGNALWIRE_SPACE environment variables. Uses the SignalWire DataSphere
|
|
6
|
+
* API to perform semantic search across uploaded documents.
|
|
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 search result from the DataSphere API. */
|
|
19
|
+
interface DataSphereResult {
|
|
20
|
+
/** Matched text chunk content. */
|
|
21
|
+
text: string;
|
|
22
|
+
/** Distance score (lower is more similar). */
|
|
23
|
+
score: number;
|
|
24
|
+
/** ID of the source document. */
|
|
25
|
+
document_id?: string;
|
|
26
|
+
/** Document metadata. */
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
/** Index of the chunk within the document. */
|
|
29
|
+
chunk_index?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Response shape from the SignalWire DataSphere search API. */
|
|
33
|
+
interface DataSphereResponse {
|
|
34
|
+
/** Array of search results. */
|
|
35
|
+
results?: DataSphereResult[];
|
|
36
|
+
/** Error message if the request failed. */
|
|
37
|
+
error?: string;
|
|
38
|
+
/** Additional error information. */
|
|
39
|
+
message?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Searches SignalWire DataSphere for knowledge base content using semantic search.
|
|
44
|
+
*
|
|
45
|
+
* Tier 3 built-in skill. Requires `SIGNALWIRE_PROJECT_ID`, `SIGNALWIRE_TOKEN`,
|
|
46
|
+
* and `SIGNALWIRE_SPACE` environment variables. Supports `max_results` and
|
|
47
|
+
* `distance_threshold` config options.
|
|
48
|
+
*/
|
|
49
|
+
export class DataSphereSkill extends SkillBase {
|
|
50
|
+
/**
|
|
51
|
+
* @param config - Optional configuration; supports `max_results` and `distance_threshold`.
|
|
52
|
+
*/
|
|
53
|
+
constructor(config?: SkillConfig) {
|
|
54
|
+
super('datasphere', config);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @returns Manifest declaring SignalWire credentials as required env vars. */
|
|
58
|
+
getManifest(): SkillManifest {
|
|
59
|
+
return {
|
|
60
|
+
name: 'datasphere',
|
|
61
|
+
description:
|
|
62
|
+
'Searches SignalWire DataSphere for knowledge base content using semantic search across uploaded documents.',
|
|
63
|
+
version: '1.0.0',
|
|
64
|
+
author: 'SignalWire',
|
|
65
|
+
tags: ['search', 'datasphere', 'signalwire', 'knowledge', 'rag', 'external'],
|
|
66
|
+
requiredEnvVars: ['SIGNALWIRE_PROJECT_ID', 'SIGNALWIRE_TOKEN', 'SIGNALWIRE_SPACE'],
|
|
67
|
+
configSchema: {
|
|
68
|
+
max_results: {
|
|
69
|
+
type: 'number',
|
|
70
|
+
description: 'Maximum number of results to return. Defaults to 5.',
|
|
71
|
+
default: 5,
|
|
72
|
+
},
|
|
73
|
+
distance_threshold: {
|
|
74
|
+
type: 'number',
|
|
75
|
+
description:
|
|
76
|
+
'Maximum distance threshold for results (0-1, lower is more similar). Defaults to 0.7.',
|
|
77
|
+
default: 0.7,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @returns A single `search_datasphere` tool that performs semantic search on uploaded documents. */
|
|
84
|
+
getTools(): SkillToolDefinition[] {
|
|
85
|
+
const maxResults = this.getConfig<number>('max_results', 5);
|
|
86
|
+
const distanceThreshold = this.getConfig<number>('distance_threshold', 0.7);
|
|
87
|
+
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
name: 'search_datasphere',
|
|
91
|
+
description:
|
|
92
|
+
'Search the SignalWire DataSphere knowledge base for relevant information. Returns the most relevant text chunks from uploaded documents.',
|
|
93
|
+
parameters: {
|
|
94
|
+
query: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
description: 'The question or topic to search for in the knowledge base.',
|
|
97
|
+
},
|
|
98
|
+
document_id: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
description:
|
|
101
|
+
'Optional: limit search to a specific document by its ID.',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
required: ['query'],
|
|
105
|
+
handler: async (args: Record<string, unknown>) => {
|
|
106
|
+
const query = args.query as string | undefined;
|
|
107
|
+
const documentId = args.document_id as string | undefined;
|
|
108
|
+
|
|
109
|
+
if (!query || typeof query !== 'string' || query.trim().length === 0) {
|
|
110
|
+
return new SwaigFunctionResult(
|
|
111
|
+
'Please provide a query to search the knowledge base.',
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const projectId = process.env['SIGNALWIRE_PROJECT_ID'];
|
|
116
|
+
const token = process.env['SIGNALWIRE_TOKEN'];
|
|
117
|
+
const space = process.env['SIGNALWIRE_SPACE'];
|
|
118
|
+
|
|
119
|
+
if (!projectId || !token || !space) {
|
|
120
|
+
return new SwaigFunctionResult(
|
|
121
|
+
'DataSphere is not configured. The SIGNALWIRE_PROJECT_ID, SIGNALWIRE_TOKEN, and SIGNALWIRE_SPACE environment variables are required.',
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const spaceHost = space.includes('.') ? space : `${space}.signalwire.com`;
|
|
127
|
+
const url = `https://${spaceHost}/api/datasphere/documents/search`;
|
|
128
|
+
|
|
129
|
+
const requestBody: Record<string, unknown> = {
|
|
130
|
+
query: query.trim(),
|
|
131
|
+
count: maxResults,
|
|
132
|
+
distance: distanceThreshold,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (documentId && typeof documentId === 'string' && documentId.trim().length > 0) {
|
|
136
|
+
requestBody['document_id'] = documentId.trim();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const authHeader = Buffer.from(`${projectId}:${token}`).toString('base64');
|
|
140
|
+
|
|
141
|
+
const response = await fetch(url, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: {
|
|
144
|
+
'Content-Type': 'application/json',
|
|
145
|
+
'Authorization': `Basic ${authHeader}`,
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify(requestBody),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
const errorText = await response.text();
|
|
152
|
+
let errorMsg: string;
|
|
153
|
+
try {
|
|
154
|
+
const errorData = JSON.parse(errorText) as DataSphereResponse;
|
|
155
|
+
errorMsg = errorData.error ?? errorData.message ?? `HTTP ${response.status}`;
|
|
156
|
+
} catch {
|
|
157
|
+
errorMsg = `HTTP ${response.status}: ${errorText.slice(0, 200)}`;
|
|
158
|
+
}
|
|
159
|
+
return new SwaigFunctionResult(
|
|
160
|
+
`DataSphere search failed: ${errorMsg}`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const data = (await response.json()) as DataSphereResponse;
|
|
165
|
+
|
|
166
|
+
if (!data.results || data.results.length === 0) {
|
|
167
|
+
return new SwaigFunctionResult(
|
|
168
|
+
`No relevant results found in the knowledge base for "${query}".`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const parts: string[] = [
|
|
173
|
+
`Knowledge base results for "${query}" (${data.results.length} results):`,
|
|
174
|
+
'',
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
for (let i = 0; i < data.results.length; i++) {
|
|
178
|
+
const result = data.results[i];
|
|
179
|
+
const score = (1 - result.score).toFixed(2);
|
|
180
|
+
parts.push(`--- Result ${i + 1} (relevance: ${score}) ---`);
|
|
181
|
+
parts.push(result.text.trim());
|
|
182
|
+
if (result.document_id) {
|
|
183
|
+
parts.push(`[Document: ${result.document_id}]`);
|
|
184
|
+
}
|
|
185
|
+
parts.push('');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return new SwaigFunctionResult(parts.join('\n').trim());
|
|
189
|
+
} catch (err) {
|
|
190
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
191
|
+
return new SwaigFunctionResult(
|
|
192
|
+
`Failed to search DataSphere for "${query}": ${message}`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @returns Prompt section describing DataSphere knowledge base search capabilities. */
|
|
201
|
+
getPromptSections(): SkillPromptSection[] {
|
|
202
|
+
return [
|
|
203
|
+
{
|
|
204
|
+
title: 'Knowledge Base Search (DataSphere)',
|
|
205
|
+
body: 'You have access to a knowledge base of documents that can be searched for relevant information.',
|
|
206
|
+
bullets: [
|
|
207
|
+
'Use the search_datasphere tool when the user asks questions that might be answered by internal documentation or uploaded knowledge.',
|
|
208
|
+
'Results are ranked by relevance. Higher relevance scores indicate better matches.',
|
|
209
|
+
'You can optionally search within a specific document by providing its ID.',
|
|
210
|
+
'Synthesize information from multiple results when appropriate.',
|
|
211
|
+
'If no results are found, let the user know and suggest rephrasing their question.',
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Factory function for creating DataSphereSkill instances.
|
|
220
|
+
* @param config - Optional skill configuration.
|
|
221
|
+
* @returns A new DataSphereSkill instance.
|
|
222
|
+
*/
|
|
223
|
+
export function createSkill(config?: SkillConfig): DataSphereSkill {
|
|
224
|
+
return new DataSphereSkill(config);
|
|
225
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DataSphere Serverless Skill - Searches SignalWire DataSphere using a DataMap.
|
|
3
|
+
*
|
|
4
|
+
* Tier 3 built-in skill: requires SIGNALWIRE_PROJECT_ID, SIGNALWIRE_TOKEN,
|
|
5
|
+
* and SIGNALWIRE_SPACE environment variables. Unlike the standard datasphere
|
|
6
|
+
* skill, this uses a DataMap to execute the search server-side without
|
|
7
|
+
* requiring a webhook endpoint. Ideal for serverless or edge deployments.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { SkillBase } from '../SkillBase.js';
|
|
11
|
+
import type {
|
|
12
|
+
SkillManifest,
|
|
13
|
+
SkillToolDefinition,
|
|
14
|
+
SkillPromptSection,
|
|
15
|
+
SkillConfig,
|
|
16
|
+
} from '../SkillBase.js';
|
|
17
|
+
import { SwaigFunctionResult } from '../../SwaigFunctionResult.js';
|
|
18
|
+
import { DataMap } from '../../DataMap.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Searches SignalWire DataSphere using a server-side DataMap for serverless execution.
|
|
22
|
+
*
|
|
23
|
+
* Tier 3 built-in skill. Requires `SIGNALWIRE_PROJECT_ID`, `SIGNALWIRE_TOKEN`,
|
|
24
|
+
* and `SIGNALWIRE_SPACE` environment variables. Unlike the standard DataSphere
|
|
25
|
+
* skill, this generates a DataMap configuration that SignalWire executes directly
|
|
26
|
+
* without needing a webhook endpoint. Supports `max_results`, `distance_threshold`,
|
|
27
|
+
* and `document_id` config options.
|
|
28
|
+
*/
|
|
29
|
+
export class DataSphereServerlessSkill extends SkillBase {
|
|
30
|
+
/**
|
|
31
|
+
* @param config - Optional configuration; supports `max_results`, `distance_threshold`, `document_id`.
|
|
32
|
+
*/
|
|
33
|
+
constructor(config?: SkillConfig) {
|
|
34
|
+
super('datasphere_serverless', config);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @returns Manifest declaring SignalWire credentials as required env vars. */
|
|
38
|
+
getManifest(): SkillManifest {
|
|
39
|
+
return {
|
|
40
|
+
name: 'datasphere_serverless',
|
|
41
|
+
description:
|
|
42
|
+
'Searches SignalWire DataSphere using a server-side DataMap. No webhook endpoint required; executes entirely on the SignalWire platform.',
|
|
43
|
+
version: '1.0.0',
|
|
44
|
+
author: 'SignalWire',
|
|
45
|
+
tags: ['search', 'datasphere', 'signalwire', 'knowledge', 'rag', 'serverless', 'datamap'],
|
|
46
|
+
requiredEnvVars: ['SIGNALWIRE_PROJECT_ID', 'SIGNALWIRE_TOKEN', 'SIGNALWIRE_SPACE'],
|
|
47
|
+
configSchema: {
|
|
48
|
+
max_results: {
|
|
49
|
+
type: 'number',
|
|
50
|
+
description: 'Maximum number of results to return. Defaults to 5.',
|
|
51
|
+
default: 5,
|
|
52
|
+
},
|
|
53
|
+
distance_threshold: {
|
|
54
|
+
type: 'number',
|
|
55
|
+
description:
|
|
56
|
+
'Maximum distance threshold for results (0-1, lower is more similar). Defaults to 0.7.',
|
|
57
|
+
default: 0.7,
|
|
58
|
+
},
|
|
59
|
+
document_id: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
description: 'Optional: restrict search to a specific document ID.',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build the DataMap-based SWAIG function definition for server-side
|
|
69
|
+
* DataSphere search. This generates a data_map configuration that
|
|
70
|
+
* SignalWire executes directly, without needing a webhook callback.
|
|
71
|
+
*/
|
|
72
|
+
private buildDataMapFunction(): Record<string, unknown> {
|
|
73
|
+
const maxResults = this.getConfig<number>('max_results', 5);
|
|
74
|
+
const distanceThreshold = this.getConfig<number>('distance_threshold', 0.7);
|
|
75
|
+
const documentId = this.getConfig<string | undefined>('document_id', undefined);
|
|
76
|
+
|
|
77
|
+
const dm = new DataMap('search_datasphere');
|
|
78
|
+
dm.enableEnvExpansion(true);
|
|
79
|
+
|
|
80
|
+
dm.purpose(
|
|
81
|
+
'Search the SignalWire DataSphere knowledge base for relevant information. ' +
|
|
82
|
+
'Returns the most relevant text chunks from uploaded documents.',
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
dm.parameter('query', 'string', 'The question or topic to search for in the knowledge base.', {
|
|
86
|
+
required: true,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Build the request body
|
|
90
|
+
const requestBody: Record<string, unknown> = {
|
|
91
|
+
query: '%{args.query}',
|
|
92
|
+
count: maxResults,
|
|
93
|
+
distance: distanceThreshold,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (documentId) {
|
|
97
|
+
requestBody['document_id'] = documentId;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Configure the webhook to call the DataSphere API
|
|
101
|
+
dm.webhook('POST', 'https://${ENV.SIGNALWIRE_SPACE}.signalwire.com/api/datasphere/documents/search', {
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
'Authorization': 'Basic ${ENV.SIGNALWIRE_AUTH}',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
dm.body(requestBody);
|
|
109
|
+
|
|
110
|
+
dm.output(
|
|
111
|
+
new SwaigFunctionResult(
|
|
112
|
+
'Knowledge base results for the query: %{array[0].text} %{array[1].text} %{array[2].text}',
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
dm.errorKeys(['error', 'message']);
|
|
117
|
+
|
|
118
|
+
dm.fallbackOutput(
|
|
119
|
+
new SwaigFunctionResult(
|
|
120
|
+
'No relevant results found in the knowledge base. Try rephrasing your question.',
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return dm.toSwaigFunction();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Return a stub tool definition since this skill uses DataMap-based execution.
|
|
129
|
+
* The actual DataMap function is provided by getDataMapTools().
|
|
130
|
+
* @returns A single stub `search_datasphere` tool that explains its DataMap nature.
|
|
131
|
+
*/
|
|
132
|
+
getTools(): SkillToolDefinition[] {
|
|
133
|
+
// DataMap-based skills do not use handler-based tools.
|
|
134
|
+
// The tool is provided via getDataMapTools() instead.
|
|
135
|
+
// We return a stub handler that explains this to prevent confusion
|
|
136
|
+
// if something tries to invoke it as a regular tool.
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
name: 'search_datasphere',
|
|
140
|
+
description:
|
|
141
|
+
'Search the SignalWire DataSphere knowledge base for relevant information. (Serverless DataMap mode)',
|
|
142
|
+
parameters: {
|
|
143
|
+
query: {
|
|
144
|
+
type: 'string',
|
|
145
|
+
description: 'The question or topic to search for in the knowledge base.',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
required: ['query'],
|
|
149
|
+
handler: () => {
|
|
150
|
+
return new SwaigFunctionResult(
|
|
151
|
+
'This tool is configured for serverless DataMap execution. ' +
|
|
152
|
+
'It should be registered as a data_map function, not invoked via webhook.',
|
|
153
|
+
);
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get DataMap-based tool definitions for server-side execution.
|
|
161
|
+
* These are registered directly in the SWML output as data_map functions
|
|
162
|
+
* rather than as webhook-backed SWAIG tools.
|
|
163
|
+
* @returns Array containing the DataSphere search DataMap function definition.
|
|
164
|
+
*/
|
|
165
|
+
getDataMapTools(): Record<string, unknown>[] {
|
|
166
|
+
return [this.buildDataMapFunction()];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @returns Prompt section describing serverless DataSphere search capabilities. */
|
|
170
|
+
getPromptSections(): SkillPromptSection[] {
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
title: 'Knowledge Base Search (DataSphere - Serverless)',
|
|
174
|
+
body: 'You have access to a knowledge base of documents that can be searched for relevant information. Searches are executed server-side for optimal performance.',
|
|
175
|
+
bullets: [
|
|
176
|
+
'Use the search_datasphere tool when the user asks questions that might be answered by internal documentation or uploaded knowledge.',
|
|
177
|
+
'Results are ranked by relevance and returned automatically.',
|
|
178
|
+
'This search runs entirely on the SignalWire platform without requiring external webhooks.',
|
|
179
|
+
'Synthesize information from the results when appropriate.',
|
|
180
|
+
'If no results are found, let the user know and suggest rephrasing their question.',
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Factory function for creating DataSphereServerlessSkill instances.
|
|
189
|
+
* @param config - Optional skill configuration.
|
|
190
|
+
* @returns A new DataSphereServerlessSkill instance.
|
|
191
|
+
*/
|
|
192
|
+
export function createSkill(config?: SkillConfig): DataSphereServerlessSkill {
|
|
193
|
+
return new DataSphereServerlessSkill(config);
|
|
194
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateTime Skill - Provides current date/time with optional timezone support.
|
|
3
|
+
*
|
|
4
|
+
* Tier 1 built-in skill: no external dependencies required.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { SkillBase } from '../SkillBase.js';
|
|
8
|
+
import type {
|
|
9
|
+
SkillManifest,
|
|
10
|
+
SkillToolDefinition,
|
|
11
|
+
SkillPromptSection,
|
|
12
|
+
SkillConfig,
|
|
13
|
+
} from '../SkillBase.js';
|
|
14
|
+
import { SwaigFunctionResult } from '../../SwaigFunctionResult.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Provides the current date and time with optional timezone support.
|
|
18
|
+
*
|
|
19
|
+
* Tier 1 built-in skill with no external dependencies. Supports all IANA
|
|
20
|
+
* timezone identifiers via the Intl.DateTimeFormat API.
|
|
21
|
+
*/
|
|
22
|
+
export class DateTimeSkill extends SkillBase {
|
|
23
|
+
/**
|
|
24
|
+
* @param config - Optional configuration (no config keys used by this skill).
|
|
25
|
+
*/
|
|
26
|
+
constructor(config?: SkillConfig) {
|
|
27
|
+
super('datetime', config);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @returns Manifest with skill metadata and tags. */
|
|
31
|
+
getManifest(): SkillManifest {
|
|
32
|
+
return {
|
|
33
|
+
name: 'datetime',
|
|
34
|
+
description: 'Provides current date and time information with timezone support.',
|
|
35
|
+
version: '1.0.0',
|
|
36
|
+
tags: ['utility', 'datetime', 'timezone'],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @returns A single `get_datetime` tool that returns the current date/time in a given timezone. */
|
|
41
|
+
getTools(): SkillToolDefinition[] {
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
name: 'get_datetime',
|
|
45
|
+
description:
|
|
46
|
+
'Get the current date and time. Optionally specify a timezone to get the time in that timezone.',
|
|
47
|
+
parameters: {
|
|
48
|
+
timezone: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description:
|
|
51
|
+
'IANA timezone identifier (e.g., America/New_York, Europe/London, Asia/Tokyo). Defaults to UTC if not specified.',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
handler: (args: Record<string, unknown>) => {
|
|
55
|
+
const timezone = (args.timezone as string | undefined) ?? 'UTC';
|
|
56
|
+
const now = new Date();
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const dateFormatter = new Intl.DateTimeFormat('en-US', {
|
|
60
|
+
timeZone: timezone,
|
|
61
|
+
weekday: 'long',
|
|
62
|
+
year: 'numeric',
|
|
63
|
+
month: 'long',
|
|
64
|
+
day: 'numeric',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const timeFormatter = new Intl.DateTimeFormat('en-US', {
|
|
68
|
+
timeZone: timezone,
|
|
69
|
+
hour: '2-digit',
|
|
70
|
+
minute: '2-digit',
|
|
71
|
+
second: '2-digit',
|
|
72
|
+
hour12: true,
|
|
73
|
+
timeZoneName: 'short',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const dateStr = dateFormatter.format(now);
|
|
77
|
+
const timeStr = timeFormatter.format(now);
|
|
78
|
+
|
|
79
|
+
return new SwaigFunctionResult(
|
|
80
|
+
`The current date and time in ${timezone} is: ${dateStr}, ${timeStr}.`,
|
|
81
|
+
);
|
|
82
|
+
} catch {
|
|
83
|
+
return new SwaigFunctionResult(
|
|
84
|
+
`Invalid timezone "${timezone}". Please use a valid IANA timezone identifier such as America/New_York, Europe/London, or Asia/Tokyo.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @returns Prompt section instructing the AI how to use the datetime tool. */
|
|
93
|
+
getPromptSections(): SkillPromptSection[] {
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
title: 'Date and Time',
|
|
97
|
+
body: 'You have the ability to check the current date and time.',
|
|
98
|
+
bullets: [
|
|
99
|
+
'Use the get_datetime tool to retrieve the current date and time.',
|
|
100
|
+
'You can specify a timezone using IANA timezone identifiers (e.g., America/New_York, Europe/London, Asia/Tokyo).',
|
|
101
|
+
'If no timezone is specified, UTC is used by default.',
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Factory function for creating DateTimeSkill instances.
|
|
110
|
+
* @param config - Optional skill configuration.
|
|
111
|
+
* @returns A new DateTimeSkill instance.
|
|
112
|
+
*/
|
|
113
|
+
export function createSkill(config?: SkillConfig): DateTimeSkill {
|
|
114
|
+
return new DateTimeSkill(config);
|
|
115
|
+
}
|