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,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptManager - Manages agent prompts with POM support.
|
|
3
|
+
*
|
|
4
|
+
* Holds either raw prompt text or a PomBuilder for structured prompts.
|
|
5
|
+
*/
|
|
6
|
+
import { PomBuilder } from './PomBuilder.js';
|
|
7
|
+
/** Manages agent prompt text, supporting both raw text and structured POM-based prompts. */
|
|
8
|
+
export class PromptManager {
|
|
9
|
+
rawText = null;
|
|
10
|
+
postPrompt = null;
|
|
11
|
+
pom = null;
|
|
12
|
+
usePom;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new PromptManager.
|
|
15
|
+
* @param usePom - Whether to use structured POM sections (default true).
|
|
16
|
+
*/
|
|
17
|
+
constructor(usePom = true) {
|
|
18
|
+
this.usePom = usePom;
|
|
19
|
+
if (usePom) {
|
|
20
|
+
this.pom = new PomBuilder();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sets the raw prompt text, bypassing POM rendering.
|
|
25
|
+
* @param text - The raw prompt string.
|
|
26
|
+
*/
|
|
27
|
+
setPromptText(text) {
|
|
28
|
+
this.rawText = text;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sets the post-prompt text appended after the main prompt.
|
|
32
|
+
* @param text - The post-prompt string.
|
|
33
|
+
*/
|
|
34
|
+
setPostPrompt(text) {
|
|
35
|
+
this.postPrompt = text;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Adds a POM section to the prompt, initializing the PomBuilder if needed.
|
|
39
|
+
* @param title - The section heading.
|
|
40
|
+
* @param opts - Optional body, bullets, numbering, and subsection configuration.
|
|
41
|
+
*/
|
|
42
|
+
addSection(title, opts) {
|
|
43
|
+
if (!this.pom) {
|
|
44
|
+
this.pom = new PomBuilder();
|
|
45
|
+
this.usePom = true;
|
|
46
|
+
}
|
|
47
|
+
this.pom.addSection(title, opts);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Appends body text or bullets to an existing POM section, creating it if absent.
|
|
51
|
+
* @param title - The section heading to append to.
|
|
52
|
+
* @param opts - Body text and/or bullets to add.
|
|
53
|
+
*/
|
|
54
|
+
addToSection(title, opts) {
|
|
55
|
+
if (!this.pom) {
|
|
56
|
+
this.pom = new PomBuilder();
|
|
57
|
+
this.usePom = true;
|
|
58
|
+
}
|
|
59
|
+
this.pom.addToSection(title, opts);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Adds a subsection under a parent POM section, creating the parent if absent.
|
|
63
|
+
* @param parentTitle - The heading of the parent section.
|
|
64
|
+
* @param title - The subsection heading.
|
|
65
|
+
* @param opts - Optional body text and bullets for the subsection.
|
|
66
|
+
*/
|
|
67
|
+
addSubsection(parentTitle, title, opts) {
|
|
68
|
+
if (!this.pom) {
|
|
69
|
+
this.pom = new PomBuilder();
|
|
70
|
+
this.usePom = true;
|
|
71
|
+
}
|
|
72
|
+
this.pom.addSubsection(parentTitle, title, opts);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks whether a POM section with the given title exists.
|
|
76
|
+
* @param title - The section heading to look for.
|
|
77
|
+
* @returns True if the section exists.
|
|
78
|
+
*/
|
|
79
|
+
hasSection(title) {
|
|
80
|
+
return this.pom?.hasSection(title) ?? false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the fully rendered prompt text, either raw text or POM-rendered Markdown.
|
|
84
|
+
* @returns The prompt string, or empty string if nothing is set.
|
|
85
|
+
*/
|
|
86
|
+
getPrompt() {
|
|
87
|
+
if (this.rawText !== null)
|
|
88
|
+
return this.rawText;
|
|
89
|
+
if (this.pom)
|
|
90
|
+
return this.pom.renderMarkdown();
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the post-prompt text.
|
|
95
|
+
* @returns The post-prompt string, or null if not set.
|
|
96
|
+
*/
|
|
97
|
+
getPostPrompt() {
|
|
98
|
+
return this.postPrompt;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the underlying PomBuilder instance, if POM mode is active.
|
|
102
|
+
* @returns The PomBuilder, or null if POM is not in use.
|
|
103
|
+
*/
|
|
104
|
+
getPomBuilder() {
|
|
105
|
+
return this.pom;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=PromptManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptManager.js","sourceRoot":"","sources":["../src/PromptManager.ts"],"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ACb,IAA4C;QAE5C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,SAAS;QACP,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC;QAC/C,IAAI,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAC/C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SchemaUtils - JSON Schema validation for SWML documents.
|
|
3
|
+
*
|
|
4
|
+
* Provides basic structural validation of rendered SWML.
|
|
5
|
+
* Set SWML_SKIP_SCHEMA_VALIDATION=true to disable.
|
|
6
|
+
*/
|
|
7
|
+
/** Result of validating a SWML document. */
|
|
8
|
+
export interface ValidationResult {
|
|
9
|
+
/** Whether the document passed all validation checks. */
|
|
10
|
+
valid: boolean;
|
|
11
|
+
/** List of human-readable error messages; empty when valid. */
|
|
12
|
+
errors: string[];
|
|
13
|
+
}
|
|
14
|
+
/** Validates SWML documents against structural rules with an LRU-style result cache. */
|
|
15
|
+
export declare class SchemaUtils {
|
|
16
|
+
private skipValidation;
|
|
17
|
+
private cache;
|
|
18
|
+
private maxCacheSize;
|
|
19
|
+
/**
|
|
20
|
+
* Create a SchemaUtils instance.
|
|
21
|
+
* @param opts - Optional settings for skipping validation or limiting cache size.
|
|
22
|
+
*/
|
|
23
|
+
constructor(opts?: {
|
|
24
|
+
skipValidation?: boolean;
|
|
25
|
+
maxCacheSize?: number;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Validate a SWML document against structural rules.
|
|
29
|
+
* @param swml - The SWML document as a JSON string or parsed object.
|
|
30
|
+
* @returns The validation result indicating success or a list of errors.
|
|
31
|
+
*/
|
|
32
|
+
validate(swml: string | Record<string, unknown>): ValidationResult;
|
|
33
|
+
private validateAiVerb;
|
|
34
|
+
/** Clear the validation cache */
|
|
35
|
+
clearCache(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get the number of cached validation results.
|
|
38
|
+
* @returns The current cache entry count.
|
|
39
|
+
*/
|
|
40
|
+
getCacheSize(): number;
|
|
41
|
+
private cacheResult;
|
|
42
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SchemaUtils - JSON Schema validation for SWML documents.
|
|
3
|
+
*
|
|
4
|
+
* Provides basic structural validation of rendered SWML.
|
|
5
|
+
* Set SWML_SKIP_SCHEMA_VALIDATION=true to disable.
|
|
6
|
+
*/
|
|
7
|
+
// Basic SWML structure expectations
|
|
8
|
+
const REQUIRED_TOP_LEVEL = ['version', 'sections'];
|
|
9
|
+
const VALID_VERSIONS = ['1.0.0'];
|
|
10
|
+
/** Validates SWML documents against structural rules with an LRU-style result cache. */
|
|
11
|
+
export class SchemaUtils {
|
|
12
|
+
skipValidation;
|
|
13
|
+
cache = new Map();
|
|
14
|
+
maxCacheSize;
|
|
15
|
+
/**
|
|
16
|
+
* Create a SchemaUtils instance.
|
|
17
|
+
* @param opts - Optional settings for skipping validation or limiting cache size.
|
|
18
|
+
*/
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
this.skipValidation = opts?.skipValidation ?? (process.env['SWML_SKIP_SCHEMA_VALIDATION'] === 'true');
|
|
21
|
+
this.maxCacheSize = opts?.maxCacheSize ?? 100;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate a SWML document against structural rules.
|
|
25
|
+
* @param swml - The SWML document as a JSON string or parsed object.
|
|
26
|
+
* @returns The validation result indicating success or a list of errors.
|
|
27
|
+
*/
|
|
28
|
+
validate(swml) {
|
|
29
|
+
if (this.skipValidation) {
|
|
30
|
+
return { valid: true, errors: [] };
|
|
31
|
+
}
|
|
32
|
+
const swmlStr = typeof swml === 'string' ? swml : JSON.stringify(swml);
|
|
33
|
+
// Check cache
|
|
34
|
+
const cached = this.cache.get(swmlStr);
|
|
35
|
+
if (cached)
|
|
36
|
+
return cached;
|
|
37
|
+
const errors = [];
|
|
38
|
+
let doc;
|
|
39
|
+
try {
|
|
40
|
+
doc = typeof swml === 'string' ? JSON.parse(swml) : swml;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
const result = { valid: false, errors: ['Invalid JSON'] };
|
|
44
|
+
this.cacheResult(swmlStr, result);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
// Check top-level required keys
|
|
48
|
+
for (const key of REQUIRED_TOP_LEVEL) {
|
|
49
|
+
if (!(key in doc)) {
|
|
50
|
+
errors.push(`Missing required top-level key: ${key}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Check version
|
|
54
|
+
if (doc['version'] && !VALID_VERSIONS.includes(doc['version'])) {
|
|
55
|
+
errors.push(`Invalid version: ${doc['version']}. Expected one of: ${VALID_VERSIONS.join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
// Check sections
|
|
58
|
+
if (doc['sections']) {
|
|
59
|
+
if (typeof doc['sections'] !== 'object' || Array.isArray(doc['sections'])) {
|
|
60
|
+
errors.push('sections must be an object');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const sections = doc['sections'];
|
|
64
|
+
if (!('main' in sections)) {
|
|
65
|
+
errors.push('sections must contain a "main" section');
|
|
66
|
+
}
|
|
67
|
+
// Validate each section is an array
|
|
68
|
+
for (const [name, section] of Object.entries(sections)) {
|
|
69
|
+
if (!Array.isArray(section)) {
|
|
70
|
+
errors.push(`Section "${name}" must be an array`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Validate AI verb structure if present
|
|
76
|
+
if (doc['sections'] && typeof doc['sections'] === 'object') {
|
|
77
|
+
const sections = doc['sections'];
|
|
78
|
+
const main = sections['main'];
|
|
79
|
+
if (Array.isArray(main)) {
|
|
80
|
+
for (const verb of main) {
|
|
81
|
+
if (typeof verb === 'object' && verb !== null && 'ai' in verb) {
|
|
82
|
+
this.validateAiVerb(verb['ai'], errors);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const result = {
|
|
88
|
+
valid: errors.length === 0,
|
|
89
|
+
errors,
|
|
90
|
+
};
|
|
91
|
+
this.cacheResult(swmlStr, result);
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
validateAiVerb(ai, errors) {
|
|
95
|
+
if (!ai)
|
|
96
|
+
return;
|
|
97
|
+
// Prompt must have text
|
|
98
|
+
if (ai['prompt']) {
|
|
99
|
+
const prompt = ai['prompt'];
|
|
100
|
+
if (typeof prompt === 'object' && !prompt['text']) {
|
|
101
|
+
errors.push('AI prompt must have a "text" field');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// SWAIG validation
|
|
105
|
+
if (ai['SWAIG']) {
|
|
106
|
+
const swaig = ai['SWAIG'];
|
|
107
|
+
if (swaig['functions'] && !Array.isArray(swaig['functions'])) {
|
|
108
|
+
errors.push('SWAIG functions must be an array');
|
|
109
|
+
}
|
|
110
|
+
if (Array.isArray(swaig['functions'])) {
|
|
111
|
+
for (let i = 0; i < swaig['functions'].length; i++) {
|
|
112
|
+
const fn = swaig['functions'][i];
|
|
113
|
+
if (!fn['function']) {
|
|
114
|
+
errors.push(`SWAIG function at index ${i} missing "function" name`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Post-prompt validation
|
|
120
|
+
if (ai['post_prompt']) {
|
|
121
|
+
const pp = ai['post_prompt'];
|
|
122
|
+
if (typeof pp === 'object' && !pp['text']) {
|
|
123
|
+
errors.push('AI post_prompt must have a "text" field');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Clear the validation cache */
|
|
128
|
+
clearCache() {
|
|
129
|
+
this.cache.clear();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the number of cached validation results.
|
|
133
|
+
* @returns The current cache entry count.
|
|
134
|
+
*/
|
|
135
|
+
getCacheSize() {
|
|
136
|
+
return this.cache.size;
|
|
137
|
+
}
|
|
138
|
+
cacheResult(key, result) {
|
|
139
|
+
if (this.cache.size >= this.maxCacheSize) {
|
|
140
|
+
// Remove oldest entry
|
|
141
|
+
const firstKey = this.cache.keys().next().value;
|
|
142
|
+
if (firstKey)
|
|
143
|
+
this.cache.delete(firstKey);
|
|
144
|
+
}
|
|
145
|
+
this.cache.set(key, result);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=SchemaUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../src/SchemaUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,oCAAoC;AACpC,MAAM,kBAAkB,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACnD,MAAM,cAAc,GAAG,CAAC,OAAO,CAAC,CAAC;AAEjC,wFAAwF;AACxF,MAAM,OAAO,WAAW;IACd,cAAc,CAAU;IACxB,KAAK,GAAkC,IAAI,GAAG,EAAE,CAAC;I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AC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ServerlessAdapter - Adapts AgentBase for serverless platforms.
|
|
3
|
+
*
|
|
4
|
+
* Supports AWS Lambda, Google Cloud Functions, Azure Functions, and CGI mode.
|
|
5
|
+
* Auto-detects platform from environment variables.
|
|
6
|
+
*/
|
|
7
|
+
/** Supported serverless platform identifiers, or 'auto' for environment-based detection. */
|
|
8
|
+
export type ServerlessPlatform = 'lambda' | 'gcf' | 'azure' | 'cgi' | 'auto';
|
|
9
|
+
/** Normalized incoming event from a serverless platform. */
|
|
10
|
+
export interface ServerlessEvent {
|
|
11
|
+
/** HTTP method (AWS Lambda style). */
|
|
12
|
+
httpMethod?: string;
|
|
13
|
+
/** HTTP method (GCF/Azure style). */
|
|
14
|
+
method?: string;
|
|
15
|
+
/** Request headers as key-value pairs. */
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
/** Request body, either raw JSON string or parsed object. */
|
|
18
|
+
body?: string | Record<string, unknown>;
|
|
19
|
+
/** Request path. */
|
|
20
|
+
path?: string;
|
|
21
|
+
/** Raw request path (AWS API Gateway v2). */
|
|
22
|
+
rawPath?: string;
|
|
23
|
+
/** Query string parameters as key-value pairs. */
|
|
24
|
+
queryStringParameters?: Record<string, string>;
|
|
25
|
+
/** Platform-specific request context metadata. */
|
|
26
|
+
requestContext?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** Normalized outgoing response returned to a serverless platform. */
|
|
29
|
+
export interface ServerlessResponse {
|
|
30
|
+
/** HTTP status code. */
|
|
31
|
+
statusCode: number;
|
|
32
|
+
/** Response headers as key-value pairs. */
|
|
33
|
+
headers: Record<string, string>;
|
|
34
|
+
/** Response body as a string. */
|
|
35
|
+
body: string;
|
|
36
|
+
}
|
|
37
|
+
/** Adapts a Hono application for deployment on AWS Lambda, Google Cloud Functions, Azure Functions, or CGI. */
|
|
38
|
+
export declare class ServerlessAdapter {
|
|
39
|
+
private platform;
|
|
40
|
+
/**
|
|
41
|
+
* Create a ServerlessAdapter for the given platform.
|
|
42
|
+
* @param platform - Target platform; defaults to 'auto' which detects from environment variables.
|
|
43
|
+
*/
|
|
44
|
+
constructor(platform?: ServerlessPlatform);
|
|
45
|
+
/**
|
|
46
|
+
* Detect the serverless platform by inspecting well-known environment variables.
|
|
47
|
+
* @returns The detected platform identifier; defaults to 'lambda' if no match is found.
|
|
48
|
+
*/
|
|
49
|
+
detectPlatform(): ServerlessPlatform;
|
|
50
|
+
/**
|
|
51
|
+
* Get the resolved platform identifier.
|
|
52
|
+
* @returns The serverless platform this adapter is configured for.
|
|
53
|
+
*/
|
|
54
|
+
getPlatform(): ServerlessPlatform;
|
|
55
|
+
/**
|
|
56
|
+
* Convert a serverless event into a standard Request, route it through the Hono app, and return a normalized response.
|
|
57
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
58
|
+
* @param event - The incoming serverless event to process.
|
|
59
|
+
* @returns The normalized serverless response.
|
|
60
|
+
*/
|
|
61
|
+
handleRequest(app: {
|
|
62
|
+
fetch: (req: Request) => Promise<Response>;
|
|
63
|
+
}, event: ServerlessEvent): Promise<ServerlessResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Generate the platform-specific invocation URL for a deployed function.
|
|
66
|
+
* @param opts - Optional overrides for region, project, function name, stage, or API ID.
|
|
67
|
+
* @returns The constructed URL string.
|
|
68
|
+
*/
|
|
69
|
+
generateUrl(opts?: {
|
|
70
|
+
region?: string;
|
|
71
|
+
projectId?: string;
|
|
72
|
+
functionName?: string;
|
|
73
|
+
stage?: string;
|
|
74
|
+
apiId?: string;
|
|
75
|
+
}): string;
|
|
76
|
+
/**
|
|
77
|
+
* Create an AWS Lambda-compatible handler function from a Hono app.
|
|
78
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
79
|
+
* @returns A function that accepts a Lambda event and returns a promise of a serverless response.
|
|
80
|
+
*/
|
|
81
|
+
static createLambdaHandler(app: {
|
|
82
|
+
fetch: (req: Request) => Promise<Response>;
|
|
83
|
+
}): (event: ServerlessEvent) => Promise<ServerlessResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Create a Google Cloud Functions-compatible handler from a Hono app.
|
|
86
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
87
|
+
* @returns A function that accepts GCF request/response objects.
|
|
88
|
+
*/
|
|
89
|
+
static createGcfHandler(app: {
|
|
90
|
+
fetch: (req: Request) => Promise<Response>;
|
|
91
|
+
}): (req: any, res: any) => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Create an Azure Functions-compatible handler from a Hono app.
|
|
94
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
95
|
+
* @returns A function that accepts an Azure context and request object.
|
|
96
|
+
*/
|
|
97
|
+
static createAzureHandler(app: {
|
|
98
|
+
fetch: (req: Request) => Promise<Response>;
|
|
99
|
+
}): (context: any, req: any) => Promise<void>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ServerlessAdapter - Adapts AgentBase for serverless platforms.
|
|
3
|
+
*
|
|
4
|
+
* Supports AWS Lambda, Google Cloud Functions, Azure Functions, and CGI mode.
|
|
5
|
+
* Auto-detects platform from environment variables.
|
|
6
|
+
*/
|
|
7
|
+
import { getLogger } from './Logger.js';
|
|
8
|
+
const log = getLogger('ServerlessAdapter');
|
|
9
|
+
/** Adapts a Hono application for deployment on AWS Lambda, Google Cloud Functions, Azure Functions, or CGI. */
|
|
10
|
+
export class ServerlessAdapter {
|
|
11
|
+
platform;
|
|
12
|
+
/**
|
|
13
|
+
* Create a ServerlessAdapter for the given platform.
|
|
14
|
+
* @param platform - Target platform; defaults to 'auto' which detects from environment variables.
|
|
15
|
+
*/
|
|
16
|
+
constructor(platform = 'auto') {
|
|
17
|
+
this.platform = platform === 'auto' ? this.detectPlatform() : platform;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect the serverless platform by inspecting well-known environment variables.
|
|
21
|
+
* @returns The detected platform identifier; defaults to 'lambda' if no match is found.
|
|
22
|
+
*/
|
|
23
|
+
detectPlatform() {
|
|
24
|
+
if (process.env['AWS_LAMBDA_FUNCTION_NAME'] || process.env['_HANDLER'])
|
|
25
|
+
return 'lambda';
|
|
26
|
+
if (process.env['FUNCTION_TARGET'] || process.env['K_SERVICE'])
|
|
27
|
+
return 'gcf';
|
|
28
|
+
if (process.env['FUNCTIONS_WORKER_RUNTIME'] || process.env['AZURE_FUNCTIONS_ENVIRONMENT'])
|
|
29
|
+
return 'azure';
|
|
30
|
+
if (process.env['GATEWAY_INTERFACE'])
|
|
31
|
+
return 'cgi';
|
|
32
|
+
return 'lambda'; // default fallback
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the resolved platform identifier.
|
|
36
|
+
* @returns The serverless platform this adapter is configured for.
|
|
37
|
+
*/
|
|
38
|
+
getPlatform() {
|
|
39
|
+
return this.platform;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert a serverless event into a standard Request, route it through the Hono app, and return a normalized response.
|
|
43
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
44
|
+
* @param event - The incoming serverless event to process.
|
|
45
|
+
* @returns The normalized serverless response.
|
|
46
|
+
*/
|
|
47
|
+
async handleRequest(app, event) {
|
|
48
|
+
const method = event.httpMethod ?? event.method ?? 'POST';
|
|
49
|
+
const path = event.rawPath ?? event.path ?? '/';
|
|
50
|
+
const headers = event.headers ?? {};
|
|
51
|
+
// Build URL
|
|
52
|
+
const host = headers['host'] ?? 'localhost';
|
|
53
|
+
const proto = headers['x-forwarded-proto'] ?? 'https';
|
|
54
|
+
let url = `${proto}://${host}${path}`;
|
|
55
|
+
if (event.queryStringParameters) {
|
|
56
|
+
const qs = new URLSearchParams(event.queryStringParameters).toString();
|
|
57
|
+
if (qs)
|
|
58
|
+
url += `?${qs}`;
|
|
59
|
+
}
|
|
60
|
+
// Build body
|
|
61
|
+
let body;
|
|
62
|
+
if (event.body) {
|
|
63
|
+
body = typeof event.body === 'string' ? event.body : JSON.stringify(event.body);
|
|
64
|
+
}
|
|
65
|
+
// Create Request
|
|
66
|
+
const request = new Request(url, {
|
|
67
|
+
method,
|
|
68
|
+
headers: new Headers(headers),
|
|
69
|
+
body: method !== 'GET' && method !== 'HEAD' ? body : undefined,
|
|
70
|
+
});
|
|
71
|
+
log.debug(`Handling ${method} ${path} on ${this.platform}`);
|
|
72
|
+
// Route through Hono
|
|
73
|
+
const response = await app.fetch(request);
|
|
74
|
+
// Convert back to serverless response
|
|
75
|
+
const responseHeaders = {};
|
|
76
|
+
response.headers.forEach((v, k) => { responseHeaders[k] = v; });
|
|
77
|
+
return {
|
|
78
|
+
statusCode: response.status,
|
|
79
|
+
headers: responseHeaders,
|
|
80
|
+
body: await response.text(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate the platform-specific invocation URL for a deployed function.
|
|
85
|
+
* @param opts - Optional overrides for region, project, function name, stage, or API ID.
|
|
86
|
+
* @returns The constructed URL string.
|
|
87
|
+
*/
|
|
88
|
+
generateUrl(opts) {
|
|
89
|
+
const functionName = opts?.functionName ?? process.env['AWS_LAMBDA_FUNCTION_NAME'] ?? 'agent';
|
|
90
|
+
switch (this.platform) {
|
|
91
|
+
case 'lambda': {
|
|
92
|
+
const region = opts?.region ?? process.env['AWS_REGION'] ?? 'us-east-1';
|
|
93
|
+
const apiId = opts?.apiId ?? 'API_ID';
|
|
94
|
+
const stage = opts?.stage ?? 'prod';
|
|
95
|
+
return `https://${apiId}.execute-api.${region}.amazonaws.com/${stage}`;
|
|
96
|
+
}
|
|
97
|
+
case 'gcf': {
|
|
98
|
+
const project = opts?.projectId ?? process.env['GCLOUD_PROJECT'] ?? 'PROJECT';
|
|
99
|
+
const region = opts?.region ?? process.env['FUNCTION_REGION'] ?? 'us-central1';
|
|
100
|
+
return `https://${region}-${project}.cloudfunctions.net/${functionName}`;
|
|
101
|
+
}
|
|
102
|
+
case 'azure': {
|
|
103
|
+
return `https://${functionName}.azurewebsites.net/api/${functionName}`;
|
|
104
|
+
}
|
|
105
|
+
case 'cgi': {
|
|
106
|
+
return `http://localhost/cgi-bin/${functionName}`;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
return `https://localhost/${functionName}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create an AWS Lambda-compatible handler function from a Hono app.
|
|
114
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
115
|
+
* @returns A function that accepts a Lambda event and returns a promise of a serverless response.
|
|
116
|
+
*/
|
|
117
|
+
static createLambdaHandler(app) {
|
|
118
|
+
const adapter = new ServerlessAdapter('lambda');
|
|
119
|
+
return (event) => adapter.handleRequest(app, event);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a Google Cloud Functions-compatible handler from a Hono app.
|
|
123
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
124
|
+
* @returns A function that accepts GCF request/response objects.
|
|
125
|
+
*/
|
|
126
|
+
static createGcfHandler(app) {
|
|
127
|
+
const adapter = new ServerlessAdapter('gcf');
|
|
128
|
+
return async (req, res) => {
|
|
129
|
+
const event = {
|
|
130
|
+
method: req.method,
|
|
131
|
+
headers: req.headers,
|
|
132
|
+
body: req.body,
|
|
133
|
+
path: req.path ?? req.url,
|
|
134
|
+
};
|
|
135
|
+
const response = await adapter.handleRequest(app, event);
|
|
136
|
+
res.status(response.statusCode);
|
|
137
|
+
for (const [k, v] of Object.entries(response.headers)) {
|
|
138
|
+
res.set(k, v);
|
|
139
|
+
}
|
|
140
|
+
res.send(response.body);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create an Azure Functions-compatible handler from a Hono app.
|
|
145
|
+
* @param app - A Hono-compatible application with a `fetch` method.
|
|
146
|
+
* @returns A function that accepts an Azure context and request object.
|
|
147
|
+
*/
|
|
148
|
+
static createAzureHandler(app) {
|
|
149
|
+
const adapter = new ServerlessAdapter('azure');
|
|
150
|
+
return async (context, req) => {
|
|
151
|
+
const event = {
|
|
152
|
+
method: req.method,
|
|
153
|
+
headers: req.headers,
|
|
154
|
+
body: req.body,
|
|
155
|
+
path: req.url,
|
|
156
|
+
};
|
|
157
|
+
const response = await adapter.handleRequest(app, event);
|
|
158
|
+
context.res = {
|
|
159
|
+
status: response.statusCode,
|
|
160
|
+
headers: response.headers,
|
|
161
|
+
body: response.body,
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=ServerlessAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerlessAdapter.js","sourceRoot":"","sources":["../src/ServerlessAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,GAAG,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAmC3C,+GAA+G;AAC/G,MAAM,OAAO,iBAAiB;IACpB,QAAQ,CAAqB;IAErC;;;OAGG;IACH,YAAY,WAA+B,MAAM;QAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzE,CAAC;IAED;;;OAGG;IACH,cAAc;QACZ,IAAI,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;YAAE,OAAO,QAAQ,CAAC;QACxF,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAA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}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionManager - Stateless HMAC-SHA256 token generation and validation.
|
|
3
|
+
*
|
|
4
|
+
* Tokens encode call_id, function name, expiry and a nonce, signed with a
|
|
5
|
+
* shared secret. No server-side state is stored.
|
|
6
|
+
*/
|
|
7
|
+
/** Stateless HMAC-SHA256 token manager for SWAIG function call authentication and per-session metadata storage. */
|
|
8
|
+
export declare class SessionManager {
|
|
9
|
+
/** Token validity duration in seconds. */
|
|
10
|
+
tokenExpirySecs: number;
|
|
11
|
+
private secretKey;
|
|
12
|
+
private sessionMetadata;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new SessionManager.
|
|
15
|
+
* @param tokenExpirySecs - Token validity duration in seconds (default 3600).
|
|
16
|
+
* @param secretKey - HMAC signing secret; a random key is generated if omitted.
|
|
17
|
+
*/
|
|
18
|
+
constructor(tokenExpirySecs?: number, secretKey?: string);
|
|
19
|
+
/**
|
|
20
|
+
* Return the given callId or generate a new random session identifier.
|
|
21
|
+
* @param callId - Existing call ID to reuse.
|
|
22
|
+
* @returns The call ID string.
|
|
23
|
+
*/
|
|
24
|
+
createSession(callId?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a signed, base64url-encoded token binding a function name to a call ID.
|
|
27
|
+
* @param functionName - The SWAIG function name to bind.
|
|
28
|
+
* @param callId - The call ID to bind.
|
|
29
|
+
* @returns A base64url-encoded token string.
|
|
30
|
+
*/
|
|
31
|
+
generateToken(functionName: string, callId: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Alias for {@link generateToken}.
|
|
34
|
+
* @param functionName - The SWAIG function name to bind.
|
|
35
|
+
* @param callId - The call ID to bind.
|
|
36
|
+
* @returns A base64url-encoded token string.
|
|
37
|
+
*/
|
|
38
|
+
createToolToken(functionName: string, callId: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Validate a token against the expected call ID and function name.
|
|
41
|
+
* @param callId - The expected call ID.
|
|
42
|
+
* @param functionName - The expected function name.
|
|
43
|
+
* @param token - The base64url-encoded token to validate.
|
|
44
|
+
* @returns True if the token is valid and not expired.
|
|
45
|
+
*/
|
|
46
|
+
validateToken(callId: string, functionName: string, token: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Alias for {@link validateToken} with reordered parameters.
|
|
49
|
+
* @param functionName - The expected function name.
|
|
50
|
+
* @param token - The base64url-encoded token to validate.
|
|
51
|
+
* @param callId - The expected call ID.
|
|
52
|
+
* @returns True if the token is valid and not expired.
|
|
53
|
+
*/
|
|
54
|
+
validateToolToken(functionName: string, token: string, callId: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Decode token components for debugging without validating the signature.
|
|
57
|
+
* @param token - The base64url-encoded token to decode.
|
|
58
|
+
* @returns The decoded token fields and expiration status, or null if malformed.
|
|
59
|
+
*/
|
|
60
|
+
debugToken(token: string): {
|
|
61
|
+
callId: string;
|
|
62
|
+
functionName: string;
|
|
63
|
+
expiry: number;
|
|
64
|
+
nonce: string;
|
|
65
|
+
signature: string;
|
|
66
|
+
expired: boolean;
|
|
67
|
+
} | null;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieve metadata associated with a session.
|
|
70
|
+
* @param sessionId - The session identifier.
|
|
71
|
+
* @returns The metadata record, or undefined if no metadata exists.
|
|
72
|
+
*/
|
|
73
|
+
getSessionMetadata(sessionId: string): Record<string, unknown> | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Merge metadata into a session, creating the entry if it does not exist.
|
|
76
|
+
* @param sessionId - The session identifier.
|
|
77
|
+
* @param metadata - Key-value pairs to merge into the session metadata.
|
|
78
|
+
*/
|
|
79
|
+
setSessionMetadata(sessionId: string, metadata: Record<string, unknown>): void;
|
|
80
|
+
/**
|
|
81
|
+
* Delete all metadata for a session.
|
|
82
|
+
* @param sessionId - The session identifier.
|
|
83
|
+
* @returns True if the session existed and was deleted.
|
|
84
|
+
*/
|
|
85
|
+
deleteSessionMetadata(sessionId: string): boolean;
|
|
86
|
+
}
|