@signalwire/sdk 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +27 -0
- package/.github/workflows/test.yml +17 -0
- package/CLAUDE.md +112 -0
- package/README.md +254 -0
- package/docs/MIGRATION-2.0.md +81 -0
- package/docs/agent-guide.md +869 -0
- package/docs/agent_guide.md +1026 -0
- package/docs/api-reference.md +2420 -0
- package/docs/api_reference.md +1301 -0
- package/docs/architecture.md +843 -0
- package/docs/cli-guide.md +579 -0
- package/docs/cli_guide.md +448 -0
- package/docs/cloud_functions_guide.md +474 -0
- package/docs/configuration.md +422 -0
- package/docs/contexts-guide.md +787 -0
- package/docs/contexts_guide.md +511 -0
- package/docs/datamap-guide.md +1141 -0
- package/docs/datamap_guide.md +595 -0
- package/docs/llm_parameters.md +239 -0
- package/docs/mcp_gateway_reference.md +648 -0
- package/docs/mcp_integration.md +108 -0
- package/docs/prefabs-guide.md +800 -0
- package/docs/sdk_features.md +477 -0
- package/docs/security.md +436 -0
- package/docs/serverless-guide.md +513 -0
- package/docs/skills-guide.md +857 -0
- package/docs/skills-system.md +301 -0
- package/docs/skills_parameter_schema.md +392 -0
- package/docs/skills_system.md +467 -0
- package/docs/swaig-reference.md +1627 -0
- package/docs/swaig_reference.md +910 -0
- package/docs/swml_service_guide.md +600 -0
- package/docs/third_party_skills.md +533 -0
- package/docs/web_service.md +677 -0
- package/examples/README.md +131 -0
- package/examples/advanced-datamap.ts +100 -0
- package/examples/advanced-dynamic-config.ts +70 -0
- package/examples/auto-vivified.ts +94 -0
- package/examples/call-flow.ts +63 -0
- package/examples/comprehensive-dynamic.ts +125 -0
- package/examples/contexts-steps.ts +65 -0
- package/examples/custom-path.ts +45 -0
- package/examples/datamap-tools.ts +55 -0
- package/examples/datasphere-multi-instance.ts +63 -0
- package/examples/datasphere-serverless-env.ts +68 -0
- package/examples/datasphere-webhook-env.ts +66 -0
- package/examples/datasphere.ts +37 -0
- package/examples/declarative.ts +100 -0
- package/examples/dynamic-config.ts +54 -0
- package/examples/dynamic-info-gatherer.ts +69 -0
- package/examples/dynamic-swml-service.ts +67 -0
- package/examples/gather-info.ts +71 -0
- package/examples/gather-per-question-functions-demo.ts +140 -0
- package/examples/joke-agent.ts +34 -0
- package/examples/kubernetes-agent.ts +45 -0
- package/examples/llm-params.ts +69 -0
- package/examples/mcp-agent.ts +84 -0
- package/examples/mcp-gateway.ts +35 -0
- package/examples/multi-agent.ts +73 -0
- package/examples/multi-endpoint.ts +79 -0
- package/examples/pom-prompt.ts +71 -0
- package/examples/prefab-concierge.ts +47 -0
- package/examples/prefab-faq.ts +54 -0
- package/examples/prefab-info-gatherer.ts +33 -0
- package/examples/prefab-receptionist.ts +36 -0
- package/examples/prefab-survey.ts +68 -0
- package/examples/record-call.ts +67 -0
- package/examples/relay-demo.ts +33 -0
- package/examples/room-and-sip.ts +94 -0
- package/examples/serverless-lambda.ts +35 -0
- package/examples/session-state.ts +83 -0
- package/examples/simple-agent.ts +36 -0
- package/examples/simple-static.ts +29 -0
- package/examples/skills-demo.ts +38 -0
- package/examples/step-function-inheritance-demo.ts +124 -0
- package/examples/swaig-features.ts +187 -0
- package/examples/swml-service-routing.ts +66 -0
- package/examples/swml-service.ts +38 -0
- package/examples/tap.ts +68 -0
- package/examples/verb-methods.ts +45 -0
- package/examples/web-search-multi-instance.ts +72 -0
- package/examples/web-search.ts +38 -0
- package/examples/wikipedia.ts +36 -0
- package/livewire/README.md +140 -0
- package/livewire/docs/migration-guide.md +228 -0
- package/livewire/examples/livewire-basic-agent.ts +74 -0
- package/livewire/examples/livewire-handoff.ts +197 -0
- package/livewire/examples/livewire-multi-tool.ts +117 -0
- package/package.json +38 -0
- package/relay/README.md +70 -0
- package/relay/RELAY_IMPLEMENTATION_GUIDE.md +1257 -0
- package/relay/docs/call-methods.md +474 -0
- package/relay/docs/client-reference.md +142 -0
- package/relay/docs/events.md +134 -0
- package/relay/docs/getting-started.md +134 -0
- package/relay/docs/guide.md +306 -0
- package/relay/docs/messaging.md +182 -0
- package/relay/examples/relay-inbound.ts +66 -0
- package/relay/examples/relay-messaging.ts +71 -0
- package/relay/examples/relay-outbound.ts +76 -0
- package/rest/README.md +95 -0
- package/rest/docs/calling.md +273 -0
- package/rest/docs/client-reference.md +107 -0
- package/rest/docs/compat.md +204 -0
- package/rest/docs/fabric.md +183 -0
- package/rest/docs/getting-started.md +110 -0
- package/rest/docs/guide.md +351 -0
- package/rest/docs/namespaces.md +285 -0
- package/rest/examples/rest-10dlc-registration.ts +161 -0
- package/rest/examples/rest-calling-ivr-and-ai.ts +102 -0
- package/rest/examples/rest-calling-play-and-record.ts +91 -0
- package/rest/examples/rest-client.ts +65 -0
- package/rest/examples/rest-compat-laml.ts +210 -0
- package/rest/examples/rest-datasphere-search.ts +82 -0
- package/rest/examples/rest-fabric-conferences-and-routing.ts +144 -0
- package/rest/examples/rest-fabric-subscribers-and-sip.ts +108 -0
- package/rest/examples/rest-fabric-swml-and-callflows.ts +99 -0
- package/rest/examples/rest-manage-resources.ts +65 -0
- package/rest/examples/rest-phone-number-management.ts +197 -0
- package/rest/examples/rest-queues-mfa-and-recordings.ts +143 -0
- package/rest/examples/rest-video-rooms.ts +186 -0
- package/src/AgentBase.ts +2489 -0
- package/src/AgentServer.ts +415 -0
- package/src/AuthHandler.ts +256 -0
- package/src/ConfigLoader.ts +447 -0
- package/src/ContextBuilder.ts +1150 -0
- package/src/DataMap.ts +449 -0
- package/src/FunctionResult.ts +866 -0
- package/src/Logger.ts +337 -0
- package/src/PomBuilder.ts +439 -0
- package/src/PromptManager.ts +133 -0
- package/src/SWMLHandler.ts +298 -0
- package/src/SWMLService.ts +717 -0
- package/src/SchemaUtils.ts +361 -0
- package/src/SecurityUtils.ts +153 -0
- package/src/ServerlessAdapter.ts +221 -0
- package/src/SessionManager.ts +311 -0
- package/src/SslConfig.ts +118 -0
- package/src/SwaigFunction.ts +276 -0
- package/src/SwmlBuilder.ts +258 -0
- package/src/SwmlVerbMethods.generated.ts +234 -0
- package/src/TypeInference.ts +181 -0
- package/src/WebService.ts +619 -0
- package/src/cli/agent-loader.ts +166 -0
- package/src/cli/mock-data.ts +111 -0
- package/src/cli/swaig-test.ts +452 -0
- package/src/generateVerbTypes.ts +322 -0
- package/src/index.ts +167 -0
- package/src/livewire/index.ts +950 -0
- package/src/prefabs/ConciergeAgent.ts +287 -0
- package/src/prefabs/FAQBotAgent.ts +384 -0
- package/src/prefabs/InfoGathererAgent.ts +339 -0
- package/src/prefabs/ReceptionistAgent.ts +366 -0
- package/src/prefabs/SurveyAgent.ts +646 -0
- package/src/prefabs/index.ts +27 -0
- package/src/relay/Action.ts +314 -0
- package/src/relay/Call.ts +854 -0
- package/src/relay/Deferred.ts +71 -0
- package/src/relay/Message.ts +148 -0
- package/src/relay/RelayClient.ts +1036 -0
- package/src/relay/RelayError.ts +14 -0
- package/src/relay/RelayEvent.ts +892 -0
- package/src/relay/constants.ts +132 -0
- package/src/relay/index.ts +123 -0
- package/src/relay/types.ts +149 -0
- package/src/rest/HttpClient.ts +103 -0
- package/src/rest/RestError.ts +31 -0
- package/src/rest/base/BaseResource.ts +19 -0
- package/src/rest/base/CrudResource.ts +51 -0
- package/src/rest/base/CrudWithAddresses.ts +26 -0
- package/src/rest/index.ts +200 -0
- package/src/rest/namespaces/addresses.ts +32 -0
- package/src/rest/namespaces/calling.ts +187 -0
- package/src/rest/namespaces/chat.ts +20 -0
- package/src/rest/namespaces/compat.ts +352 -0
- package/src/rest/namespaces/datasphere.ts +45 -0
- package/src/rest/namespaces/fabric.ts +222 -0
- package/src/rest/namespaces/imported-numbers.ts +20 -0
- package/src/rest/namespaces/logs.ts +84 -0
- package/src/rest/namespaces/lookup.ts +21 -0
- package/src/rest/namespaces/mfa.ts +30 -0
- package/src/rest/namespaces/number-groups.ts +38 -0
- package/src/rest/namespaces/phone-numbers.ts +44 -0
- package/src/rest/namespaces/project.ts +36 -0
- package/src/rest/namespaces/pubsub.ts +20 -0
- package/src/rest/namespaces/queues.ts +33 -0
- package/src/rest/namespaces/recordings.ts +28 -0
- package/src/rest/namespaces/registry.ts +101 -0
- package/src/rest/namespaces/short-codes.ts +28 -0
- package/src/rest/namespaces/sip-profile.ts +25 -0
- package/src/rest/namespaces/verified-callers.ts +27 -0
- package/src/rest/namespaces/video.ts +165 -0
- package/src/rest/pagination.ts +84 -0
- package/src/rest/types.ts +61 -0
- package/src/schema.json +12250 -0
- package/src/skills/SkillBase.ts +547 -0
- package/src/skills/SkillManager.ts +415 -0
- package/src/skills/SkillRegistry.ts +367 -0
- package/src/skills/builtin/api_ninjas_trivia.ts +280 -0
- package/src/skills/builtin/ask_claude.ts +241 -0
- package/src/skills/builtin/claude_skills.ts +978 -0
- package/src/skills/builtin/custom_skills.ts +312 -0
- package/src/skills/builtin/datasphere.ts +438 -0
- package/src/skills/builtin/datasphere_serverless.ts +339 -0
- package/src/skills/builtin/datetime.ts +130 -0
- package/src/skills/builtin/google_maps.ts +651 -0
- package/src/skills/builtin/index.ts +88 -0
- package/src/skills/builtin/info_gatherer.ts +405 -0
- package/src/skills/builtin/joke.ts +191 -0
- package/src/skills/builtin/math.ts +142 -0
- package/src/skills/builtin/mcp_gateway.ts +677 -0
- package/src/skills/builtin/native_vector_search.ts +901 -0
- package/src/skills/builtin/play_background_file.ts +358 -0
- package/src/skills/builtin/spider.ts +869 -0
- package/src/skills/builtin/swml_transfer.ts +635 -0
- package/src/skills/builtin/weather_api.ts +248 -0
- package/src/skills/builtin/web_search.ts +1074 -0
- package/src/skills/builtin/wikipedia_search.ts +299 -0
- package/src/skills/index.ts +12 -0
- package/src/types.ts +132 -0
- package/tests/AgentBase.test.ts +1093 -0
- package/tests/AgentServer.test.ts +126 -0
- package/tests/AuthHandler.test.ts +133 -0
- package/tests/ConfigLoader.test.ts +151 -0
- package/tests/ContextBuilder.test.ts +108 -0
- package/tests/DataMap.test.ts +367 -0
- package/tests/EphemeralSkillCopy.test.ts +107 -0
- package/tests/FunctionResult.test.ts +298 -0
- package/tests/GracefulShutdown.test.ts +46 -0
- package/tests/Logger.test.ts +420 -0
- package/tests/PomBuilder.test.ts +228 -0
- package/tests/ProxyDetection.test.ts +228 -0
- package/tests/SWMLService.test.ts +320 -0
- package/tests/SWMLVerbHandler.test.ts +523 -0
- package/tests/SchemaUtils.test.ts +106 -0
- package/tests/SchemaUtils.verb.test.ts +206 -0
- package/tests/SecurityUtils.test.ts +192 -0
- package/tests/ServerlessAdapter.test.ts +222 -0
- package/tests/SessionManager.test.ts +257 -0
- package/tests/SkillBaseFeatures.test.ts +130 -0
- package/tests/SkillMultiInstance.test.ts +102 -0
- package/tests/SkillParameterSchemas.test.ts +134 -0
- package/tests/SkillRegistrySchema.test.ts +84 -0
- package/tests/SslConfig.test.ts +97 -0
- package/tests/SwmlBuilder.test.ts +400 -0
- package/tests/TypeInference.test.ts +165 -0
- package/tests/VerbHandlerRegistry.test.ts +128 -0
- package/tests/cli/mock-data.test.ts +113 -0
- package/tests/cli/swaig-test.test.ts +108 -0
- package/tests/examples.test.ts +194 -0
- package/tests/fixtures/scrape-parity/README.md +53 -0
- package/tests/fixtures/scrape-parity/expected/01_simple_article.json +5 -0
- package/tests/fixtures/scrape-parity/expected/02_class_based_noise.json +5 -0
- package/tests/fixtures/scrape-parity/expected/03_nested_containers.json +5 -0
- package/tests/fixtures/scrape-parity/expected/04_bare_body.json +5 -0
- package/tests/fixtures/scrape-parity/expected/05_malformed.json +5 -0
- package/tests/fixtures/scrape-parity/expected/06_multi_class.json +5 -0
- package/tests/fixtures/scrape-parity/expected/07_anchor_pattern.json +5 -0
- package/tests/fixtures/scrape-parity/expected/08_inline_script.json +5 -0
- package/tests/fixtures/scrape-parity/expected/09_whitespace_nbsp.json +5 -0
- package/tests/fixtures/scrape-parity/expected/10_entity_unicode.json +5 -0
- package/tests/fixtures/scrape-parity/expected/11_cdata_comments.json +5 -0
- package/tests/fixtures/scrape-parity/expected/12_deep_nested_removals.json +5 -0
- package/tests/fixtures/scrape-parity/html/01_simple_article.html +18 -0
- package/tests/fixtures/scrape-parity/html/02_class_based_noise.html +18 -0
- package/tests/fixtures/scrape-parity/html/03_nested_containers.html +13 -0
- package/tests/fixtures/scrape-parity/html/04_bare_body.html +9 -0
- package/tests/fixtures/scrape-parity/html/05_malformed.html +11 -0
- package/tests/fixtures/scrape-parity/html/06_multi_class.html +18 -0
- package/tests/fixtures/scrape-parity/html/07_anchor_pattern.html +12 -0
- package/tests/fixtures/scrape-parity/html/08_inline_script.html +17 -0
- package/tests/fixtures/scrape-parity/html/09_whitespace_nbsp.html +21 -0
- package/tests/fixtures/scrape-parity/html/10_entity_unicode.html +10 -0
- package/tests/fixtures/scrape-parity/html/11_cdata_comments.html +13 -0
- package/tests/fixtures/scrape-parity/html/12_deep_nested_removals.html +24 -0
- package/tests/fixtures/scrape-parity/python_extract.py +109 -0
- package/tests/livewire/livewire.test.ts +780 -0
- package/tests/mcp.test.ts +221 -0
- package/tests/prefabs/prefabs.test.ts +1093 -0
- package/tests/relay/Action.test.ts +392 -0
- package/tests/relay/Call.test.ts +535 -0
- package/tests/relay/Deferred.test.ts +71 -0
- package/tests/relay/Message.test.ts +164 -0
- package/tests/relay/RelayClient.test.ts +779 -0
- package/tests/relay/RelayEvent.test.ts +463 -0
- package/tests/relay/helpers.ts +79 -0
- package/tests/rest/HttpClient.test.ts +274 -0
- package/tests/rest/RestError.test.ts +53 -0
- package/tests/rest/calling.test.ts +156 -0
- package/tests/rest/client.test.ts +197 -0
- package/tests/rest/compat.test.ts +335 -0
- package/tests/rest/datasphere.test.ts +71 -0
- package/tests/rest/fabric.test.ts +186 -0
- package/tests/rest/helpers.ts +95 -0
- package/tests/rest/logs.test.ts +68 -0
- package/tests/rest/pagination.test.ts +133 -0
- package/tests/rest/registry.test.ts +94 -0
- package/tests/rest/relay-rest.test.ts +290 -0
- package/tests/rest/video.test.ts +173 -0
- package/tests/setup.ts +6 -0
- package/tests/skills/SkillBase.test.ts +108 -0
- package/tests/skills/SkillManager.test.ts +268 -0
- package/tests/skills/SkillRegistry.test.ts +176 -0
- package/tests/skills/builtin.test.ts +1472 -0
- package/tests/skills/claude-skills.test.ts +54 -0
- package/tests/skills/custom-skills.test.ts +53 -0
- package/tests/skills/datasphere-serverless.test.ts +70 -0
- package/tests/skills/datasphere.test.ts +107 -0
- package/tests/skills/datetime.test.ts +101 -0
- package/tests/skills/google-maps.test.ts +78 -0
- package/tests/skills/info-gatherer.test.ts +411 -0
- package/tests/skills/joke.test.ts +81 -0
- package/tests/skills/math.test.ts +68 -0
- package/tests/skills/mcp-gateway.test.ts +101 -0
- package/tests/skills/play-background.test.ts +54 -0
- package/tests/skills/spider.test.ts +108 -0
- package/tests/skills/swml-transfer.test.ts +178 -0
- package/tests/skills/trivia.test.ts +54 -0
- package/tests/skills/vector-search.test.ts +135 -0
- package/tests/skills/weather-api.test.ts +77 -0
- package/tests/skills/web-search-parity.test.ts +59 -0
- package/tests/skills/web-search.test.ts +103 -0
- package/tests/skills/wikipedia.test.ts +63 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE — do not edit manually.
|
|
3
|
+
* Generated by: npx tsx src/generateVerbTypes.ts
|
|
4
|
+
*
|
|
5
|
+
* Provides TypeScript interface augmentation for all SWML verb methods
|
|
6
|
+
* auto-installed on SwmlBuilder from schema.json.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
10
|
+
|
|
11
|
+
export interface AiVerbConfig {
|
|
12
|
+
/** Text prompt for the AI agent (mutually exclusive with prompt when using POM). */
|
|
13
|
+
prompt?: string | Array<Record<string, unknown>>;
|
|
14
|
+
/** Optional post-prompt text sent to the LLM after the conversation ends. */
|
|
15
|
+
post_prompt?: string;
|
|
16
|
+
/** URL to receive post-prompt status callbacks. */
|
|
17
|
+
post_prompt_url?: string;
|
|
18
|
+
/** SignalWire AI Gateway (SWAIG) configuration for custom function/tool definitions. */
|
|
19
|
+
SWAIG?: Record<string, unknown>;
|
|
20
|
+
/** Additional AI parameters passed through to the platform. */
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PlayVerbConfig {
|
|
25
|
+
/** Single URL to play (mutually exclusive with urls). */
|
|
26
|
+
url?: string;
|
|
27
|
+
/** Array of URLs to play (mutually exclusive with url). */
|
|
28
|
+
urls?: string[];
|
|
29
|
+
/** Volume level for audio playback. Valid range -40 to 40. Default 0. */
|
|
30
|
+
volume?: number;
|
|
31
|
+
/** Voice name to use for text-to-speech (e.g. "Polly.Joanna"). */
|
|
32
|
+
say_voice?: string;
|
|
33
|
+
/** Language code for text-to-speech (e.g. "en-US"). */
|
|
34
|
+
say_language?: string;
|
|
35
|
+
/** Gender for text-to-speech ("male" or "female"). */
|
|
36
|
+
say_gender?: string;
|
|
37
|
+
/** If true, auto-answer the call before playing audio. Default true. */
|
|
38
|
+
auto_answer?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare module './SwmlBuilder.js' {
|
|
42
|
+
interface SwmlBuilder {
|
|
43
|
+
/** Answer incoming call and set an optional maximum duration. */
|
|
44
|
+
answer(config?: { /** Maximum duration in seconds for the call. Defaults to `14400` seconds (4 hours). */
|
|
45
|
+
max_duration?: number; /** Comma-separated string of codecs to offer. Valid codecs are: PCMU, PCMA, G722, G729, AMR-WB, OPUS, VP8, H264. */
|
|
46
|
+
codecs?: string; /** Username to use for SIP authentication. */
|
|
47
|
+
username?: string; /** Password to use for SIP authentication. */
|
|
48
|
+
password?: string }): this;
|
|
49
|
+
/** Creates an AI agent that conducts voice conversations using automatic speech recognition (ASR), large language models (LLMs), and text-to-speech (TTS) synthesis. The agent processes caller speech in real-time, generates contextually appropriate responses, and can execute custom functions to interact with external systems through SignalWire AI Gateway (SWAIG). */
|
|
50
|
+
ai(config?: AiVerbConfig): this;
|
|
51
|
+
/** Creates a new Bedrock AI Agent */
|
|
52
|
+
amazon_bedrock(config?: unknown): this;
|
|
53
|
+
/** Execute a sequence of instructions depending on the value of a JavaScript condition. */
|
|
54
|
+
cond(config?: Record<string, unknown>): this;
|
|
55
|
+
/** Dial a SIP URI or phone number. */
|
|
56
|
+
connect(config: Record<string, unknown>): this;
|
|
57
|
+
/** Start noise reduction. You can stop it at any time using `stop_denoise`. */
|
|
58
|
+
denoise(config?: Record<string, unknown>): this;
|
|
59
|
+
/** Place the current call in a named queue where it will wait to be connected to an available agent or resource. While waiting, callers will hear music or custom audio. When an agent connects to the queue (using the connect method), the caller and agent are bridged together. After the bridge completes, execution continues with the SWML script specified in transfer_after_bridge. */
|
|
60
|
+
enter_queue(config?: unknown): this;
|
|
61
|
+
/** Execute a specified section or URL as a subroutine, and upon completion, return to the current document. Use the return statement to pass any return values or objects back to the current document. */
|
|
62
|
+
execute(config: { /** Specifies what to execute. The value can be one of: - `<section_name>` - section in the current document to execute - A URL (http or https) that returns a SWML document - Sends HTTP POST - An inline SWML document (as a JSON string) */
|
|
63
|
+
dest: string; /** Named parameters to send to section or URL */
|
|
64
|
+
params?: Record<string, unknown>; /** User-defined metadata, ignored by SignalWire */
|
|
65
|
+
meta?: Record<string, unknown>; /** The list of SWML instructions to be executed when the executed section or URL returns */
|
|
66
|
+
on_return?: unknown[]; /** Action to take based on the result of the call. This will run once the peer leg of the call has ended. Will use the switch method when the return_value is an object, and will use the cond method when the return_value is an array. */
|
|
67
|
+
result?: unknown[] }): this;
|
|
68
|
+
/** Jump to a label within the current section, optionally based on a condition. The goto method will only navigate to a label within the same section. */
|
|
69
|
+
goto(config: { /** Mark any point of the SWML section with a label so that goto can jump to it. */
|
|
70
|
+
label: string; /** A JavaScript condition that determines whether to perform the jump. If the condition evaluates to true, the jump is executed. If omitted, the jump is unconditional. */
|
|
71
|
+
when?: string; /** The maximum number of times to perform the jump. Must be a number between 1 and 100. Default `100`. */
|
|
72
|
+
max?: number }): this;
|
|
73
|
+
/** Mark any point of the SWML section with a label so that goto can jump to it. */
|
|
74
|
+
label(value: string): this;
|
|
75
|
+
/** Start live transcription of the call. The transcription will be sent to the specified webhook URL. */
|
|
76
|
+
live_transcribe(config: { /** The action to perform during live transcription. */
|
|
77
|
+
action: unknown }): this;
|
|
78
|
+
/** Start live translation of the call. The translation will be sent to the specified webhook URL. */
|
|
79
|
+
live_translate(config: { /** The action to perform during live translation. */
|
|
80
|
+
action: unknown }): this;
|
|
81
|
+
/** End the call with an optional reason. */
|
|
82
|
+
hangup(config?: { /** The reason for hanging up the call. */
|
|
83
|
+
reason?: string }): this;
|
|
84
|
+
/** Join a RELAY room. If the room doesn't exist, it creates a new room. */
|
|
85
|
+
join_room(config: { /** Name of the room to join. Allowed characters: A-Z, a-z, 0-9, underscore, and hyphen. */
|
|
86
|
+
name: string }): this;
|
|
87
|
+
/** Join an ad-hoc audio conference started on either the SignalWire or Compatibility API. This method allows you to connect the current call to a named conference where multiple participants can communicate simultaneously. */
|
|
88
|
+
join_conference(config?: unknown): this;
|
|
89
|
+
/** Play file(s), ringtones, speech or silence. */
|
|
90
|
+
play(config?: PlayVerbConfig): this;
|
|
91
|
+
/** Play a prompt and wait for input. The input can be received either as digits from the keypad, or from speech, or both depending on what parameters are set. By default, only digit input is enabled. To enable speech input, set at least one speech parameter. To enable both digit and speech input, set at least one parameter for each. */
|
|
92
|
+
prompt(config: { /** URL or array of URLs to play. Allowed URLs are: http:// or https:// - audio file to GET ring:[duration:]<country code> - ring tone to play. For example: ring:us to play single ring or ring:20.0:us to play ring for 20 seconds. say:<text to speak> - Sentence to say silence: <duration> - seconds of silence to play */
|
|
93
|
+
play: unknown[]; /** Volume level for the audio file. Default is `0`. Valid range is -40 to 40. */
|
|
94
|
+
volume?: number; /** The voice to use for the text to speech. */
|
|
95
|
+
say_voice?: string; /** The language to use for the text to speech. */
|
|
96
|
+
say_language?: string; /** The gender to use for the text to speech. */
|
|
97
|
+
say_gender?: string; /** Number of digits to collect. Default is `1`. */
|
|
98
|
+
max_digits?: number; /** Digits that terminate digit collection. Default is not set. */
|
|
99
|
+
terminators?: string; /** Time in seconds to wait for next digit. Default is `5.0` seconds. */
|
|
100
|
+
digit_timeout?: number; /** Time in seconds to wait for start of input. Default is `5.0` seconds. */
|
|
101
|
+
initial_timeout?: number; /** Max time in seconds to wait for speech result. */
|
|
102
|
+
speech_timeout?: number; /** Time in seconds to wait for end of speech utterance. */
|
|
103
|
+
speech_end_timeout?: number; /** Language to detect speech in. */
|
|
104
|
+
speech_language?: string; /** Expected words or phrases to help the speech recognition. */
|
|
105
|
+
speech_hints?: string[] | unknown[]; /** The engine that is selected for speech recognition. The engine must support the specified language. [Deepgram|Google| etc...] Default is not set (SignalWire picks the engine). */
|
|
106
|
+
speech_engine?: string; /** http or https URL to deliver prompt status events */
|
|
107
|
+
status_url?: string }): this;
|
|
108
|
+
/** Receive a fax being delivered to this call. */
|
|
109
|
+
receive_fax(config?: { /** http or https URL to deliver receive_fax status events */
|
|
110
|
+
status_url?: string }): this;
|
|
111
|
+
/** Record the call audio in the foreground, pausing further SWML execution until recording ends. Use this, for example, to record voicemails. To record calls in the background in a non-blocking fashion, use the record_call method. */
|
|
112
|
+
record(config?: { /** If true, record in stereo. Default is `false`. */
|
|
113
|
+
stereo?: boolean; /** The format to record in. Can be `wav`, `mp3`, or `mp4`. Default is `"wav"`. */
|
|
114
|
+
format?: 'wav' | 'mp3' | 'mp4'; /** Direction of the audio to record: "speak" for what party says, "listen" for what party hears. Default is `"speak"`. */
|
|
115
|
+
direction?: 'speak' | 'listen'; /** String of digits that will stop the recording when pressed. Default is `"#"`. */
|
|
116
|
+
terminators?: string; /** Play a beep before recording. Default is `false`. */
|
|
117
|
+
beep?: boolean; /** How sensitive the recording voice activity detector is to background noise. A larger value is more sensitive. Allowed values from 0.0 to 100.0. Default is `44.0`. */
|
|
118
|
+
input_sensitivity?: number; /** Time in seconds to wait for the start of speech. Default is `4.0` seconds. */
|
|
119
|
+
initial_timeout?: number; /** Time in seconds to wait in silence before ending the recording. Default is `5.0` seconds. */
|
|
120
|
+
end_silence_timeout?: number; /** Maximum length of the recording in seconds. */
|
|
121
|
+
max_length?: number; /** URL to send recording status events to. */
|
|
122
|
+
status_url?: string }): this;
|
|
123
|
+
/** Record call in the background. Unlike the record method, the record_call method will start the recording and continue executing the SWML script while allowing the recording to happen in the background. To stop call recordings started with record_call, use the stop_record_call method. */
|
|
124
|
+
record_call(config?: { /** Identifier for this recording, to use with `stop_call_record`. */
|
|
125
|
+
control_id?: string; /** If `true`, record in stereo. Default is `false`. */
|
|
126
|
+
stereo?: boolean; /** The format to record in. It can be `wav`, `mp3`, or `mp4`. Default is `"wav"`. */
|
|
127
|
+
format?: 'wav' | 'mp3' | 'mp4'; /** Direction of the audio to record: "speak" for what party says, "listen" for what party hears, "both" for what the party hears and says. Default is `"both"`. */
|
|
128
|
+
direction?: 'speak' | 'listen' | 'both'; /** String of digits that will stop the recording when pressed. Default is `""` (empty). */
|
|
129
|
+
terminators?: string; /** Play a beep before recording. Default is `false`. */
|
|
130
|
+
beep?: boolean; /** How sensitive the recording voice activity detector is to background noise. A larger value is more sensitive. Allowed values from 0.0 to 100.0. Default is `44.0`. */
|
|
131
|
+
input_sensitivity?: number; /** Time in seconds to wait for the start of speech. Default is `0.0` seconds. */
|
|
132
|
+
initial_timeout?: number; /** Time in seconds to wait in silence before ending the recording. Default is `0.0` seconds. */
|
|
133
|
+
end_silence_timeout?: number; /** Maximum length of the recording in seconds. */
|
|
134
|
+
max_length?: number; /** http or https URL to deliver record_call status events */
|
|
135
|
+
status_url?: string }): this;
|
|
136
|
+
/** Send a GET, POST, PUT, or DELETE request to a remote URL. */
|
|
137
|
+
request(config: { /** URL to send the HTTPS request to. Authentication can also be set in the URL in the format of username:password@url. */
|
|
138
|
+
url: string; /** The HTTP method to be used for the request. Can be `GET`, `POST`, `PUT`, or `DELETE`. */
|
|
139
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE'; /** Object containing HTTP headers to set. Valid header values are Accept, Authorization, Content-Type, Range, and custom X- headers. */
|
|
140
|
+
headers?: Record<string, unknown>; /** Request body. Content-Type header should be explicitly set, but if not set, the most likely type will be set based on the first non-whitespace character. */
|
|
141
|
+
body?: string | Record<string, unknown>; /** Maximum time in seconds to wait for a response. Default is `0` (no timeout). */
|
|
142
|
+
timeout?: number; /** Maximum time in seconds to wait for a connection. Default is `0` (no timeout). */
|
|
143
|
+
connect_timeout?: number; /** Store parsed JSON response as variables. Default is `false`. */
|
|
144
|
+
save_variables?: boolean }): this;
|
|
145
|
+
/** Return a value from an execute call or exit the script. The value can be any type. */
|
|
146
|
+
return(config?: unknown): this;
|
|
147
|
+
/** Send digit presses as DTMF tones. */
|
|
148
|
+
send_digits(config: { /** The digits to send. Valid values are 0123456789*#ABCDWw. Character W is a 1 second delay, and w is a 500ms delay. */
|
|
149
|
+
digits: string }): this;
|
|
150
|
+
/** Send a fax. */
|
|
151
|
+
send_fax(config: { /** URL to the PDF document to fax. */
|
|
152
|
+
document: string; /** Header text to include on the fax. */
|
|
153
|
+
header_info?: string; /** Station identity to report. Default is the calling party's caller ID number. */
|
|
154
|
+
identity?: string; /** http or https URL to deliver send_fax status events */
|
|
155
|
+
status_url?: string }): this;
|
|
156
|
+
/** Send an outbound SMS or MMS message to a PSTN phone number. */
|
|
157
|
+
send_sms(config: Record<string, unknown> | number): this;
|
|
158
|
+
/** Set script variables to the specified values. Accepts an object mapping variable names to values. Variables set using set can be removed using unset. */
|
|
159
|
+
set(config?: Record<string, unknown>): this;
|
|
160
|
+
/** Pause execution for a specified duration. */
|
|
161
|
+
sleep(durationOrConfig: number | { duration: number }): this;
|
|
162
|
+
/** Send SIP REFER to a SIP call. */
|
|
163
|
+
sip_refer(config: { /** The SIP URI to send the REFER to. */
|
|
164
|
+
to_uri: string; /** The HTTP or HTTPS URL to send status callback events to. */
|
|
165
|
+
status_url?: string; /** Username to use for SIP authentication. */
|
|
166
|
+
username?: string; /** Password to use for SIP authentication. */
|
|
167
|
+
password?: string }): this;
|
|
168
|
+
/** Stop noise reduction that was started with denoise. */
|
|
169
|
+
stop_denoise(config?: Record<string, unknown>): this;
|
|
170
|
+
/** Stop an active background recording. */
|
|
171
|
+
stop_record_call(config?: { /** Identifier for the recording to stop. If not set, the last recording started will be stopped. */
|
|
172
|
+
control_id?: string }): this;
|
|
173
|
+
/** Stop an active tap stream. */
|
|
174
|
+
stop_tap(config?: { /** ID of the tap to stop. If not set, it will shut off the most recent tap session. */
|
|
175
|
+
control_id?: string }): this;
|
|
176
|
+
/** Execute different instructions based on a variable's value. */
|
|
177
|
+
switch(config: { /** Name of the variable whose value needs to be compared. */
|
|
178
|
+
variable: string; /** Object of key-mapped values to array of SWML methods to execute. */
|
|
179
|
+
case: Record<string, unknown>; /** Array of SWML methods to execute if no cases match. */
|
|
180
|
+
default?: unknown[] }): this;
|
|
181
|
+
/** Start background call tap. Media is streamed over Websocket or RTP to customer controlled URI. */
|
|
182
|
+
tap(config: { /** Destination of the tap media stream: rtp://IP:port, ws://example.com, or wss://example.com. */
|
|
183
|
+
uri: string; /** Identifier for this tap to use with `stop_tap`. */
|
|
184
|
+
control_id?: string; /** Direction of the audio to tap: `speak` for what party says, `listen` for what party hears, `both` for what party hears and says. Default is `"speak"`. */
|
|
185
|
+
direction?: 'speak' | 'listen' | 'both'; /** Codec to use for the tap media stream. Possible Values: [`PCMU`, `PCMA`] Default is `"PCMU"`. */
|
|
186
|
+
codec?: 'PCMU' | 'PCMA'; /** If `uri` is a `rtp://` this will set the packetization time of the media in milliseconds. Default is `20` milliseconds. */
|
|
187
|
+
rtp_ptime?: number; /** http or https URL to deliver tap status events */
|
|
188
|
+
status_url?: string }): this;
|
|
189
|
+
/** Transfer the execution of the script to a different SWML section, URL, or Relay application. Once the transfer is complete, the script will continue executing SWML from the new location. */
|
|
190
|
+
transfer(config: { /** Specifies where to transfer to. The value can be one of: - <section_name> - section in the SWML document to jump to - A URL (http or https) - URL to fetch next document from. Sends HTTP POST. Authentication can also be set in the URL in the format of username:password@url. - An inline SWML document (as a JSON string) */
|
|
191
|
+
dest: string; /** Named parameters to send to transfer destination. Accepts an object mapping variable names to values. Default is not set. */
|
|
192
|
+
params?: Record<string, unknown>; /** User data, ignored by SignalWire. Accepts an object mapping variable names to values. Default is not set. */
|
|
193
|
+
meta?: Record<string, unknown> }): this;
|
|
194
|
+
/** Unset specified variables. The variables may have been set using the set method or as a byproduct of other statements or methods. Accepts a single variable name as a string or an array of variable names. */
|
|
195
|
+
unset(config: Record<string, unknown> | number): this;
|
|
196
|
+
/** Enables secure payment processing during voice calls. When implemented, it manages the entire payment flow including data collection, validation, and processing through your configured payment gateway. */
|
|
197
|
+
pay(config: { /** The URL to make POST requests with all the gathered payment details. This URL is used to process the final payment transaction and return the results through the response. Visit https://developer.signalwire.com/swml/methods/pay/payment_connector_url for more important information. */
|
|
198
|
+
payment_connector_url: string; /** The amount to charge against payment method passed in the request. `Float` value with no currency prefix passed as string. */
|
|
199
|
+
charge_amount?: string; /** Uses the ISO 4217 currency code of the charge amount. */
|
|
200
|
+
currency?: string; /** Custom description of the payment provided in the request. */
|
|
201
|
+
description?: string; /** The method of how to collect the payment details. Currently only `dtmf` mode is supported. */
|
|
202
|
+
input?: 'dtmf'; /** Language to use for prompts being played to the caller by the `pay` method. */
|
|
203
|
+
language?: string; /** Number of times the `pay` method will retry to collect payment details. */
|
|
204
|
+
max_attempts?: number; /** The minimum length of the postal code the user must enter. */
|
|
205
|
+
min_postal_code_length?: number; /** Array of parameter objects to pass to your payment processor. The parameters are user-defined key-value pairs. */
|
|
206
|
+
parameters?: unknown[]; /** Indicates the payment method which is going to be used in this payment request. Currently only `credit-card` is supported. */
|
|
207
|
+
payment_method?: 'credit-card'; /** Takes `true`, `false` or real postalcode (if it's known beforehand) to let pay method know whether to prompt for postal code. Default is `true`. */
|
|
208
|
+
postal_code?: boolean | string; /** Array of prompt objects for customizing the audio prompts during different stages of the payment process. */
|
|
209
|
+
prompts?: unknown[]; /** Takes true or false to let pay method know whether to prompt for security code. */
|
|
210
|
+
security_code?: boolean; /** The URL to send requests for each status change during the payment process. See https://developer.signalwire.com/swml/methods/pay#status_url_request_body for more important information. */
|
|
211
|
+
status_url?: string; /** Limit in seconds that pay method waits for the caller to press another digit before moving on to validate the digits captured. */
|
|
212
|
+
timeout?: number; /** Whether the payment is a one off payment or re-occurring. Allowed values: - `one-time` - `reusable` */
|
|
213
|
+
token_type?: 'one-time' | 'reusable'; /** List of payment cards allowed to use in the requested payment process separated by space. Allowed values: - `visa` - `mastercard` - `amex` - `maestro` - `discover` - `jcb` - `diners-club` */
|
|
214
|
+
valid_card_types?: string; /** Text-to-speech voice to use. Please refer to https://developer.signalwire.com/voice/getting-started/voice-and-languages for more information. */
|
|
215
|
+
voice?: string }): this;
|
|
216
|
+
/** A detection method that combines AMD (Answering Machine Detection) and fax detection. Detect whether the user on the other end of the call is a machine (fax, voicemail, etc.) or a human. The detection result(s) will be sent to the specified status_url as a POST request and will also be saved in the detect_result variable. */
|
|
217
|
+
detect_machine(config?: { /** If `true`, stops detection on beep / end of voicemail greeting. Default `false`. */
|
|
218
|
+
detect_message_end?: boolean; /** Comma-separated string of detectors to enable. Valid values: `amd`, `fax`. */
|
|
219
|
+
detectors?: string; /** How long to wait for voice to finish. Default `1.0`. */
|
|
220
|
+
end_silence_timeout?: number; /** How long to wait for initial voice before giving up. Default `4.5`. */
|
|
221
|
+
initial_timeout?: number; /** How long to wait for voice to finish before firing READY event. Default is `end_silence_timeout`. */
|
|
222
|
+
machine_ready_timeout?: number; /** The number of seconds of ongoing voice activity required to classify as MACHINE. Default `1.25`. */
|
|
223
|
+
machine_voice_threshold?: number; /** The minimum number of words that must be detected in a single utterance before classifying the call as MACHINE. Default `6`. */
|
|
224
|
+
machine_words_threshold?: number; /** The http(s) URL to deliver detector events to. */
|
|
225
|
+
status_url?: string; /** The max time to run detector. Default `30.0` seconds. */
|
|
226
|
+
timeout?: number; /** The tone to detect, will only receive remote side tone. Default `CED`. */
|
|
227
|
+
tone?: 'CED' | 'CNG'; /** If false, the detector will run asynchronously and status_url must be set. If true, the detector will wait for detection to complete before moving to the next SWML instruction. Default is `true`. */
|
|
228
|
+
wait?: boolean }): this;
|
|
229
|
+
/** Allows the user to set and send events to the connected client on the call. This is useful for triggering actions on the client side. Commonly used with the [browser-sdk](https://developer.signalwire.com/sdks/reference/browser-sdk/SignalWire%20Client/). The event object can be any valid JSON object. Any key-value pair in the object is sent to the client as an event type called `user_event`. */
|
|
230
|
+
user_event(config: { event: Record<string, unknown> }): this;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeInference - Runtime schema inference and typed handler wrapping.
|
|
3
|
+
*
|
|
4
|
+
* Extracts parameter names and default values from function source code,
|
|
5
|
+
* infers JSON Schema types from defaults, and creates wrapper functions
|
|
6
|
+
* that unpack args dicts into named positional parameters.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { SwaigHandler } from './SwaigFunction.js';
|
|
10
|
+
|
|
11
|
+
/** A parsed function parameter with optional default value. */
|
|
12
|
+
export interface ParsedParam {
|
|
13
|
+
name: string;
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Result of schema inference from a function. */
|
|
18
|
+
export interface InferredSchema {
|
|
19
|
+
/** JSON Schema properties keyed by parameter name. */
|
|
20
|
+
parameters: Record<string, { type: string; description?: string }>;
|
|
21
|
+
/** List of required parameter names (those without defaults). */
|
|
22
|
+
required: string[];
|
|
23
|
+
/** Ordered parameter names (excluding rawData). */
|
|
24
|
+
paramNames: string[];
|
|
25
|
+
/** Whether the function accepts a rawData parameter. */
|
|
26
|
+
hasRawData: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parse function parameter names and default values from source code.
|
|
31
|
+
*
|
|
32
|
+
* Handles arrow functions, regular functions, and method shorthand.
|
|
33
|
+
* Returns an array of { name, defaultValue? } objects.
|
|
34
|
+
*/
|
|
35
|
+
export function parseFunctionParams(source: string): ParsedParam[] {
|
|
36
|
+
// Extract the parameter list between the first set of parens
|
|
37
|
+
// Handle: function f(a, b) {}, (a, b) => {}, async (a, b) => {}
|
|
38
|
+
const match = source.match(/^[^(]*\(([^)]*)\)/);
|
|
39
|
+
if (!match) return [];
|
|
40
|
+
|
|
41
|
+
const paramStr = match[1].trim();
|
|
42
|
+
if (!paramStr) return [];
|
|
43
|
+
|
|
44
|
+
const params: ParsedParam[] = [];
|
|
45
|
+
// Split on commas, but respect nested structures (not needed for simple params)
|
|
46
|
+
let depth = 0;
|
|
47
|
+
let current = '';
|
|
48
|
+
for (let i = 0; i < paramStr.length; i++) {
|
|
49
|
+
const ch = paramStr[i];
|
|
50
|
+
if (ch === '(' || ch === '[' || ch === '{') depth++;
|
|
51
|
+
else if (ch === ')' || ch === ']' || ch === '}') depth--;
|
|
52
|
+
else if (ch === ',' && depth === 0) {
|
|
53
|
+
params.push(parseOneParam(current.trim()));
|
|
54
|
+
current = '';
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
current += ch;
|
|
58
|
+
}
|
|
59
|
+
if (current.trim()) {
|
|
60
|
+
params.push(parseOneParam(current.trim()));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return params;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseOneParam(param: string): ParsedParam {
|
|
67
|
+
// Strip TypeScript type annotations: `name: type = default` or `name: type`
|
|
68
|
+
// We need to handle `name = default` and `name: Type = default`
|
|
69
|
+
const eqIdx = param.indexOf('=');
|
|
70
|
+
if (eqIdx !== -1) {
|
|
71
|
+
const beforeEq = param.slice(0, eqIdx).trim();
|
|
72
|
+
const defaultValue = param.slice(eqIdx + 1).trim();
|
|
73
|
+
// beforeEq might be "name: Type" — extract just the name
|
|
74
|
+
const name = extractParamName(beforeEq);
|
|
75
|
+
return { name, defaultValue };
|
|
76
|
+
}
|
|
77
|
+
// No default — might have type annotation
|
|
78
|
+
const name = extractParamName(param);
|
|
79
|
+
return { name };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function extractParamName(expr: string): string {
|
|
83
|
+
// Handle "name: Type" — take everything before the colon
|
|
84
|
+
const colonIdx = expr.indexOf(':');
|
|
85
|
+
if (colonIdx !== -1) {
|
|
86
|
+
return expr.slice(0, colonIdx).trim();
|
|
87
|
+
}
|
|
88
|
+
return expr.trim();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Infer a JSON Schema from a function's parameters.
|
|
93
|
+
*
|
|
94
|
+
* Returns null if the function appears to be an old-style `(args, rawData)` handler.
|
|
95
|
+
* Otherwise, extracts parameter names and infers types from default values:
|
|
96
|
+
* - Number literals → "integer" (for integers) or "number" (for floats)
|
|
97
|
+
* - String literals → "string"
|
|
98
|
+
* - Boolean literals → "boolean"
|
|
99
|
+
* - No default → "string" (and marked required)
|
|
100
|
+
*/
|
|
101
|
+
export function inferSchema(fn: Function): InferredSchema | null {
|
|
102
|
+
const source = fn.toString();
|
|
103
|
+
const parsed = parseFunctionParams(source);
|
|
104
|
+
|
|
105
|
+
if (parsed.length === 0) {
|
|
106
|
+
return { parameters: {}, required: [], paramNames: [], hasRawData: false };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Detection heuristic: if the function looks like an old-style handler
|
|
110
|
+
// with (args, rawData) or (args) pattern, return null
|
|
111
|
+
if (parsed.length <= 2) {
|
|
112
|
+
const firstName = parsed[0].name;
|
|
113
|
+
if (firstName === 'args' || firstName === 'arguments') {
|
|
114
|
+
// This is likely old-style (args, rawData) — skip inference
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Check if last param is rawData
|
|
120
|
+
const hasRawData = parsed.length > 0 && parsed[parsed.length - 1].name === 'rawData';
|
|
121
|
+
const schemaParams = hasRawData ? parsed.slice(0, -1) : parsed;
|
|
122
|
+
|
|
123
|
+
const parameters: Record<string, { type: string; description?: string }> = {};
|
|
124
|
+
const required: string[] = [];
|
|
125
|
+
const paramNames: string[] = [];
|
|
126
|
+
|
|
127
|
+
for (const p of schemaParams) {
|
|
128
|
+
paramNames.push(p.name);
|
|
129
|
+
const inferredType = inferTypeFromDefault(p.defaultValue);
|
|
130
|
+
parameters[p.name] = { type: inferredType, description: `The ${p.name} parameter` };
|
|
131
|
+
if (p.defaultValue === undefined) {
|
|
132
|
+
required.push(p.name);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return { parameters, required, paramNames, hasRawData };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function inferTypeFromDefault(defaultValue?: string): string {
|
|
140
|
+
if (defaultValue === undefined) return 'string';
|
|
141
|
+
|
|
142
|
+
const trimmed = defaultValue.trim();
|
|
143
|
+
|
|
144
|
+
// Boolean
|
|
145
|
+
if (trimmed === 'true' || trimmed === 'false') return 'boolean';
|
|
146
|
+
|
|
147
|
+
// Number: integer vs float
|
|
148
|
+
if (/^-?\d+$/.test(trimmed)) return 'integer';
|
|
149
|
+
if (/^-?\d+\.\d+$/.test(trimmed)) return 'number';
|
|
150
|
+
|
|
151
|
+
// String (quoted)
|
|
152
|
+
if ((trimmed.startsWith("'") && trimmed.endsWith("'")) ||
|
|
153
|
+
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
154
|
+
(trimmed.startsWith('`') && trimmed.endsWith('`'))) {
|
|
155
|
+
return 'string';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Default fallback
|
|
159
|
+
return 'string';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Create a wrapper function that adapts a typed handler to the standard
|
|
164
|
+
* `(args, rawData) => result` SWAIG handler signature.
|
|
165
|
+
*
|
|
166
|
+
* The wrapper extracts named parameters from the args dict and passes
|
|
167
|
+
* them as positional arguments to the original function.
|
|
168
|
+
*/
|
|
169
|
+
export function createTypedHandlerWrapper(
|
|
170
|
+
fn: Function,
|
|
171
|
+
paramNames: string[],
|
|
172
|
+
hasRawData: boolean,
|
|
173
|
+
): SwaigHandler {
|
|
174
|
+
return (args: Record<string, unknown>, rawData: Record<string, unknown>) => {
|
|
175
|
+
const positionalArgs = paramNames.map((name) => args[name]);
|
|
176
|
+
if (hasRawData) {
|
|
177
|
+
positionalArgs.push(rawData);
|
|
178
|
+
}
|
|
179
|
+
return fn(...positionalArgs);
|
|
180
|
+
};
|
|
181
|
+
}
|