fmp-ai-tools 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -14,6 +14,18 @@ pnpm add fmp-ai-tools
14
14
  yarn add fmp-ai-tools
15
15
  ```
16
16
 
17
+ ## Version Compatibility
18
+
19
+ ### OpenAI Agents Compatibility
20
+
21
+ **⚠️ Important**: This package requires `@openai/agents` version `^0.0.17` or higher due to breaking changes in the API.
22
+
23
+ If you're using an older version, you'll encounter errors like:
24
+
25
+ ```
26
+ Zod field uses .optional() without .nullable() which is not supported by the API
27
+ ```
28
+
17
29
  ## Quick Start
18
30
 
19
31
  ### Vercel AI SDK (Recommended)
@@ -70,6 +82,45 @@ FMP_API_KEY=your_api_key_here
70
82
 
71
83
  The tools internally use the `fmp-node-api` library, which reads this environment variable to authenticate with the Financial Modeling Prep API.
72
84
 
85
+ ### Debugging and Logging
86
+
87
+ **⚠️ Development Only**: These logging features are intended for debugging and development, not production use.
88
+
89
+ Two logging modes controlled by environment variables:
90
+
91
+ #### Full Logging Mode
92
+
93
+ ```bash
94
+ FMP_TOOLS_LOG_API_RESULTS=true
95
+ ```
96
+
97
+ Logs: tool name, input parameters, result summary with token count, execution time.
98
+
99
+ #### Data-Only Logging Mode
100
+
101
+ ```bash
102
+ FMP_TOOLS_LOG_DATA_ONLY=true
103
+ ```
104
+
105
+ Logs: result summary and formatted JSON response data.
106
+
107
+ #### Example Output
108
+
109
+ **Full Logging:**
110
+
111
+ ```
112
+ 🔧 getStockQuote: object (~28 tokens)
113
+ ⏱️ Execution Time: 245ms
114
+ ```
115
+
116
+ **Data-Only Logging:**
117
+
118
+ ```
119
+ 📤 Result: { "symbol": "AAPL", "price": 150.25, ... }
120
+ ```
121
+
122
+ **Note**: Both modes are disabled by default. Use only during development.
123
+
73
124
  ## Available Tools
74
125
 
75
126
  ### Quote Tools
@@ -1,56 +1,56 @@
1
1
  import * as _openai_agents from '@openai/agents';
2
2
  import { Tool } from '@openai/agents';
3
3
 
4
- declare const getCompanyProfile: _openai_agents.FunctionTool<unknown, undefined, string>;
5
-
6
- declare const getEarningsCalendar: _openai_agents.FunctionTool<unknown, undefined, string>;
7
- declare const getEconomicCalendar: _openai_agents.FunctionTool<unknown, undefined, string>;
8
-
9
- declare const getTreasuryRates: _openai_agents.FunctionTool<unknown, undefined, string>;
10
- declare const getEconomicIndicators: _openai_agents.FunctionTool<unknown, undefined, string>;
11
-
12
- declare const getETFHoldings: _openai_agents.FunctionTool<unknown, undefined, string>;
13
- declare const getETFProfile: _openai_agents.FunctionTool<unknown, undefined, string>;
14
-
15
- declare const getBalanceSheet: _openai_agents.FunctionTool<unknown, undefined, string>;
16
- declare const getIncomeStatement: _openai_agents.FunctionTool<unknown, undefined, string>;
17
- declare const getCashFlowStatement: _openai_agents.FunctionTool<unknown, undefined, string>;
18
- declare const getFinancialRatios: _openai_agents.FunctionTool<unknown, undefined, string>;
19
-
20
- declare const getInsiderTrading: _openai_agents.FunctionTool<unknown, undefined, string>;
21
-
22
- declare const getInstitutionalHolders: _openai_agents.FunctionTool<unknown, undefined, string>;
23
-
24
- declare const getMarketPerformance: _openai_agents.FunctionTool<unknown, undefined, string>;
25
- declare const getSectorPerformance: _openai_agents.FunctionTool<unknown, undefined, string>;
26
- declare const getGainers: _openai_agents.FunctionTool<unknown, undefined, string>;
27
- declare const getLosers: _openai_agents.FunctionTool<unknown, undefined, string>;
28
- declare const getMostActive: _openai_agents.FunctionTool<unknown, undefined, string>;
29
-
30
- declare const getStockQuote: _openai_agents.FunctionTool<unknown, undefined, string>;
31
-
32
- declare const getSenateTrading: _openai_agents.FunctionTool<unknown, undefined, string>;
33
- declare const getHouseTrading: _openai_agents.FunctionTool<unknown, undefined, string>;
34
- declare const getSenateTradingByName: _openai_agents.FunctionTool<unknown, undefined, string>;
35
- declare const getHouseTradingByName: _openai_agents.FunctionTool<unknown, undefined, string>;
36
- declare const getSenateTradingRSSFeed: _openai_agents.FunctionTool<unknown, undefined, string>;
37
- declare const getHouseTradingRSSFeed: _openai_agents.FunctionTool<unknown, undefined, string>;
38
-
39
- declare const getMarketCap: _openai_agents.FunctionTool<unknown, undefined, string>;
40
- declare const getStockSplits: _openai_agents.FunctionTool<unknown, undefined, string>;
41
- declare const getDividendHistory: _openai_agents.FunctionTool<unknown, undefined, string>;
42
-
43
- declare const companyTools: Tool[];
44
- declare const calendarTools: Tool[];
45
- declare const economicTools: Tool[];
46
- declare const etfTools: Tool[];
47
- declare const financialTools: Tool[];
48
- declare const insiderTools: Tool[];
49
- declare const institutionalTools: Tool[];
50
- declare const marketTools: Tool[];
51
- declare const quoteTools: Tool[];
52
- declare const senateHouseTools: Tool[];
53
- declare const stockTools: Tool[];
54
- declare const fmpTools: Tool[];
4
+ declare const getCompanyProfile: _openai_agents.FunctionTool<unknown, any, string>;
5
+
6
+ declare const getEarningsCalendar: _openai_agents.FunctionTool<unknown, any, string>;
7
+ declare const getEconomicCalendar: _openai_agents.FunctionTool<unknown, any, string>;
8
+
9
+ declare const getTreasuryRates: _openai_agents.FunctionTool<unknown, any, string>;
10
+ declare const getEconomicIndicators: _openai_agents.FunctionTool<unknown, any, string>;
11
+
12
+ declare const getETFHoldings: _openai_agents.FunctionTool<unknown, any, string>;
13
+ declare const getETFProfile: _openai_agents.FunctionTool<unknown, any, string>;
14
+
15
+ declare const getBalanceSheet: _openai_agents.FunctionTool<unknown, any, string>;
16
+ declare const getIncomeStatement: _openai_agents.FunctionTool<unknown, any, string>;
17
+ declare const getCashFlowStatement: _openai_agents.FunctionTool<unknown, any, string>;
18
+ declare const getFinancialRatios: _openai_agents.FunctionTool<unknown, any, string>;
19
+
20
+ declare const getInsiderTrading: _openai_agents.FunctionTool<unknown, any, string>;
21
+
22
+ declare const getInstitutionalHolders: _openai_agents.FunctionTool<unknown, any, string>;
23
+
24
+ declare const getMarketPerformance: _openai_agents.FunctionTool<unknown, any, string>;
25
+ declare const getSectorPerformance: _openai_agents.FunctionTool<unknown, any, string>;
26
+ declare const getGainers: _openai_agents.FunctionTool<unknown, any, string>;
27
+ declare const getLosers: _openai_agents.FunctionTool<unknown, any, string>;
28
+ declare const getMostActive: _openai_agents.FunctionTool<unknown, any, string>;
29
+
30
+ declare const getStockQuote: _openai_agents.FunctionTool<unknown, any, string>;
31
+
32
+ declare const getSenateTrading: _openai_agents.FunctionTool<unknown, any, string>;
33
+ declare const getHouseTrading: _openai_agents.FunctionTool<unknown, any, string>;
34
+ declare const getSenateTradingByName: _openai_agents.FunctionTool<unknown, any, string>;
35
+ declare const getHouseTradingByName: _openai_agents.FunctionTool<unknown, any, string>;
36
+ declare const getSenateTradingRSSFeed: _openai_agents.FunctionTool<unknown, any, string>;
37
+ declare const getHouseTradingRSSFeed: _openai_agents.FunctionTool<unknown, any, string>;
38
+
39
+ declare const getMarketCap: _openai_agents.FunctionTool<unknown, any, string>;
40
+ declare const getStockSplits: _openai_agents.FunctionTool<unknown, any, string>;
41
+ declare const getDividendHistory: _openai_agents.FunctionTool<unknown, any, string>;
42
+
43
+ declare const companyTools: Tool<unknown>[];
44
+ declare const calendarTools: Tool<unknown>[];
45
+ declare const economicTools: Tool<unknown>[];
46
+ declare const etfTools: Tool<unknown>[];
47
+ declare const financialTools: Tool<unknown>[];
48
+ declare const insiderTools: Tool<unknown>[];
49
+ declare const institutionalTools: Tool<unknown>[];
50
+ declare const marketTools: Tool<unknown>[];
51
+ declare const quoteTools: Tool<unknown>[];
52
+ declare const senateHouseTools: Tool<unknown>[];
53
+ declare const stockTools: Tool<unknown>[];
54
+ declare const fmpTools: Tool<unknown>[];
55
55
 
56
56
  export { calendarTools, companyTools, economicTools, etfTools, financialTools, fmpTools, getBalanceSheet, getCashFlowStatement, getCompanyProfile, getDividendHistory, getETFHoldings, getETFProfile, getEarningsCalendar, getEconomicCalendar, getEconomicIndicators, getFinancialRatios, getGainers, getHouseTrading, getHouseTradingByName, getHouseTradingRSSFeed, getIncomeStatement, getInsiderTrading, getInstitutionalHolders, getLosers, getMarketCap, getMarketPerformance, getMostActive, getSectorPerformance, getSenateTrading, getSenateTradingByName, getSenateTradingRSSFeed, getStockQuote, getStockSplits, getTreasuryRates, insiderTools, institutionalTools, marketTools, quoteTools, senateHouseTools, stockTools };
@@ -1,56 +1,56 @@
1
1
  import * as _openai_agents from '@openai/agents';
2
2
  import { Tool } from '@openai/agents';
3
3
 
4
- declare const getCompanyProfile: _openai_agents.FunctionTool<unknown, undefined, string>;
5
-
6
- declare const getEarningsCalendar: _openai_agents.FunctionTool<unknown, undefined, string>;
7
- declare const getEconomicCalendar: _openai_agents.FunctionTool<unknown, undefined, string>;
8
-
9
- declare const getTreasuryRates: _openai_agents.FunctionTool<unknown, undefined, string>;
10
- declare const getEconomicIndicators: _openai_agents.FunctionTool<unknown, undefined, string>;
11
-
12
- declare const getETFHoldings: _openai_agents.FunctionTool<unknown, undefined, string>;
13
- declare const getETFProfile: _openai_agents.FunctionTool<unknown, undefined, string>;
14
-
15
- declare const getBalanceSheet: _openai_agents.FunctionTool<unknown, undefined, string>;
16
- declare const getIncomeStatement: _openai_agents.FunctionTool<unknown, undefined, string>;
17
- declare const getCashFlowStatement: _openai_agents.FunctionTool<unknown, undefined, string>;
18
- declare const getFinancialRatios: _openai_agents.FunctionTool<unknown, undefined, string>;
19
-
20
- declare const getInsiderTrading: _openai_agents.FunctionTool<unknown, undefined, string>;
21
-
22
- declare const getInstitutionalHolders: _openai_agents.FunctionTool<unknown, undefined, string>;
23
-
24
- declare const getMarketPerformance: _openai_agents.FunctionTool<unknown, undefined, string>;
25
- declare const getSectorPerformance: _openai_agents.FunctionTool<unknown, undefined, string>;
26
- declare const getGainers: _openai_agents.FunctionTool<unknown, undefined, string>;
27
- declare const getLosers: _openai_agents.FunctionTool<unknown, undefined, string>;
28
- declare const getMostActive: _openai_agents.FunctionTool<unknown, undefined, string>;
29
-
30
- declare const getStockQuote: _openai_agents.FunctionTool<unknown, undefined, string>;
31
-
32
- declare const getSenateTrading: _openai_agents.FunctionTool<unknown, undefined, string>;
33
- declare const getHouseTrading: _openai_agents.FunctionTool<unknown, undefined, string>;
34
- declare const getSenateTradingByName: _openai_agents.FunctionTool<unknown, undefined, string>;
35
- declare const getHouseTradingByName: _openai_agents.FunctionTool<unknown, undefined, string>;
36
- declare const getSenateTradingRSSFeed: _openai_agents.FunctionTool<unknown, undefined, string>;
37
- declare const getHouseTradingRSSFeed: _openai_agents.FunctionTool<unknown, undefined, string>;
38
-
39
- declare const getMarketCap: _openai_agents.FunctionTool<unknown, undefined, string>;
40
- declare const getStockSplits: _openai_agents.FunctionTool<unknown, undefined, string>;
41
- declare const getDividendHistory: _openai_agents.FunctionTool<unknown, undefined, string>;
42
-
43
- declare const companyTools: Tool[];
44
- declare const calendarTools: Tool[];
45
- declare const economicTools: Tool[];
46
- declare const etfTools: Tool[];
47
- declare const financialTools: Tool[];
48
- declare const insiderTools: Tool[];
49
- declare const institutionalTools: Tool[];
50
- declare const marketTools: Tool[];
51
- declare const quoteTools: Tool[];
52
- declare const senateHouseTools: Tool[];
53
- declare const stockTools: Tool[];
54
- declare const fmpTools: Tool[];
4
+ declare const getCompanyProfile: _openai_agents.FunctionTool<unknown, any, string>;
5
+
6
+ declare const getEarningsCalendar: _openai_agents.FunctionTool<unknown, any, string>;
7
+ declare const getEconomicCalendar: _openai_agents.FunctionTool<unknown, any, string>;
8
+
9
+ declare const getTreasuryRates: _openai_agents.FunctionTool<unknown, any, string>;
10
+ declare const getEconomicIndicators: _openai_agents.FunctionTool<unknown, any, string>;
11
+
12
+ declare const getETFHoldings: _openai_agents.FunctionTool<unknown, any, string>;
13
+ declare const getETFProfile: _openai_agents.FunctionTool<unknown, any, string>;
14
+
15
+ declare const getBalanceSheet: _openai_agents.FunctionTool<unknown, any, string>;
16
+ declare const getIncomeStatement: _openai_agents.FunctionTool<unknown, any, string>;
17
+ declare const getCashFlowStatement: _openai_agents.FunctionTool<unknown, any, string>;
18
+ declare const getFinancialRatios: _openai_agents.FunctionTool<unknown, any, string>;
19
+
20
+ declare const getInsiderTrading: _openai_agents.FunctionTool<unknown, any, string>;
21
+
22
+ declare const getInstitutionalHolders: _openai_agents.FunctionTool<unknown, any, string>;
23
+
24
+ declare const getMarketPerformance: _openai_agents.FunctionTool<unknown, any, string>;
25
+ declare const getSectorPerformance: _openai_agents.FunctionTool<unknown, any, string>;
26
+ declare const getGainers: _openai_agents.FunctionTool<unknown, any, string>;
27
+ declare const getLosers: _openai_agents.FunctionTool<unknown, any, string>;
28
+ declare const getMostActive: _openai_agents.FunctionTool<unknown, any, string>;
29
+
30
+ declare const getStockQuote: _openai_agents.FunctionTool<unknown, any, string>;
31
+
32
+ declare const getSenateTrading: _openai_agents.FunctionTool<unknown, any, string>;
33
+ declare const getHouseTrading: _openai_agents.FunctionTool<unknown, any, string>;
34
+ declare const getSenateTradingByName: _openai_agents.FunctionTool<unknown, any, string>;
35
+ declare const getHouseTradingByName: _openai_agents.FunctionTool<unknown, any, string>;
36
+ declare const getSenateTradingRSSFeed: _openai_agents.FunctionTool<unknown, any, string>;
37
+ declare const getHouseTradingRSSFeed: _openai_agents.FunctionTool<unknown, any, string>;
38
+
39
+ declare const getMarketCap: _openai_agents.FunctionTool<unknown, any, string>;
40
+ declare const getStockSplits: _openai_agents.FunctionTool<unknown, any, string>;
41
+ declare const getDividendHistory: _openai_agents.FunctionTool<unknown, any, string>;
42
+
43
+ declare const companyTools: Tool<unknown>[];
44
+ declare const calendarTools: Tool<unknown>[];
45
+ declare const economicTools: Tool<unknown>[];
46
+ declare const etfTools: Tool<unknown>[];
47
+ declare const financialTools: Tool<unknown>[];
48
+ declare const insiderTools: Tool<unknown>[];
49
+ declare const institutionalTools: Tool<unknown>[];
50
+ declare const marketTools: Tool<unknown>[];
51
+ declare const quoteTools: Tool<unknown>[];
52
+ declare const senateHouseTools: Tool<unknown>[];
53
+ declare const stockTools: Tool<unknown>[];
54
+ declare const fmpTools: Tool<unknown>[];
55
55
 
56
56
  export { calendarTools, companyTools, economicTools, etfTools, financialTools, fmpTools, getBalanceSheet, getCashFlowStatement, getCompanyProfile, getDividendHistory, getETFHoldings, getETFProfile, getEarningsCalendar, getEconomicCalendar, getEconomicIndicators, getFinancialRatios, getGainers, getHouseTrading, getHouseTradingByName, getHouseTradingRSSFeed, getIncomeStatement, getInsiderTrading, getInstitutionalHolders, getLosers, getMarketCap, getMarketPerformance, getMostActive, getSectorPerformance, getSenateTrading, getSenateTradingByName, getSenateTradingRSSFeed, getStockQuote, getStockSplits, getTreasuryRates, insiderTools, institutionalTools, marketTools, quoteTools, senateHouseTools, stockTools };
@@ -4,15 +4,211 @@ var zod = require('zod');
4
4
  var agents = require('@openai/agents');
5
5
  var fmpNodeApi = require('fmp-node-api');
6
6
 
7
- // src/providers/openai/company.ts
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+
14
+ // src/utils/version-check.ts
15
+ function checkOpenAIAgentsVersion() {
16
+ try {
17
+ const { tool: tool2 } = __require("@openai/agents");
18
+ tool2({
19
+ name: "test",
20
+ description: "test",
21
+ parameters: { type: "object", properties: {} },
22
+ strict: true,
23
+ execute: async () => "test"
24
+ });
25
+ } catch (error) {
26
+ const errorMessage = error instanceof Error ? error.message : String(error);
27
+ throw new Error(
28
+ `Incompatible @openai/agents version detected. This package requires version ^0.0.17 or higher due to breaking changes in the API. Please upgrade with: npm install @openai/agents@latest
29
+
30
+ Error details: ${errorMessage}`
31
+ );
32
+ }
33
+ }
34
+
35
+ // src/utils/logger.ts
36
+ function isApiLoggingEnabled() {
37
+ return process.env.FMP_TOOLS_LOG_API_RESULTS === "true";
38
+ }
39
+ function isDataOnlyLoggingEnabled() {
40
+ return process.env.FMP_TOOLS_LOG_DATA_ONLY === "true";
41
+ }
42
+ function estimateTokenCount(text) {
43
+ try {
44
+ const parsed = JSON.parse(text);
45
+ return estimateTokenCountForData(parsed);
46
+ } catch {
47
+ return estimateTokenCountForText(text);
48
+ }
49
+ }
50
+ function estimateTokenCountForData(data) {
51
+ if (data === null || data === void 0) {
52
+ return 1;
53
+ }
54
+ if (typeof data === "string") {
55
+ return Math.ceil(data.length / 3);
56
+ }
57
+ if (typeof data === "number") {
58
+ return data.toString().length > 10 ? 2 : 1;
59
+ }
60
+ if (typeof data === "boolean") {
61
+ return 1;
62
+ }
63
+ if (Array.isArray(data)) {
64
+ let tokens = 2;
65
+ for (const item of data) {
66
+ tokens += estimateTokenCountForData(item);
67
+ if (data.indexOf(item) < data.length - 1) {
68
+ tokens += 1;
69
+ }
70
+ }
71
+ return tokens;
72
+ }
73
+ if (typeof data === "object") {
74
+ let tokens = 2;
75
+ const keys = Object.keys(data);
76
+ for (let i = 0; i < keys.length; i++) {
77
+ const key = keys[i];
78
+ const value = data[key];
79
+ tokens += Math.ceil(key.length / 3);
80
+ tokens += 2;
81
+ tokens += 1;
82
+ tokens += estimateTokenCountForData(value);
83
+ if (i < keys.length - 1) {
84
+ tokens += 1;
85
+ }
86
+ }
87
+ return tokens;
88
+ }
89
+ return 1;
90
+ }
91
+ function estimateTokenCountForText(text) {
92
+ const words = text.split(/\s+/).filter((word) => word.length > 0);
93
+ let tokens = 0;
94
+ for (const word of words) {
95
+ if (/^\d+$/.test(word)) {
96
+ tokens += word.length > 8 ? 2 : 1;
97
+ } else if (/^[A-Z]+$/.test(word)) {
98
+ tokens += 1;
99
+ } else if (/^\$[\d,]+\.?\d*$/.test(word)) {
100
+ tokens += 3;
101
+ } else {
102
+ tokens += Math.ceil(word.length / 3.5);
103
+ }
104
+ }
105
+ return tokens;
106
+ }
107
+ function getResultInfo(result) {
108
+ if (result === null || result === void 0) {
109
+ return "null/undefined";
110
+ }
111
+ if (typeof result === "string") {
112
+ const tokenCount = estimateTokenCount(result);
113
+ try {
114
+ const parsed = JSON.parse(result);
115
+ if (Array.isArray(parsed)) {
116
+ return `JSON string (array of ${parsed.length} items, ~${tokenCount} tokens)`;
117
+ }
118
+ } catch {
119
+ }
120
+ return `string (${result.length} chars, ~${tokenCount} tokens)`;
121
+ }
122
+ if (Array.isArray(result)) {
123
+ const jsonStr = JSON.stringify(result);
124
+ const tokenCount = estimateTokenCount(jsonStr);
125
+ return `array (${result.length} items, ~${tokenCount} tokens)`;
126
+ }
127
+ if (typeof result === "object") {
128
+ const jsonStr = JSON.stringify(result);
129
+ const tokenCount = estimateTokenCount(jsonStr);
130
+ return `object (~${tokenCount} tokens)`;
131
+ }
132
+ return typeof result;
133
+ }
134
+ function logApiExecution(options) {
135
+ if (!isApiLoggingEnabled()) {
136
+ return;
137
+ }
138
+ const { toolName, input, result, executionTime } = options;
139
+ console.log("\n" + "=".repeat(80));
140
+ console.log(`\u{1F527} FMP Tool Execution: ${toolName}`);
141
+ console.log("=".repeat(80));
142
+ console.log("\n\u{1F4E5} Input:");
143
+ console.log(JSON.stringify(input, null, 2));
144
+ const resultInfo = getResultInfo(result);
145
+ console.log(`\u{1F527} ${toolName}: ${resultInfo}`);
146
+ if (executionTime !== void 0) {
147
+ console.log(`
148
+ \u23F1\uFE0F Execution Time: ${executionTime}ms`);
149
+ }
150
+ console.log("=".repeat(80) + "\n");
151
+ }
152
+ function logDataOnly(options) {
153
+ if (!isDataOnlyLoggingEnabled()) {
154
+ return;
155
+ }
156
+ const { result } = options;
157
+ console.log("\n\u{1F4E4} Result:");
158
+ if (typeof result === "string") {
159
+ try {
160
+ const parsed = JSON.parse(result);
161
+ console.log(JSON.stringify(parsed, null, 2));
162
+ } catch {
163
+ console.log(result);
164
+ }
165
+ } else {
166
+ console.log(JSON.stringify(result, null, 2));
167
+ }
168
+ console.log("=".repeat(80) + "\n");
169
+ }
170
+ async function logApiExecutionWithTiming(toolName, input, executeFn) {
171
+ const startTime = Date.now();
172
+ try {
173
+ const result = await executeFn();
174
+ const executionTime = Date.now() - startTime;
175
+ logApiExecution({
176
+ toolName,
177
+ input,
178
+ result,
179
+ executionTime
180
+ });
181
+ logDataOnly({
182
+ toolName,
183
+ input,
184
+ result,
185
+ executionTime
186
+ });
187
+ return result;
188
+ } catch (error) {
189
+ const executionTime = Date.now() - startTime;
190
+ if (isApiLoggingEnabled()) {
191
+ console.log("\n" + "=".repeat(80));
192
+ console.log(`\u274C FMP Tool Execution Error: ${toolName}`);
193
+ console.log("=".repeat(80));
194
+ console.log("\n\u{1F4E5} Input:");
195
+ console.log(JSON.stringify(input, null, 2));
196
+ console.log("\n\u274C Error:");
197
+ console.log(error instanceof Error ? error.message : String(error));
198
+ console.log(`
199
+ \u23F1\uFE0F Execution Time: ${executionTime}ms`);
200
+ console.log("=".repeat(80) + "\n");
201
+ }
202
+ throw error;
203
+ }
204
+ }
205
+
206
+ // src/utils/openai-tool-wrapper.ts
8
207
  function createOpenAITool(config) {
9
208
  const { name, description, inputSchema, execute } = config;
10
- const properties = {};
11
- const required = [];
12
209
  if (inputSchema instanceof zod.z.ZodObject) {
13
210
  const shape = inputSchema.shape;
14
211
  Object.entries(shape).forEach(([key, schema]) => {
15
- let isRequired = true;
16
212
  let actualSchema = schema;
17
213
  let fieldDescription = "";
18
214
  if (schema && typeof schema === "object" && "description" in schema) {
@@ -22,72 +218,35 @@ function createOpenAITool(config) {
22
218
  }
23
219
  }
24
220
  if (schema instanceof zod.z.ZodOptional) {
25
- isRequired = false;
26
221
  actualSchema = schema.unwrap();
27
222
  if (!fieldDescription && actualSchema.description) {
28
223
  fieldDescription = actualSchema.description;
29
224
  }
30
225
  }
31
226
  if (schema instanceof zod.z.ZodDefault) {
32
- isRequired = false;
33
227
  actualSchema = schema.removeDefault();
34
228
  if (!fieldDescription && actualSchema.description) {
35
229
  fieldDescription = actualSchema.description;
36
230
  }
37
231
  }
38
- if (actualSchema instanceof zod.z.ZodString) {
39
- properties[key] = {
40
- type: "string",
41
- description: fieldDescription || `${key} parameter`
42
- };
43
- } else if (actualSchema instanceof zod.z.ZodEnum) {
44
- properties[key] = {
232
+ if (actualSchema instanceof zod.z.ZodString) ; else if (actualSchema instanceof zod.z.ZodEnum) {
233
+ ({
45
234
  type: "string",
46
235
  enum: actualSchema._def.values,
47
236
  description: fieldDescription || `${key} parameter`
48
- };
49
- } else if (actualSchema instanceof zod.z.ZodNumber) {
50
- properties[key] = {
51
- type: "number",
52
- description: fieldDescription || `${key} parameter`
53
- };
54
- } else if (actualSchema instanceof zod.z.ZodBoolean) {
55
- properties[key] = {
56
- type: "boolean",
57
- description: fieldDescription || `${key} parameter`
58
- };
59
- } else if (actualSchema instanceof zod.z.ZodArray) {
60
- properties[key] = {
61
- type: "array",
62
- items: { type: "string" },
63
- // Default to string array, can be enhanced
64
- description: fieldDescription || `${key} parameter`
65
- };
66
- } else {
67
- properties[key] = {
68
- type: "string",
69
- description: fieldDescription || `${key} parameter`
70
- };
71
- }
72
- if (isRequired) {
73
- required.push(key);
74
- }
237
+ });
238
+ } else if (actualSchema instanceof zod.z.ZodNumber) ; else if (actualSchema instanceof zod.z.ZodBoolean) ; else if (actualSchema instanceof zod.z.ZodArray) ; else ;
75
239
  });
76
240
  }
77
241
  return agents.tool({
78
242
  name,
79
243
  description,
80
- parameters: {
81
- type: "object",
82
- properties,
83
- required,
84
- additionalProperties: false
85
- },
86
- strict: false,
244
+ parameters: inputSchema,
245
+ strict: true,
87
246
  execute: async (input) => {
88
247
  try {
89
248
  const validatedInput = inputSchema.parse(input);
90
- return await execute(validatedInput);
249
+ return await logApiExecutionWithTiming(name, validatedInput, () => execute(validatedInput));
91
250
  } catch (error) {
92
251
  if (error instanceof zod.z.ZodError) {
93
252
  return `Invalid input: ${error.errors.map((e) => e.message).join(", ")}`;
@@ -115,8 +274,8 @@ var getCompanyProfile = createOpenAITool({
115
274
  }
116
275
  });
117
276
  var calendarInputSchema = zod.z.object({
118
- from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format (optional)"),
119
- to: zod.z.string().optional().describe("End date in YYYY-MM-DD format (optional)")
277
+ from: zod.z.string().optional().nullable().describe("Start date in YYYY-MM-DD format (optional)"),
278
+ to: zod.z.string().optional().nullable().describe("End date in YYYY-MM-DD format (optional)")
120
279
  });
121
280
  var getEarningsCalendar = createOpenAITool({
122
281
  name: "getEarningsCalendar",
@@ -124,7 +283,10 @@ var getEarningsCalendar = createOpenAITool({
124
283
  inputSchema: calendarInputSchema,
125
284
  execute: async ({ from, to }) => {
126
285
  const fmp = getFMPClient();
127
- const earningsCalendar = await fmp.calendar.getEarningsCalendar({ from, to });
286
+ const earningsCalendar = await fmp.calendar.getEarningsCalendar({
287
+ from: from ?? void 0,
288
+ to: to ?? void 0
289
+ });
128
290
  return JSON.stringify(earningsCalendar.data, null, 2);
129
291
  }
130
292
  });
@@ -134,13 +296,16 @@ var getEconomicCalendar = createOpenAITool({
134
296
  inputSchema: calendarInputSchema,
135
297
  execute: async ({ from, to }) => {
136
298
  const fmp = getFMPClient();
137
- const economicCalendar = await fmp.calendar.getEconomicsCalendar({ from, to });
299
+ const economicCalendar = await fmp.calendar.getEconomicsCalendar({
300
+ from: from ?? void 0,
301
+ to: to ?? void 0
302
+ });
138
303
  return JSON.stringify(economicCalendar.data, null, 2);
139
304
  }
140
305
  });
141
306
  var treasuryRatesInputSchema = zod.z.object({
142
- from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format (optional)"),
143
- to: zod.z.string().optional().describe("End date in YYYY-MM-DD format (optional)")
307
+ from: zod.z.string().optional().nullable().describe("Start date in YYYY-MM-DD format (optional)"),
308
+ to: zod.z.string().optional().nullable().describe("End date in YYYY-MM-DD format (optional)")
144
309
  });
145
310
  var economicIndicatorNames = [
146
311
  "GDP",
@@ -169,8 +334,8 @@ var economicIndicatorNames = [
169
334
  ];
170
335
  var economicIndicatorsInputSchema = zod.z.object({
171
336
  name: zod.z.enum(economicIndicatorNames).describe("The name of the economic indicator"),
172
- from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format (optional)"),
173
- to: zod.z.string().optional().describe("End date in YYYY-MM-DD format (optional)")
337
+ from: zod.z.string().optional().nullable().describe("Start date in YYYY-MM-DD format (optional)"),
338
+ to: zod.z.string().optional().nullable().describe("End date in YYYY-MM-DD format (optional)")
174
339
  });
175
340
  var getTreasuryRates = createOpenAITool({
176
341
  name: "getTreasuryRates",
@@ -178,7 +343,10 @@ var getTreasuryRates = createOpenAITool({
178
343
  inputSchema: treasuryRatesInputSchema,
179
344
  execute: async ({ from, to }) => {
180
345
  const fmp = getFMPClient();
181
- const treasuryRates = await fmp.economic.getTreasuryRates({ from, to });
346
+ const treasuryRates = await fmp.economic.getTreasuryRates({
347
+ from: from ?? void 0,
348
+ to: to ?? void 0
349
+ });
182
350
  return JSON.stringify(treasuryRates.data, null, 2);
183
351
  }
184
352
  });
@@ -188,13 +356,17 @@ var getEconomicIndicators = createOpenAITool({
188
356
  inputSchema: economicIndicatorsInputSchema,
189
357
  execute: async ({ name, from, to }) => {
190
358
  const fmp = getFMPClient();
191
- const economicIndicators = await fmp.economic.getEconomicIndicators({ name, from, to });
359
+ const economicIndicators = await fmp.economic.getEconomicIndicators({
360
+ name,
361
+ from: from ?? void 0,
362
+ to: to ?? void 0
363
+ });
192
364
  return JSON.stringify(economicIndicators.data, null, 2);
193
365
  }
194
366
  });
195
367
  var etfHoldingsInputSchema = zod.z.object({
196
368
  symbol: zod.z.string().min(1, "ETF symbol is required").describe("ETF symbol (e.g., SPY, QQQ, VTI)"),
197
- date: zod.z.string().optional().describe("Date for holdings in YYYY-MM-DD format (optional)")
369
+ date: zod.z.string().optional().nullable().describe("Date for holdings in YYYY-MM-DD format (optional)")
198
370
  });
199
371
  var etfProfileInputSchema = zod.z.object({
200
372
  symbol: zod.z.string().min(1, "ETF symbol is required").describe("ETF symbol (e.g., SPY, QQQ, VTI)")
@@ -521,6 +693,7 @@ var fmpTools = [
521
693
  getStockSplits,
522
694
  getDividendHistory
523
695
  ];
696
+ checkOpenAIAgentsVersion();
524
697
 
525
698
  exports.calendarTools = calendarTools;
526
699
  exports.companyTools = companyTools;