@jambonz/tools 0.1.2

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.
@@ -0,0 +1,139 @@
1
+ /**
2
+ * JSON Schema for a tool's parameters, following the OpenAI function-calling format.
3
+ */
4
+ interface ToolParameters {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ }
9
+ /**
10
+ * The schema definition passed to llmOptions.tools in a jambonz pipeline verb.
11
+ * Compatible with OpenAI, Anthropic, Google, and Bedrock function-calling formats.
12
+ */
13
+ interface ToolSchema {
14
+ name: string;
15
+ description: string;
16
+ parameters: ToolParameters;
17
+ }
18
+ /**
19
+ * A pre-built, reusable tool for jambonz pipeline voice AI agents.
20
+ *
21
+ * Each tool bundles:
22
+ * - `schema` — the tool definition the LLM needs to know how to call it
23
+ * - `execute` — the handler that runs when the LLM invokes the tool
24
+ */
25
+ interface JambonzTool {
26
+ /** Tool schema for llmOptions.tools */
27
+ schema: ToolSchema;
28
+ /** Execute the tool and return a text result for the LLM */
29
+ execute(args: Record<string, any>): Promise<string>;
30
+ }
31
+ /**
32
+ * Minimal session interface — matches @jambonz/sdk WebSocket session
33
+ * without requiring a hard dependency on the SDK.
34
+ */
35
+ interface SessionLike {
36
+ on(event: string, handler: (evt: any) => void): void;
37
+ sendToolOutput(toolCallId: string, data: unknown): void;
38
+ }
39
+
40
+ interface ToolCallEvent {
41
+ tool_call_id: string;
42
+ name: string;
43
+ arguments: Record<string, any>;
44
+ }
45
+ /**
46
+ * Register one or more tools on a jambonz session.
47
+ *
48
+ * Listens on the given hook path for tool-call events, dispatches to the
49
+ * matching tool's execute() method, and sends the result back via
50
+ * session.sendToolOutput(). Unknown tool names are reported as errors.
51
+ *
52
+ * @param session - A jambonz WebSocket session (or any object with .on() and .sendToolOutput())
53
+ * @param hookPath - The toolHook path used in the pipeline verb (e.g. '/tool-call')
54
+ * @param tools - Array of JambonzTool instances to register
55
+ * @param options - Optional configuration
56
+ * @param options.logger - A pino-compatible logger for debug/error output
57
+ * @param options.onUnknownTool - Custom handler for unrecognized tool names
58
+ */
59
+ declare function registerTools(session: SessionLike, hookPath: string, tools: JambonzTool[], options?: {
60
+ logger?: {
61
+ info: (...args: any[]) => void;
62
+ error: (...args: any[]) => void;
63
+ };
64
+ onUnknownTool?: (session: SessionLike, evt: ToolCallEvent) => void;
65
+ }): void;
66
+
67
+ interface TavilySearchOptions {
68
+ /** Tavily API key (required) */
69
+ apiKey: string;
70
+ /** Maximum number of results to return (default: 3) */
71
+ maxResults?: number;
72
+ /** Search depth: 'basic' is faster, 'advanced' is more thorough (default: 'basic') */
73
+ searchDepth?: 'basic' | 'advanced';
74
+ /** Topic category (default: 'general') */
75
+ topic?: 'general' | 'news' | 'finance';
76
+ /** Only include results from these domains */
77
+ includeDomains?: string[];
78
+ /** Exclude results from these domains */
79
+ excludeDomains?: string[];
80
+ }
81
+ /**
82
+ * Create a web search tool powered by the Tavily Search API.
83
+ *
84
+ * Useful for answering questions about current events, recent news,
85
+ * or any topic that requires up-to-date information.
86
+ *
87
+ * Requires a Tavily API key — sign up at https://tavily.com
88
+ */
89
+ declare function createTavilySearch(options: TavilySearchOptions): JambonzTool;
90
+
91
+ interface WeatherOptions {
92
+ /** Temperature scale (default: 'celsius') */
93
+ scale?: 'celsius' | 'fahrenheit';
94
+ }
95
+ /**
96
+ * Create a weather lookup tool using the free Open-Meteo API.
97
+ *
98
+ * No API key required. Provides current temperature, wind speed,
99
+ * and weather conditions for any location worldwide.
100
+ */
101
+ declare function createWeather(options?: WeatherOptions): JambonzTool;
102
+
103
+ interface WikipediaOptions {
104
+ /** Maximum number of sentences to return from the article summary (default: 5) */
105
+ maxSentences?: number;
106
+ /** Wikipedia language edition (default: 'en') */
107
+ language?: string;
108
+ }
109
+ /**
110
+ * Create a Wikipedia lookup tool using the free Wikipedia REST API.
111
+ *
112
+ * No API key required. Searches Wikipedia and returns article summaries,
113
+ * ideal for answering general knowledge questions in voice conversations.
114
+ */
115
+ declare function createWikipedia(options?: WikipediaOptions): JambonzTool;
116
+
117
+ /**
118
+ * Create a safe math calculator tool.
119
+ *
120
+ * Uses a recursive descent parser — no eval() — to safely evaluate
121
+ * arithmetic expressions. Ideal for voice agents handling calculations
122
+ * like tips, conversions, or simple math.
123
+ */
124
+ declare function createCalculator(): JambonzTool;
125
+
126
+ interface DateTimeOptions {
127
+ /** Default timezone when none is specified (default: 'UTC') */
128
+ defaultTimezone?: string;
129
+ }
130
+ /**
131
+ * Create a date/time tool using the built-in Intl API.
132
+ *
133
+ * No API key required. Returns the current date, time, and timezone
134
+ * for any IANA timezone. Handles common city-to-timezone mapping for
135
+ * cases where the LLM sends a city name instead of an IANA zone.
136
+ */
137
+ declare function createDateTime(options?: DateTimeOptions): JambonzTool;
138
+
139
+ export { type DateTimeOptions, type JambonzTool, type SessionLike, type TavilySearchOptions, type ToolParameters, type ToolSchema, type WeatherOptions, type WikipediaOptions, createCalculator, createDateTime, createTavilySearch, createWeather, createWikipedia, registerTools };
@@ -0,0 +1,139 @@
1
+ /**
2
+ * JSON Schema for a tool's parameters, following the OpenAI function-calling format.
3
+ */
4
+ interface ToolParameters {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ }
9
+ /**
10
+ * The schema definition passed to llmOptions.tools in a jambonz pipeline verb.
11
+ * Compatible with OpenAI, Anthropic, Google, and Bedrock function-calling formats.
12
+ */
13
+ interface ToolSchema {
14
+ name: string;
15
+ description: string;
16
+ parameters: ToolParameters;
17
+ }
18
+ /**
19
+ * A pre-built, reusable tool for jambonz pipeline voice AI agents.
20
+ *
21
+ * Each tool bundles:
22
+ * - `schema` — the tool definition the LLM needs to know how to call it
23
+ * - `execute` — the handler that runs when the LLM invokes the tool
24
+ */
25
+ interface JambonzTool {
26
+ /** Tool schema for llmOptions.tools */
27
+ schema: ToolSchema;
28
+ /** Execute the tool and return a text result for the LLM */
29
+ execute(args: Record<string, any>): Promise<string>;
30
+ }
31
+ /**
32
+ * Minimal session interface — matches @jambonz/sdk WebSocket session
33
+ * without requiring a hard dependency on the SDK.
34
+ */
35
+ interface SessionLike {
36
+ on(event: string, handler: (evt: any) => void): void;
37
+ sendToolOutput(toolCallId: string, data: unknown): void;
38
+ }
39
+
40
+ interface ToolCallEvent {
41
+ tool_call_id: string;
42
+ name: string;
43
+ arguments: Record<string, any>;
44
+ }
45
+ /**
46
+ * Register one or more tools on a jambonz session.
47
+ *
48
+ * Listens on the given hook path for tool-call events, dispatches to the
49
+ * matching tool's execute() method, and sends the result back via
50
+ * session.sendToolOutput(). Unknown tool names are reported as errors.
51
+ *
52
+ * @param session - A jambonz WebSocket session (or any object with .on() and .sendToolOutput())
53
+ * @param hookPath - The toolHook path used in the pipeline verb (e.g. '/tool-call')
54
+ * @param tools - Array of JambonzTool instances to register
55
+ * @param options - Optional configuration
56
+ * @param options.logger - A pino-compatible logger for debug/error output
57
+ * @param options.onUnknownTool - Custom handler for unrecognized tool names
58
+ */
59
+ declare function registerTools(session: SessionLike, hookPath: string, tools: JambonzTool[], options?: {
60
+ logger?: {
61
+ info: (...args: any[]) => void;
62
+ error: (...args: any[]) => void;
63
+ };
64
+ onUnknownTool?: (session: SessionLike, evt: ToolCallEvent) => void;
65
+ }): void;
66
+
67
+ interface TavilySearchOptions {
68
+ /** Tavily API key (required) */
69
+ apiKey: string;
70
+ /** Maximum number of results to return (default: 3) */
71
+ maxResults?: number;
72
+ /** Search depth: 'basic' is faster, 'advanced' is more thorough (default: 'basic') */
73
+ searchDepth?: 'basic' | 'advanced';
74
+ /** Topic category (default: 'general') */
75
+ topic?: 'general' | 'news' | 'finance';
76
+ /** Only include results from these domains */
77
+ includeDomains?: string[];
78
+ /** Exclude results from these domains */
79
+ excludeDomains?: string[];
80
+ }
81
+ /**
82
+ * Create a web search tool powered by the Tavily Search API.
83
+ *
84
+ * Useful for answering questions about current events, recent news,
85
+ * or any topic that requires up-to-date information.
86
+ *
87
+ * Requires a Tavily API key — sign up at https://tavily.com
88
+ */
89
+ declare function createTavilySearch(options: TavilySearchOptions): JambonzTool;
90
+
91
+ interface WeatherOptions {
92
+ /** Temperature scale (default: 'celsius') */
93
+ scale?: 'celsius' | 'fahrenheit';
94
+ }
95
+ /**
96
+ * Create a weather lookup tool using the free Open-Meteo API.
97
+ *
98
+ * No API key required. Provides current temperature, wind speed,
99
+ * and weather conditions for any location worldwide.
100
+ */
101
+ declare function createWeather(options?: WeatherOptions): JambonzTool;
102
+
103
+ interface WikipediaOptions {
104
+ /** Maximum number of sentences to return from the article summary (default: 5) */
105
+ maxSentences?: number;
106
+ /** Wikipedia language edition (default: 'en') */
107
+ language?: string;
108
+ }
109
+ /**
110
+ * Create a Wikipedia lookup tool using the free Wikipedia REST API.
111
+ *
112
+ * No API key required. Searches Wikipedia and returns article summaries,
113
+ * ideal for answering general knowledge questions in voice conversations.
114
+ */
115
+ declare function createWikipedia(options?: WikipediaOptions): JambonzTool;
116
+
117
+ /**
118
+ * Create a safe math calculator tool.
119
+ *
120
+ * Uses a recursive descent parser — no eval() — to safely evaluate
121
+ * arithmetic expressions. Ideal for voice agents handling calculations
122
+ * like tips, conversions, or simple math.
123
+ */
124
+ declare function createCalculator(): JambonzTool;
125
+
126
+ interface DateTimeOptions {
127
+ /** Default timezone when none is specified (default: 'UTC') */
128
+ defaultTimezone?: string;
129
+ }
130
+ /**
131
+ * Create a date/time tool using the built-in Intl API.
132
+ *
133
+ * No API key required. Returns the current date, time, and timezone
134
+ * for any IANA timezone. Handles common city-to-timezone mapping for
135
+ * cases where the LLM sends a city name instead of an IANA zone.
136
+ */
137
+ declare function createDateTime(options?: DateTimeOptions): JambonzTool;
138
+
139
+ export { type DateTimeOptions, type JambonzTool, type SessionLike, type TavilySearchOptions, type ToolParameters, type ToolSchema, type WeatherOptions, type WikipediaOptions, createCalculator, createDateTime, createTavilySearch, createWeather, createWikipedia, registerTools };