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,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Ninjas Trivia Skill - Fetches trivia questions from the API Ninjas service.
|
|
3
|
+
*
|
|
4
|
+
* Tier 2 built-in skill: requires API_NINJAS_KEY environment variable.
|
|
5
|
+
* Uses the API Ninjas Trivia endpoint to retrieve random trivia questions
|
|
6
|
+
* with optional category filtering.
|
|
7
|
+
*/
|
|
8
|
+
import { SkillBase } from '../SkillBase.js';
|
|
9
|
+
import { SwaigFunctionResult } from '../../SwaigFunctionResult.js';
|
|
10
|
+
const VALID_CATEGORIES = [
|
|
11
|
+
'artliterature',
|
|
12
|
+
'language',
|
|
13
|
+
'sciencenature',
|
|
14
|
+
'general',
|
|
15
|
+
'fooddrink',
|
|
16
|
+
'peopleplaces',
|
|
17
|
+
'geography',
|
|
18
|
+
'historyholidays',
|
|
19
|
+
'entertainment',
|
|
20
|
+
'toysgames',
|
|
21
|
+
'music',
|
|
22
|
+
'mathematics',
|
|
23
|
+
'religionmythology',
|
|
24
|
+
'sportsleisure',
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Fetches trivia questions from the API Ninjas service.
|
|
28
|
+
*
|
|
29
|
+
* Tier 2 built-in skill. Requires the `API_NINJAS_KEY` environment variable.
|
|
30
|
+
* Supports optional `default_category` and `reveal_answer` config options.
|
|
31
|
+
*/
|
|
32
|
+
export class ApiNinjasTriviaSkill extends SkillBase {
|
|
33
|
+
/**
|
|
34
|
+
* @param config - Optional configuration; supports `default_category` and `reveal_answer`.
|
|
35
|
+
*/
|
|
36
|
+
constructor(config) {
|
|
37
|
+
super('api_ninjas_trivia', config);
|
|
38
|
+
}
|
|
39
|
+
/** @returns Manifest declaring API_NINJAS_KEY as required and config schema for category/reveal. */
|
|
40
|
+
getManifest() {
|
|
41
|
+
return {
|
|
42
|
+
name: 'api_ninjas_trivia',
|
|
43
|
+
description: 'Fetches trivia questions from the API Ninjas service. Supports multiple categories for varied trivia topics.',
|
|
44
|
+
version: '1.0.0',
|
|
45
|
+
author: 'SignalWire',
|
|
46
|
+
tags: ['trivia', 'api', 'entertainment', 'quiz', 'external'],
|
|
47
|
+
requiredEnvVars: ['API_NINJAS_KEY'],
|
|
48
|
+
configSchema: {
|
|
49
|
+
default_category: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Default trivia category if none is specified by the user.',
|
|
52
|
+
},
|
|
53
|
+
reveal_answer: {
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
description: 'Whether to include the answer in the response. Defaults to false so the AI can quiz the user.',
|
|
56
|
+
default: false,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** @returns A single `get_trivia` tool that fetches a random trivia question with optional category. */
|
|
62
|
+
getTools() {
|
|
63
|
+
const defaultCategory = this.getConfig('default_category', undefined);
|
|
64
|
+
const revealAnswer = this.getConfig('reveal_answer', false);
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
name: 'get_trivia',
|
|
68
|
+
description: 'Get a random trivia question. Optionally specify a category to narrow the topic.',
|
|
69
|
+
parameters: {
|
|
70
|
+
category: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
description: 'Trivia category. Available categories: ' +
|
|
73
|
+
VALID_CATEGORIES.join(', ') +
|
|
74
|
+
'. If not specified, a random category is used.',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
handler: async (args) => {
|
|
78
|
+
const apiKey = process.env['API_NINJAS_KEY'];
|
|
79
|
+
if (!apiKey) {
|
|
80
|
+
return new SwaigFunctionResult('Trivia service is not configured. The API_NINJAS_KEY environment variable is missing.');
|
|
81
|
+
}
|
|
82
|
+
let category = args.category ?? defaultCategory;
|
|
83
|
+
// Validate category if provided
|
|
84
|
+
if (category && typeof category === 'string') {
|
|
85
|
+
const normalized = category.toLowerCase().trim().replace(/[\s_-]/g, '');
|
|
86
|
+
if (!VALID_CATEGORIES.includes(normalized)) {
|
|
87
|
+
return new SwaigFunctionResult(`Unknown trivia category "${category}". Available categories: ${VALID_CATEGORIES.join(', ')}.`);
|
|
88
|
+
}
|
|
89
|
+
category = normalized;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const url = category
|
|
93
|
+
? `https://api.api-ninjas.com/v1/trivia?category=${encodeURIComponent(category)}`
|
|
94
|
+
: 'https://api.api-ninjas.com/v1/trivia';
|
|
95
|
+
const response = await fetch(url, {
|
|
96
|
+
headers: {
|
|
97
|
+
'X-Api-Key': apiKey,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
return new SwaigFunctionResult(`Failed to fetch trivia: HTTP ${response.status} ${response.statusText}. Please try again later.`);
|
|
102
|
+
}
|
|
103
|
+
const data = (await response.json());
|
|
104
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
105
|
+
return new SwaigFunctionResult('No trivia questions were returned. Please try again or try a different category.');
|
|
106
|
+
}
|
|
107
|
+
const trivia = data[0];
|
|
108
|
+
if (revealAnswer) {
|
|
109
|
+
return new SwaigFunctionResult(`Trivia (${trivia.category}): ${trivia.question} Answer: ${trivia.answer}`);
|
|
110
|
+
}
|
|
111
|
+
// When not revealing the answer, provide it in a structured way
|
|
112
|
+
// so the AI knows the answer but can quiz the user
|
|
113
|
+
return new SwaigFunctionResult(`Here is a trivia question from the "${trivia.category}" category. ` +
|
|
114
|
+
`Question: ${trivia.question} ` +
|
|
115
|
+
`[The correct answer is: ${trivia.answer}. Do not reveal this unless the user attempts an answer or asks for it.]`);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
119
|
+
return new SwaigFunctionResult(`Failed to fetch trivia question: ${message}`);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
/** @returns Prompt section describing trivia capabilities and quiz behavior. */
|
|
126
|
+
getPromptSections() {
|
|
127
|
+
const revealAnswer = this.getConfig('reveal_answer', false);
|
|
128
|
+
const bullets = [
|
|
129
|
+
'Use the get_trivia tool to fetch a random trivia question.',
|
|
130
|
+
`Available categories: ${VALID_CATEGORIES.join(', ')}.`,
|
|
131
|
+
'If no category is specified, a random category will be selected.',
|
|
132
|
+
];
|
|
133
|
+
if (!revealAnswer) {
|
|
134
|
+
bullets.push('When you receive a trivia question, ask it to the user and let them try to answer before revealing the correct answer.', 'If the user gets it wrong, give them a hint or tell them the correct answer.');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
bullets.push('Trivia answers are included in the response. Share the question and answer with the user.');
|
|
138
|
+
}
|
|
139
|
+
bullets.push('Keep trivia fun and engaging. Encourage the user to try more questions.');
|
|
140
|
+
return [
|
|
141
|
+
{
|
|
142
|
+
title: 'Trivia Questions',
|
|
143
|
+
body: 'You can fetch and ask trivia questions from a wide range of categories.',
|
|
144
|
+
bullets,
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
/** @returns Speech recognition hints for trivia-related keywords. */
|
|
149
|
+
getHints() {
|
|
150
|
+
return ['trivia', 'quiz', 'question', 'fun fact'];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Factory function for creating ApiNinjasTriviaSkill instances.
|
|
155
|
+
* @param config - Optional skill configuration.
|
|
156
|
+
* @returns A new ApiNinjasTriviaSkill instance.
|
|
157
|
+
*/
|
|
158
|
+
export function createSkill(config) {
|
|
159
|
+
return new ApiNinjasTriviaSkill(config);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=api_ninjas_trivia.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api_ninjas_trivia.js","sourceRoot":"","sources":["../../../src/skills/builtin/api_ninjas_trivia.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAYnE,MAAM,gBAAgB,GAAG;IACvB,eAAe;IACf,UAAU;IACV,eAAe;IACf,SAAS;IACT,WAAW;IACX,cAAc;IACd,WAAW;IACX,iBAAiB;IACjB,eAAe;IACf,WAAW;IACX,OAAO;IACP,aAAa;IACb,mBAAmB;IACnB,eAAe;CACP,CAAC;AAEX;;;;;GAKG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACjD;;OAEG;IACH,YAAY,MAAoB;QAC9B,KAAK,CAAC,mBA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C,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Skills - Provides access to Anthropic's Claude AI for sub-queries.
|
|
3
|
+
*
|
|
4
|
+
* Tier 3 built-in skill: requires ANTHROPIC_API_KEY environment variable.
|
|
5
|
+
* Allows the agent to send prompts to Claude for complex reasoning,
|
|
6
|
+
* analysis, or sub-tasks that benefit from a dedicated AI query.
|
|
7
|
+
*/
|
|
8
|
+
import { SkillBase } from '../SkillBase.js';
|
|
9
|
+
import type { SkillManifest, SkillToolDefinition, SkillPromptSection, SkillConfig } from '../SkillBase.js';
|
|
10
|
+
/**
|
|
11
|
+
* Provides access to Anthropic's Claude AI for sub-queries and complex reasoning.
|
|
12
|
+
*
|
|
13
|
+
* Tier 3 built-in skill. Requires the `ANTHROPIC_API_KEY` environment variable.
|
|
14
|
+
* Supports `model` and `max_tokens` config options to control which Claude model
|
|
15
|
+
* is used and the maximum response length.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ClaudeSkill extends SkillBase {
|
|
18
|
+
/**
|
|
19
|
+
* @param config - Optional configuration; supports `model` and `max_tokens`.
|
|
20
|
+
*/
|
|
21
|
+
constructor(config?: SkillConfig);
|
|
22
|
+
/** @returns Manifest declaring ANTHROPIC_API_KEY as required and config schema for model/max_tokens. */
|
|
23
|
+
getManifest(): SkillManifest;
|
|
24
|
+
/** @returns A single `ask_claude` tool that sends prompts to the Claude API. */
|
|
25
|
+
getTools(): SkillToolDefinition[];
|
|
26
|
+
/** @returns Prompt section describing Claude AI delegation capabilities. */
|
|
27
|
+
getPromptSections(): SkillPromptSection[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Factory function for creating ClaudeSkill instances.
|
|
31
|
+
* @param config - Optional skill configuration.
|
|
32
|
+
* @returns A new ClaudeSkill instance.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createSkill(config?: SkillConfig): ClaudeSkill;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Skills - Provides access to Anthropic's Claude AI for sub-queries.
|
|
3
|
+
*
|
|
4
|
+
* Tier 3 built-in skill: requires ANTHROPIC_API_KEY environment variable.
|
|
5
|
+
* Allows the agent to send prompts to Claude for complex reasoning,
|
|
6
|
+
* analysis, or sub-tasks that benefit from a dedicated AI query.
|
|
7
|
+
*/
|
|
8
|
+
import { SkillBase } from '../SkillBase.js';
|
|
9
|
+
import { SwaigFunctionResult } from '../../SwaigFunctionResult.js';
|
|
10
|
+
/**
|
|
11
|
+
* Provides access to Anthropic's Claude AI for sub-queries and complex reasoning.
|
|
12
|
+
*
|
|
13
|
+
* Tier 3 built-in skill. Requires the `ANTHROPIC_API_KEY` environment variable.
|
|
14
|
+
* Supports `model` and `max_tokens` config options to control which Claude model
|
|
15
|
+
* is used and the maximum response length.
|
|
16
|
+
*/
|
|
17
|
+
export class ClaudeSkill extends SkillBase {
|
|
18
|
+
/**
|
|
19
|
+
* @param config - Optional configuration; supports `model` and `max_tokens`.
|
|
20
|
+
*/
|
|
21
|
+
constructor(config) {
|
|
22
|
+
super('claude_skills', config);
|
|
23
|
+
}
|
|
24
|
+
/** @returns Manifest declaring ANTHROPIC_API_KEY as required and config schema for model/max_tokens. */
|
|
25
|
+
getManifest() {
|
|
26
|
+
return {
|
|
27
|
+
name: 'claude_skills',
|
|
28
|
+
description: 'Provides access to Anthropic Claude AI for complex reasoning, analysis, and sub-queries.',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
author: 'SignalWire',
|
|
31
|
+
tags: ['ai', 'claude', 'anthropic', 'reasoning', 'analysis', 'external'],
|
|
32
|
+
requiredEnvVars: ['ANTHROPIC_API_KEY'],
|
|
33
|
+
configSchema: {
|
|
34
|
+
model: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
description: 'The Claude model to use. Defaults to "claude-sonnet-4-5-20250929".',
|
|
37
|
+
default: 'claude-sonnet-4-5-20250929',
|
|
38
|
+
},
|
|
39
|
+
max_tokens: {
|
|
40
|
+
type: 'number',
|
|
41
|
+
description: 'Maximum tokens in the response. Defaults to 1024.',
|
|
42
|
+
default: 1024,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** @returns A single `ask_claude` tool that sends prompts to the Claude API. */
|
|
48
|
+
getTools() {
|
|
49
|
+
const model = this.getConfig('model', 'claude-sonnet-4-5-20250929');
|
|
50
|
+
const maxTokens = this.getConfig('max_tokens', 1024);
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
name: 'ask_claude',
|
|
54
|
+
description: 'Send a prompt to Claude AI for complex reasoning, analysis, summarization, or any task that benefits from dedicated AI processing. Returns Claude\'s response.',
|
|
55
|
+
parameters: {
|
|
56
|
+
prompt: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'The prompt or question to send to Claude.',
|
|
59
|
+
},
|
|
60
|
+
system_prompt: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
description: 'Optional system prompt to set context or instructions for Claude.',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
required: ['prompt'],
|
|
66
|
+
handler: async (args) => {
|
|
67
|
+
const prompt = args.prompt;
|
|
68
|
+
const systemPrompt = args.system_prompt;
|
|
69
|
+
if (!prompt || typeof prompt !== 'string' || prompt.trim().length === 0) {
|
|
70
|
+
return new SwaigFunctionResult('Please provide a prompt for Claude.');
|
|
71
|
+
}
|
|
72
|
+
const apiKey = process.env['ANTHROPIC_API_KEY'];
|
|
73
|
+
if (!apiKey) {
|
|
74
|
+
return new SwaigFunctionResult('Claude AI is not configured. The ANTHROPIC_API_KEY environment variable is required.');
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const messages = [
|
|
78
|
+
{ role: 'user', content: prompt.trim() },
|
|
79
|
+
];
|
|
80
|
+
const requestBody = {
|
|
81
|
+
model,
|
|
82
|
+
max_tokens: maxTokens,
|
|
83
|
+
messages,
|
|
84
|
+
};
|
|
85
|
+
if (systemPrompt && typeof systemPrompt === 'string' && systemPrompt.trim().length > 0) {
|
|
86
|
+
requestBody['system'] = systemPrompt.trim();
|
|
87
|
+
}
|
|
88
|
+
const response = await fetch('https://api.anthropic.com/v1/messages', {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
'x-api-key': apiKey,
|
|
93
|
+
'anthropic-version': '2023-06-01',
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify(requestBody),
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
const errorText = await response.text();
|
|
99
|
+
let errorMsg;
|
|
100
|
+
try {
|
|
101
|
+
const errorData = JSON.parse(errorText);
|
|
102
|
+
errorMsg = errorData.error?.message ?? `HTTP ${response.status}`;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
errorMsg = `HTTP ${response.status}: ${errorText.slice(0, 300)}`;
|
|
106
|
+
}
|
|
107
|
+
return new SwaigFunctionResult(`Claude API request failed: ${errorMsg}`);
|
|
108
|
+
}
|
|
109
|
+
const data = (await response.json());
|
|
110
|
+
if (data.error) {
|
|
111
|
+
return new SwaigFunctionResult(`Claude returned an error: ${data.error.message}`);
|
|
112
|
+
}
|
|
113
|
+
// Extract text content from the response
|
|
114
|
+
const textParts = data.content
|
|
115
|
+
.filter((block) => block.type === 'text' && block.text)
|
|
116
|
+
.map((block) => block.text);
|
|
117
|
+
if (textParts.length === 0) {
|
|
118
|
+
return new SwaigFunctionResult('Claude returned an empty response. Try rephrasing your prompt.');
|
|
119
|
+
}
|
|
120
|
+
const responseText = textParts.join('\n\n');
|
|
121
|
+
return new SwaigFunctionResult(responseText);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
125
|
+
return new SwaigFunctionResult(`Failed to query Claude AI: ${message}`);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
/** @returns Prompt section describing Claude AI delegation capabilities. */
|
|
132
|
+
getPromptSections() {
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
title: 'Claude AI Assistant',
|
|
136
|
+
body: 'You can delegate complex reasoning or analysis tasks to Claude AI.',
|
|
137
|
+
bullets: [
|
|
138
|
+
'Use the ask_claude tool for tasks requiring detailed analysis, summarization, or complex reasoning.',
|
|
139
|
+
'You can provide an optional system prompt to set specific instructions or context.',
|
|
140
|
+
'This is useful for tasks like: detailed explanations, code analysis, text summarization, creative writing, or multi-step reasoning.',
|
|
141
|
+
'Do not use this tool for simple factual questions you already know the answer to.',
|
|
142
|
+
'Summarize or relay Claude\'s response naturally to the user.',
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Factory function for creating ClaudeSkill instances.
|
|
150
|
+
* @param config - Optional skill configuration.
|
|
151
|
+
* @returns A new ClaudeSkill instance.
|
|
152
|
+
*/
|
|
153
|
+
export function createSkill(config) {
|
|
154
|
+
return new ClaudeSkill(config);
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=claude_skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude_skills.js","sourceRoot":"","sources":["../../../src/skills/builtin/claude_skills.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAkDnE;;;;;;GAMG;AACH,MAAM,OAAO,WAAY,S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C,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;wBACjE,OAAO,IAAI,mBAAmB,CAC5B,8BAA8B,OAAO,EAAE,CACxC,CAAC;oBACJ,CAAC;gBACH,CAAC;aACF;SACF,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;QACf,OAAO;YACL;gBACE,KAAK,EAAE,qBAAqB;gBAC5B,IAAI,EAAE,oEAAoE;gBAC1E,OAAO,EAAE;oBACP,qGAAqG;oBACrG,oFAAoF;oBACpF,qIAAqI;oBACrI,mFAAmF;oBACnF,8DAA8D;iBAC/D;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Skills - A meta-skill that registers user-defined tools from configuration.
|
|
3
|
+
*
|
|
4
|
+
* Tier 2 built-in skill: no external dependencies required.
|
|
5
|
+
* Allows users to define arbitrary tools via config without writing skill classes.
|
|
6
|
+
* Each tool definition in the config specifies its name, description, parameters,
|
|
7
|
+
* and a handler function body (executed via Function constructor).
|
|
8
|
+
*
|
|
9
|
+
* This is useful for rapid prototyping, simple integrations, and cases where
|
|
10
|
+
* creating a full skill class would be overkill.
|
|
11
|
+
*/
|
|
12
|
+
import { SkillBase } from '../SkillBase.js';
|
|
13
|
+
import type { SkillManifest, SkillToolDefinition, SkillPromptSection, SkillConfig } from '../SkillBase.js';
|
|
14
|
+
/**
|
|
15
|
+
* A meta-skill that registers user-defined tools from configuration.
|
|
16
|
+
*
|
|
17
|
+
* Tier 2 built-in skill with no external dependencies. Allows users to define
|
|
18
|
+
* arbitrary tools via config without writing skill classes. Each tool definition
|
|
19
|
+
* specifies a name, description, parameters, and a JavaScript handler function
|
|
20
|
+
* body that is compiled via the Function constructor at instantiation time.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CustomSkillsSkill extends SkillBase {
|
|
23
|
+
private _compiledHandlers;
|
|
24
|
+
private _compilationErrors;
|
|
25
|
+
/**
|
|
26
|
+
* @param config - Configuration object containing a `tools` array of custom tool definitions.
|
|
27
|
+
*/
|
|
28
|
+
constructor(config?: SkillConfig);
|
|
29
|
+
/** @returns Manifest with config schema describing the tools array format. */
|
|
30
|
+
getManifest(): SkillManifest;
|
|
31
|
+
/**
|
|
32
|
+
* Pre-compile handler code into functions during construction.
|
|
33
|
+
* This catches syntax errors early and avoids re-compilation on each call.
|
|
34
|
+
*/
|
|
35
|
+
private _compileHandlers;
|
|
36
|
+
/**
|
|
37
|
+
* Get the raw tool definitions from config.
|
|
38
|
+
*/
|
|
39
|
+
private _getToolDefs;
|
|
40
|
+
/** @returns Array of dynamically generated tools from the configuration, with compiled handlers. */
|
|
41
|
+
getTools(): SkillToolDefinition[];
|
|
42
|
+
/** @returns Prompt section listing all custom tools and their descriptions. */
|
|
43
|
+
getPromptSections(): SkillPromptSection[];
|
|
44
|
+
/**
|
|
45
|
+
* Build tool parameters from the custom tool definition.
|
|
46
|
+
*/
|
|
47
|
+
private _buildParameters;
|
|
48
|
+
/**
|
|
49
|
+
* Get handler compilation errors for diagnostic purposes.
|
|
50
|
+
* @returns A copy of the map from tool name to error message.
|
|
51
|
+
*/
|
|
52
|
+
getCompilationErrors(): Map<string, string>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Factory function for creating CustomSkillsSkill instances.
|
|
56
|
+
* @param config - Configuration containing a `tools` array of custom tool definitions.
|
|
57
|
+
* @returns A new CustomSkillsSkill instance.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createSkill(config?: SkillConfig): CustomSkillsSkill;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Skills - A meta-skill that registers user-defined tools from configuration.
|
|
3
|
+
*
|
|
4
|
+
* Tier 2 built-in skill: no external dependencies required.
|
|
5
|
+
* Allows users to define arbitrary tools via config without writing skill classes.
|
|
6
|
+
* Each tool definition in the config specifies its name, description, parameters,
|
|
7
|
+
* and a handler function body (executed via Function constructor).
|
|
8
|
+
*
|
|
9
|
+
* This is useful for rapid prototyping, simple integrations, and cases where
|
|
10
|
+
* creating a full skill class would be overkill.
|
|
11
|
+
*/
|
|
12
|
+
import { SkillBase } from '../SkillBase.js';
|
|
13
|
+
import { SwaigFunctionResult } from '../../SwaigFunctionResult.js';
|
|
14
|
+
/**
|
|
15
|
+
* A meta-skill that registers user-defined tools from configuration.
|
|
16
|
+
*
|
|
17
|
+
* Tier 2 built-in skill with no external dependencies. Allows users to define
|
|
18
|
+
* arbitrary tools via config without writing skill classes. Each tool definition
|
|
19
|
+
* specifies a name, description, parameters, and a JavaScript handler function
|
|
20
|
+
* body that is compiled via the Function constructor at instantiation time.
|
|
21
|
+
*/
|
|
22
|
+
export class CustomSkillsSkill extends SkillBase {
|
|
23
|
+
_compiledHandlers = new Map();
|
|
24
|
+
_compilationErrors = new Map();
|
|
25
|
+
/**
|
|
26
|
+
* @param config - Configuration object containing a `tools` array of custom tool definitions.
|
|
27
|
+
*/
|
|
28
|
+
constructor(config) {
|
|
29
|
+
super('custom_skills', config);
|
|
30
|
+
this._compileHandlers();
|
|
31
|
+
}
|
|
32
|
+
/** @returns Manifest with config schema describing the tools array format. */
|
|
33
|
+
getManifest() {
|
|
34
|
+
return {
|
|
35
|
+
name: 'custom_skills',
|
|
36
|
+
description: 'A meta-skill that registers user-defined tools from configuration. Define tools with names, descriptions, parameters, and handler code.',
|
|
37
|
+
version: '1.0.0',
|
|
38
|
+
author: 'SignalWire',
|
|
39
|
+
tags: ['meta', 'custom', 'extensible', 'dynamic'],
|
|
40
|
+
configSchema: {
|
|
41
|
+
tools: {
|
|
42
|
+
type: 'array',
|
|
43
|
+
description: 'Array of custom tool definitions: { name, description, parameters?, handler_code, required?, prompt_description?, secure?, fillers? }.',
|
|
44
|
+
items: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: {
|
|
47
|
+
name: { type: 'string', description: 'Tool name (must be unique).' },
|
|
48
|
+
description: { type: 'string', description: 'Tool description for the AI.' },
|
|
49
|
+
parameters: {
|
|
50
|
+
type: 'array',
|
|
51
|
+
description: 'Tool parameters: [{ name, type, description, required? }].',
|
|
52
|
+
},
|
|
53
|
+
handler_code: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'JavaScript function body. Receives (args, rawData, SwaigFunctionResult) as arguments. Must return a SwaigFunctionResult, string, or object.',
|
|
56
|
+
},
|
|
57
|
+
required: {
|
|
58
|
+
type: 'array',
|
|
59
|
+
description: 'Array of required parameter names.',
|
|
60
|
+
},
|
|
61
|
+
prompt_description: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Description to include in the prompt section for this tool.',
|
|
64
|
+
},
|
|
65
|
+
secure: { type: 'boolean', description: 'Whether to mark the tool as secure.' },
|
|
66
|
+
fillers: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
description: 'Filler phrases for the tool.',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
required: ['name', 'description', 'handler_code'],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
prompt_title: {
|
|
75
|
+
type: 'string',
|
|
76
|
+
description: 'Custom title for the prompt section. Defaults to "Custom Tools".',
|
|
77
|
+
},
|
|
78
|
+
prompt_body: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
description: 'Custom body text for the prompt section.',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Pre-compile handler code into functions during construction.
|
|
87
|
+
* This catches syntax errors early and avoids re-compilation on each call.
|
|
88
|
+
*/
|
|
89
|
+
_compileHandlers() {
|
|
90
|
+
const toolDefs = this._getToolDefs();
|
|
91
|
+
for (const toolDef of toolDefs) {
|
|
92
|
+
try {
|
|
93
|
+
// The handler code receives: args, rawData, SwaigFunctionResult
|
|
94
|
+
// It should return a SwaigFunctionResult, string, or plain object
|
|
95
|
+
const handler = new Function('args', 'rawData', 'SwaigFunctionResult', toolDef.handler_code);
|
|
96
|
+
this._compiledHandlers.set(toolDef.name, handler);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
100
|
+
this._compilationErrors.set(toolDef.name, message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the raw tool definitions from config.
|
|
106
|
+
*/
|
|
107
|
+
_getToolDefs() {
|
|
108
|
+
const configData = this.config;
|
|
109
|
+
return configData.tools ?? [];
|
|
110
|
+
}
|
|
111
|
+
/** @returns Array of dynamically generated tools from the configuration, with compiled handlers. */
|
|
112
|
+
getTools() {
|
|
113
|
+
const toolDefs = this._getToolDefs();
|
|
114
|
+
const tools = [];
|
|
115
|
+
for (const toolDef of toolDefs) {
|
|
116
|
+
// Check for compilation errors
|
|
117
|
+
const compError = this._compilationErrors.get(toolDef.name);
|
|
118
|
+
if (compError) {
|
|
119
|
+
// Still register the tool but with an error handler
|
|
120
|
+
tools.push({
|
|
121
|
+
name: toolDef.name,
|
|
122
|
+
description: toolDef.description,
|
|
123
|
+
parameters: this._buildParameters(toolDef),
|
|
124
|
+
required: toolDef.required,
|
|
125
|
+
secure: toolDef.secure,
|
|
126
|
+
fillers: toolDef.fillers,
|
|
127
|
+
handler: () => {
|
|
128
|
+
return new SwaigFunctionResult(`Custom tool "${toolDef.name}" has a compilation error in its handler code: ${compError}. Please fix the handler_code configuration.`);
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const compiledHandler = this._compiledHandlers.get(toolDef.name);
|
|
134
|
+
if (!compiledHandler) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
tools.push({
|
|
138
|
+
name: toolDef.name,
|
|
139
|
+
description: toolDef.description,
|
|
140
|
+
parameters: this._buildParameters(toolDef),
|
|
141
|
+
required: toolDef.required,
|
|
142
|
+
secure: toolDef.secure,
|
|
143
|
+
fillers: toolDef.fillers,
|
|
144
|
+
handler: async (args, rawData) => {
|
|
145
|
+
try {
|
|
146
|
+
const result = await compiledHandler(args, rawData, SwaigFunctionResult);
|
|
147
|
+
// Normalize the result
|
|
148
|
+
if (result instanceof SwaigFunctionResult) {
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
if (typeof result === 'string') {
|
|
152
|
+
return new SwaigFunctionResult(result);
|
|
153
|
+
}
|
|
154
|
+
if (result && typeof result === 'object') {
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
return new SwaigFunctionResult('Action completed.');
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
161
|
+
return new SwaigFunctionResult(`Custom tool "${toolDef.name}" encountered a runtime error: ${message}`);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return tools;
|
|
167
|
+
}
|
|
168
|
+
/** @returns Prompt section listing all custom tools and their descriptions. */
|
|
169
|
+
getPromptSections() {
|
|
170
|
+
const toolDefs = this._getToolDefs();
|
|
171
|
+
const configData = this.config;
|
|
172
|
+
if (toolDefs.length === 0) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
const title = configData.prompt_title ?? 'Custom Tools';
|
|
176
|
+
const body = configData.prompt_body ??
|
|
177
|
+
'The following custom tools are available for use.';
|
|
178
|
+
const bullets = [];
|
|
179
|
+
for (const toolDef of toolDefs) {
|
|
180
|
+
const compError = this._compilationErrors.get(toolDef.name);
|
|
181
|
+
if (compError) {
|
|
182
|
+
bullets.push(`${toolDef.name}: [ERROR - handler compilation failed] ${toolDef.description}`);
|
|
183
|
+
}
|
|
184
|
+
else if (toolDef.prompt_description) {
|
|
185
|
+
bullets.push(`${toolDef.name}: ${toolDef.prompt_description}`);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
bullets.push(`${toolDef.name}: ${toolDef.description}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return [
|
|
192
|
+
{
|
|
193
|
+
title,
|
|
194
|
+
body,
|
|
195
|
+
bullets,
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Build tool parameters from the custom tool definition.
|
|
201
|
+
*/
|
|
202
|
+
_buildParameters(toolDef) {
|
|
203
|
+
if (!toolDef.parameters || toolDef.parameters.length === 0) {
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
const params = {};
|
|
207
|
+
for (const param of toolDef.parameters) {
|
|
208
|
+
params[param.name] = {
|
|
209
|
+
type: param.type,
|
|
210
|
+
description: param.description,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return params;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get handler compilation errors for diagnostic purposes.
|
|
217
|
+
* @returns A copy of the map from tool name to error message.
|
|
218
|
+
*/
|
|
219
|
+
getCompilationErrors() {
|
|
220
|
+
return new Map(this._compilationErrors);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Factory function for creating CustomSkillsSkill instances.
|
|
225
|
+
* @param config - Configuration containing a `tools` array of custom tool definitions.
|
|
226
|
+
* @returns A new CustomSkillsSkill instance.
|
|
227
|
+
*/
|
|
228
|
+
export function createSkill(config) {
|
|
229
|
+
return new CustomSkillsSkill(config);
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=custom_skills.js.map
|