@discomedia/utils 1.0.3

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.
Files changed (70) hide show
  1. package/README.md +25 -0
  2. package/dist/index-frontend.cjs +7798 -0
  3. package/dist/index-frontend.cjs.map +1 -0
  4. package/dist/index-frontend.mjs +7792 -0
  5. package/dist/index-frontend.mjs.map +1 -0
  6. package/dist/index.cjs +17747 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.mjs +17741 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/test.js +6783 -0
  11. package/dist/test.js.map +1 -0
  12. package/dist/types/alpaca-market-data-api.d.ts +384 -0
  13. package/dist/types/alpaca-market-data-api.d.ts.map +1 -0
  14. package/dist/types/alpaca-trading-api.d.ts +318 -0
  15. package/dist/types/alpaca-trading-api.d.ts.map +1 -0
  16. package/dist/types/format-tools.d.ts +46 -0
  17. package/dist/types/format-tools.d.ts.map +1 -0
  18. package/dist/types/index-frontend.d.ts +18 -0
  19. package/dist/types/index-frontend.d.ts.map +1 -0
  20. package/dist/types/index.d.ts +150 -0
  21. package/dist/types/index.d.ts.map +1 -0
  22. package/dist/types/json-tools.d.ts +33 -0
  23. package/dist/types/json-tools.d.ts.map +1 -0
  24. package/dist/types/llm-config.d.ts +36 -0
  25. package/dist/types/llm-config.d.ts.map +1 -0
  26. package/dist/types/llm-deepseek.d.ts +12 -0
  27. package/dist/types/llm-deepseek.d.ts.map +1 -0
  28. package/dist/types/llm-images.d.ts +49 -0
  29. package/dist/types/llm-images.d.ts.map +1 -0
  30. package/dist/types/llm-openai.d.ts +64 -0
  31. package/dist/types/llm-openai.d.ts.map +1 -0
  32. package/dist/types/llm-utils.d.ts +16 -0
  33. package/dist/types/llm-utils.d.ts.map +1 -0
  34. package/dist/types/logging.d.ts +12 -0
  35. package/dist/types/logging.d.ts.map +1 -0
  36. package/dist/types/market-hours.d.ts +24 -0
  37. package/dist/types/market-hours.d.ts.map +1 -0
  38. package/dist/types/market-time.d.ts +184 -0
  39. package/dist/types/market-time.d.ts.map +1 -0
  40. package/dist/types/misc-utils.d.ts +49 -0
  41. package/dist/types/misc-utils.d.ts.map +1 -0
  42. package/dist/types/polygon-indices.d.ts +85 -0
  43. package/dist/types/polygon-indices.d.ts.map +1 -0
  44. package/dist/types/polygon.d.ts +126 -0
  45. package/dist/types/polygon.d.ts.map +1 -0
  46. package/dist/types/technical-analysis.d.ts +90 -0
  47. package/dist/types/technical-analysis.d.ts.map +1 -0
  48. package/dist/types/test.d.ts +2 -0
  49. package/dist/types/test.d.ts.map +1 -0
  50. package/dist/types/testing/frontend-test.d.ts +2 -0
  51. package/dist/types/testing/frontend-test.d.ts.map +1 -0
  52. package/dist/types/time-utils.d.ts +17 -0
  53. package/dist/types/time-utils.d.ts.map +1 -0
  54. package/dist/types/types/alpaca-types.d.ts +962 -0
  55. package/dist/types/types/alpaca-types.d.ts.map +1 -0
  56. package/dist/types/types/index.d.ts +7 -0
  57. package/dist/types/types/index.d.ts.map +1 -0
  58. package/dist/types/types/llm-types.d.ts +82 -0
  59. package/dist/types/types/llm-types.d.ts.map +1 -0
  60. package/dist/types/types/logging-types.d.ts +10 -0
  61. package/dist/types/types/logging-types.d.ts.map +1 -0
  62. package/dist/types/types/market-time-types.d.ts +59 -0
  63. package/dist/types/types/market-time-types.d.ts.map +1 -0
  64. package/dist/types/types/polygon-indices-types.d.ts +190 -0
  65. package/dist/types/types/polygon-indices-types.d.ts.map +1 -0
  66. package/dist/types/types/polygon-types.d.ts +204 -0
  67. package/dist/types/types/polygon-types.d.ts.map +1 -0
  68. package/dist/types/types/ta-types.d.ts +89 -0
  69. package/dist/types/types/ta-types.d.ts.map +1 -0
  70. package/package.json +50 -0
@@ -0,0 +1,318 @@
1
+ import { AlpacaMarketDataConfig } from './alpaca-market-data-api';
2
+ import { AlpacaAccountDetails, AlpacaCredentials, AlpacaPosition, AssetClass, GetOptionContractsParams, GetOrdersParams, OptionAccountActivity, OptionContract, OptionContractsResponse, AlpacaOrder, OrderLeg, TradeUpdate } from './types/alpaca-types';
3
+ /**
4
+ Websocket example
5
+ const alpacaAPI = createAlpacaTradingAPI(credentials); // type AlpacaCredentials
6
+ alpacaAPI.onTradeUpdate((update: TradeUpdate) => {
7
+ this.log(`Received trade update: event ${update.event} for an order to ${update.order.side} ${update.order.qty} of ${update.order.symbol}`);
8
+ });
9
+ alpacaAPI.connectWebsocket(); // necessary to connect to the WebSocket
10
+ */
11
+ export declare class AlpacaTradingAPI {
12
+ static new(credentials: AlpacaCredentials, marketDataConfig: AlpacaMarketDataConfig): AlpacaTradingAPI;
13
+ static getInstance(credentials: AlpacaCredentials, marketDataConfig: AlpacaMarketDataConfig): AlpacaTradingAPI;
14
+ private ws;
15
+ private headers;
16
+ private tradeUpdateCallback;
17
+ private credentials;
18
+ private apiBaseUrl;
19
+ private wsUrl;
20
+ private authenticated;
21
+ private connecting;
22
+ private reconnectDelay;
23
+ private reconnectTimeout;
24
+ private messageHandlers;
25
+ private debugLogging;
26
+ private marketDataAPI;
27
+ /**
28
+ * Constructor for AlpacaTradingAPI
29
+ * @param credentials - Alpaca credentials,
30
+ * accountName: string; // The account identifier used inthis.logs and tracking
31
+ * apiKey: string; // Alpaca API key
32
+ * apiSecret: string; // Alpaca API secret
33
+ * type: AlpacaAccountType;
34
+ * orderType: AlpacaOrderType;
35
+ * @param marketDataConfig - Market data API configuration
36
+ * @param options - Optional options
37
+ * debugLogging: boolean; // Whether to log messages of type 'debug'
38
+ */
39
+ constructor(credentials: AlpacaCredentials, marketDataConfig: AlpacaMarketDataConfig, options?: {
40
+ debugLogging?: boolean;
41
+ });
42
+ private log;
43
+ /**
44
+ * Round a price to the nearest 2 decimal places for Alpaca, or 4 decimal places for prices less than $1
45
+ * @param price - The price to round
46
+ * @returns The rounded price
47
+ */
48
+ private roundPriceForAlpaca;
49
+ private handleAuthMessage;
50
+ private handleListenMessage;
51
+ private handleTradeUpdate;
52
+ private handleMessage;
53
+ connectWebsocket(): void;
54
+ private authenticate;
55
+ private subscribeToTradeUpdates;
56
+ private makeRequest;
57
+ getPositions(assetClass?: AssetClass): Promise<AlpacaPosition[]>;
58
+ /**
59
+ * Get all orders
60
+ * @param params (GetOrdersParams) - optional parameters to filter the orders
61
+ * - status: 'open' | 'closed' | 'all'
62
+ * - limit: number
63
+ * - after: string
64
+ * - until: string
65
+ * - direction: 'asc' | 'desc'
66
+ * - nested: boolean
67
+ * - symbols: string[], an array of all the symbols
68
+ * - side: 'buy' | 'sell'
69
+ * @returns all orders
70
+ */
71
+ getOrders(params?: GetOrdersParams): Promise<AlpacaOrder[]>;
72
+ getAccountDetails(): Promise<AlpacaAccountDetails>;
73
+ /**
74
+ * Create a trailing stop order
75
+ * @param symbol (string) - the symbol of the order
76
+ * @param qty (number) - the quantity of the order
77
+ * @param side (string) - the side of the order
78
+ * @param trailPercent100 (number) - the trail percent of the order (scale 100, i.e. 0.5 = 0.5%)
79
+ * @param position_intent (string) - the position intent of the order
80
+ */
81
+ createTrailingStop(symbol: string, qty: number, side: 'buy' | 'sell', trailPercent100: number, position_intent: 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close'): Promise<void>;
82
+ /**
83
+ * Create a market order
84
+ * @param symbol (string) - the symbol of the order
85
+ * @param qty (number) - the quantity of the order
86
+ * @param side (string) - the side of the order
87
+ * @param position_intent (string) - the position intent of the order. Important for knowing if a position needs a trailing stop.
88
+ */
89
+ createMarketOrder(symbol: string, qty: number, side: 'buy' | 'sell', position_intent: 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close', client_order_id?: string): Promise<AlpacaOrder>;
90
+ /**
91
+ * Get the current trail percent for a symbol, assuming that it has an open position and a trailing stop order to close it. Because this relies on an orders request for one symbol, you can't do it too often.
92
+ * @param symbol (string) - the symbol of the order
93
+ * @returns the current trail percent
94
+ */
95
+ getCurrentTrailPercent(symbol: string): Promise<number | null>;
96
+ /**
97
+ * Update the trail percent for a trailing stop order
98
+ * @param symbol (string) - the symbol of the order
99
+ * @param trailPercent100 (number) - the trail percent of the order (scale 100, i.e. 0.5 = 0.5%)
100
+ */
101
+ updateTrailingStop(symbol: string, trailPercent100: number): Promise<void>;
102
+ /**
103
+ * Cancel all open orders
104
+ */
105
+ cancelAllOrders(): Promise<void>;
106
+ /**
107
+ * Cancel a specific order by its ID
108
+ * @param orderId The id of the order to cancel
109
+ * @throws Error if the order is not cancelable (status 422) or if the order doesn't exist
110
+ * @returns Promise that resolves when the order is successfully canceled
111
+ */
112
+ cancelOrder(orderId: string): Promise<void>;
113
+ /**
114
+ * Create a limit order
115
+ * @param symbol (string) - the symbol of the order
116
+ * @param qty (number) - the quantity of the order
117
+ * @param side (string) - the side of the order
118
+ * @param limitPrice (number) - the limit price of the order
119
+ * @param position_intent (string) - the position intent of the order
120
+ * @param extended_hours (boolean) - whether the order is in extended hours
121
+ * @param client_order_id (string) - the client order id of the order
122
+ */
123
+ createLimitOrder(symbol: string, qty: number, side: 'buy' | 'sell', limitPrice: number, position_intent: 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close', extended_hours?: boolean, client_order_id?: string): Promise<AlpacaOrder>;
124
+ /**
125
+ * Close all equities positions
126
+ * @param options (object) - the options for closing the positions
127
+ * - cancel_orders (boolean) - whether to cancel related orders
128
+ * - useLimitOrders (boolean) - whether to use limit orders to close the positions
129
+ */
130
+ closeAllPositions(options?: {
131
+ cancel_orders: boolean;
132
+ useLimitOrders: boolean;
133
+ }): Promise<void>;
134
+ /**
135
+ * Close all equities positions using limit orders during extended hours trading
136
+ * @param cancelOrders Whether to cancel related orders (default: true)
137
+ * @returns Promise that resolves when all positions are closed
138
+ */
139
+ closeAllPositionsAfterHours(): Promise<void>;
140
+ onTradeUpdate(callback: (update: TradeUpdate) => void): void;
141
+ /**
142
+ * Get portfolio history for the account
143
+ * @param params Parameters for the portfolio history request
144
+ * @returns Portfolio history data
145
+ */
146
+ getPortfolioHistory(params: {
147
+ timeframe?: '1Min' | '5Min' | '15Min' | '1H' | '1D';
148
+ period?: string;
149
+ extended_hours?: boolean;
150
+ date_end?: string;
151
+ }): Promise<{
152
+ timestamp: number[];
153
+ equity: number[];
154
+ profit_loss: number[];
155
+ profit_loss_pct: number[];
156
+ base_value: number;
157
+ timeframe: string;
158
+ }>;
159
+ /**
160
+ * Get option contracts based on specified parameters
161
+ * @param params Parameters to filter option contracts
162
+ * @returns Option contracts matching the criteria
163
+ */
164
+ getOptionContracts(params: GetOptionContractsParams): Promise<OptionContractsResponse>;
165
+ /**
166
+ * Get a specific option contract by symbol or ID
167
+ * @param symbolOrId The symbol or ID of the option contract
168
+ * @returns The option contract details
169
+ */
170
+ getOptionContract(symbolOrId: string): Promise<OptionContract>;
171
+ /**
172
+ * Create a simple option order (market or limit)
173
+ * @param symbol Option contract symbol
174
+ * @param qty Quantity of contracts (must be a whole number)
175
+ * @param side Buy or sell
176
+ * @param position_intent Position intent (buy_to_open, buy_to_close, sell_to_open, sell_to_close)
177
+ * @param type Order type (market or limit)
178
+ * @param limitPrice Limit price (required for limit orders)
179
+ * @returns The created order
180
+ */
181
+ createOptionOrder(symbol: string, qty: number, side: 'buy' | 'sell', position_intent: 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close', type: 'market' | 'limit', limitPrice?: number): Promise<AlpacaOrder>;
182
+ /**
183
+ * Create a multi-leg option order
184
+ * @param legs Array of order legs
185
+ * @param qty Quantity of the multi-leg order (must be a whole number)
186
+ * @param type Order type (market or limit)
187
+ * @param limitPrice Limit price (required for limit orders)
188
+ * @returns The created multi-leg order
189
+ */
190
+ createMultiLegOptionOrder(legs: OrderLeg[], qty: number, type: 'market' | 'limit', limitPrice?: number): Promise<AlpacaOrder>;
191
+ /**
192
+ * Exercise an option contract
193
+ * @param symbolOrContractId The symbol or ID of the option contract to exercise
194
+ * @returns Response from the exercise request
195
+ */
196
+ exerciseOption(symbolOrContractId: string): Promise<any>;
197
+ /**
198
+ * Get option positions
199
+ * @returns Array of option positions
200
+ */
201
+ getOptionPositions(): Promise<AlpacaPosition[]>;
202
+ getOptionsOpenSpreadTrades(): Promise<void>;
203
+ /**
204
+ * Get option account activities (exercises, assignments, expirations)
205
+ * @param activityType Type of option activity to filter by
206
+ * @param date Date to filter activities (YYYY-MM-DD format)
207
+ * @returns Array of option account activities
208
+ */
209
+ getOptionActivities(activityType?: 'OPEXC' | 'OPASN' | 'OPEXP', date?: string): Promise<OptionAccountActivity[]>;
210
+ /**
211
+ * Create a long call spread (buy lower strike call, sell higher strike call)
212
+ * @param lowerStrikeCallSymbol Symbol of the lower strike call option
213
+ * @param higherStrikeCallSymbol Symbol of the higher strike call option
214
+ * @param qty Quantity of spreads to create (must be a whole number)
215
+ * @param limitPrice Limit price for the spread
216
+ * @returns The created multi-leg order
217
+ */
218
+ createLongCallSpread(lowerStrikeCallSymbol: string, higherStrikeCallSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
219
+ /**
220
+ * Create a long put spread (buy higher strike put, sell lower strike put)
221
+ * @param higherStrikePutSymbol Symbol of the higher strike put option
222
+ * @param lowerStrikePutSymbol Symbol of the lower strike put option
223
+ * @param qty Quantity of spreads to create (must be a whole number)
224
+ * @param limitPrice Limit price for the spread
225
+ * @returns The created multi-leg order
226
+ */
227
+ createLongPutSpread(higherStrikePutSymbol: string, lowerStrikePutSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
228
+ /**
229
+ * Create an iron condor (sell call spread and put spread)
230
+ * @param longPutSymbol Symbol of the lower strike put (long)
231
+ * @param shortPutSymbol Symbol of the higher strike put (short)
232
+ * @param shortCallSymbol Symbol of the lower strike call (short)
233
+ * @param longCallSymbol Symbol of the higher strike call (long)
234
+ * @param qty Quantity of iron condors to create (must be a whole number)
235
+ * @param limitPrice Limit price for the iron condor (credit)
236
+ * @returns The created multi-leg order
237
+ */
238
+ createIronCondor(longPutSymbol: string, shortPutSymbol: string, shortCallSymbol: string, longCallSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
239
+ /**
240
+ * Create a covered call (sell call option against owned stock)
241
+ * @param stockSymbol Symbol of the underlying stock
242
+ * @param callOptionSymbol Symbol of the call option to sell
243
+ * @param qty Quantity of covered calls to create (must be a whole number)
244
+ * @param limitPrice Limit price for the call option
245
+ * @returns The created order
246
+ */
247
+ createCoveredCall(stockSymbol: string, callOptionSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
248
+ /**
249
+ * Roll an option position to a new expiration or strike
250
+ * @param currentOptionSymbol Symbol of the current option position
251
+ * @param newOptionSymbol Symbol of the new option to roll to
252
+ * @param qty Quantity of options to roll (must be a whole number)
253
+ * @param currentPositionSide Side of the current position ('buy' or 'sell')
254
+ * @param limitPrice Net limit price for the roll
255
+ * @returns The created multi-leg order
256
+ */
257
+ rollOptionPosition(currentOptionSymbol: string, newOptionSymbol: string, qty: number, currentPositionSide: 'buy' | 'sell', limitPrice: number): Promise<AlpacaOrder>;
258
+ /**
259
+ * Get option chain for a specific underlying symbol and expiration date
260
+ * @param underlyingSymbol The underlying stock symbol
261
+ * @param expirationDate The expiration date (YYYY-MM-DD format)
262
+ * @returns Option contracts for the specified symbol and expiration date
263
+ */
264
+ getOptionChain(underlyingSymbol: string, expirationDate: string): Promise<OptionContract[]>;
265
+ /**
266
+ * Get all available expiration dates for a specific underlying symbol
267
+ * @param underlyingSymbol The underlying stock symbol
268
+ * @returns Array of available expiration dates
269
+ */
270
+ getOptionExpirationDates(underlyingSymbol: string): Promise<string[]>;
271
+ /**
272
+ * Get the current options trading level for the account
273
+ * @returns The options trading level (0-3)
274
+ */
275
+ getOptionsTradingLevel(): Promise<number>;
276
+ /**
277
+ * Check if the account has options trading enabled
278
+ * @returns Boolean indicating if options trading is enabled
279
+ */
280
+ isOptionsEnabled(): Promise<boolean>;
281
+ /**
282
+ * Close all option positions
283
+ * @param cancelOrders Whether to cancel related orders (default: true)
284
+ * @returns Response from the close positions request
285
+ */
286
+ closeAllOptionPositions(cancelOrders?: boolean): Promise<void>;
287
+ /**
288
+ * Close a specific option position
289
+ * @param symbol The option contract symbol
290
+ * @param qty Optional quantity to close (defaults to entire position)
291
+ * @returns The created order
292
+ */
293
+ closeOptionPosition(symbol: string, qty?: number): Promise<AlpacaOrder>;
294
+ /**
295
+ * Create a complete equities trade with optional stop loss and take profit
296
+ * @param params Trade parameters including symbol, qty, side, and optional referencePrice
297
+ * @param options Trade options including order type, extended hours, stop loss, and take profit settings
298
+ * @returns The created order
299
+ */
300
+ createEquitiesTrade(params: {
301
+ symbol: string;
302
+ qty: number;
303
+ side: 'buy' | 'sell';
304
+ referencePrice?: number;
305
+ }, options?: {
306
+ type?: 'market' | 'limit';
307
+ limitPrice?: number;
308
+ extendedHours?: boolean;
309
+ useStopLoss?: boolean;
310
+ stopPrice?: number;
311
+ stopPercent100?: number;
312
+ useTakeProfit?: boolean;
313
+ takeProfitPrice?: number;
314
+ takeProfitPercent100?: number;
315
+ clientOrderId?: string;
316
+ }): Promise<AlpacaOrder>;
317
+ }
318
+ //# sourceMappingURL=alpaca-trading-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpaca-trading-api.d.ts","sourceRoot":"","sources":["../../src/alpaca-trading-api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,QAAQ,EACR,WAAW,EAGZ,MAAM,sBAAsB,CAAC;AAK9B;;;;;;;EAOE;AAEF,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,GAAG,gBAAgB;IAItG,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,GAA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AAE,CAAC;IA8BjG;;;;OAIG;IACG,wBAAwB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAsC3E;;;OAGG;IACG,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAO/C;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAiB1C;;;;OAIG;IACG,uBAAuB,CAAC,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC1E;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAyB7E;;;;;OAKG;IACG,mBAAmB,CACvB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,EACD,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;QAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GACA,OAAO,CAAC,WAAW,CAAC;CAqKxB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Capitalizes the first letter of a string
3
+ * @param {string} str - The string to capitalize
4
+ * @returns {string} The capitalized string, or original value if not a string
5
+ * @example
6
+ * capitalize('hello') // 'Hello'
7
+ * capitalize(123) // 123
8
+ */
9
+ export declare function capFirstLetter(str: string): string;
10
+ /**
11
+ * Formats a number as US currency
12
+ * @param {number} value - The number to format
13
+ * @returns {string} The formatted currency string (e.g. '$1,234.56')
14
+ * @example
15
+ * formatCurrency(1234.56) // '$1,234.56'
16
+ * formatCurrency(NaN) // '$0.00'
17
+ */
18
+ export declare function formatCurrency(value: number): string;
19
+ /**
20
+ * Formats a number with commas
21
+ * @param {number} value - The number to format
22
+ * @returns {string} The formatted number string (e.g. '1,234.56')
23
+ * @example
24
+ * formatNumber(1234.56) // '1,234.56'
25
+ * formatNumber(NaN) // '0'
26
+ */
27
+ export declare function formatNumber(value: number): string;
28
+ /**
29
+ * Formats a number as a percentage
30
+ * @param {number} value - The number to format (e.g. 0.75 for 75%)
31
+ * @param {number} [decimalPlaces=2] - Number of decimal places to show
32
+ * @returns {string} The formatted percentage string (e.g. '75.00%')
33
+ * @example
34
+ * formatPercentage(0.75) // '75.00%'
35
+ * formatPercentage(0.753, 1) // '75.3%'
36
+ */
37
+ export declare function formatPercentage(value: number, decimalPlaces?: number): string;
38
+ /**
39
+ * Formats a Date object to Australian datetime format for Google Sheets
40
+ * @param {Date} date - The date to format
41
+ * @returns {string} The formatted datetime string in 'DD/MM/YYYY HH:MM:SS' format
42
+ * @example
43
+ * dateTimeForGS(new Date('2025-01-01T12:34:56')) // '01/01/2025 12:34:56'
44
+ */
45
+ export declare function dateTimeForGS(date: Date): string;
46
+ //# sourceMappingURL=format-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-tools.d.ts","sourceRoot":"","sources":["../../src/format-tools.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASpD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,GAAE,MAAU,GAAG,MAAM,CAQjF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAYhD"}
@@ -0,0 +1,18 @@
1
+ import * as llm from './llm-openai';
2
+ import * as llmImages from './llm-images';
3
+ export type { LLMResponse, LLMOptions, LLMUsage, OpenAIModel, DeepseekModel, LLMModel, OpenAIResponseFormat, ImageGenerationOptions, ImageModel, ImageGenerateParams, ImagesResponse, Image } from './types/llm-types';
4
+ export declare const disco: {
5
+ llm: {
6
+ call: typeof llm.makeLLMCall;
7
+ seek: <T = any>(content: string | import("openai/resources/index").ChatCompletionContentPart[], responseFormat?: import("./types/llm-types").OpenAIResponseFormat, options?: import("./types/llm-types").LLMOptions) => Promise<import("./types/llm-types").LLMResponse<T>>;
8
+ images: typeof llmImages.makeImagesCall;
9
+ responsesAPI: <T = any>(input: string | import("openai/resources/responses/responses").ResponseCreateParamsNonStreaming["input"], options?: Omit<import("openai/resources/responses/responses").ResponseCreateParamsNonStreaming, "input" | "model"> & {
10
+ apiKey?: string;
11
+ model?: string;
12
+ }) => Promise<import("./types/llm-types").LLMResponse<T>>;
13
+ };
14
+ };
15
+ export { makeLLMCall, makeResponsesAPICall } from './llm-openai';
16
+ export { makeImagesCall } from './llm-images';
17
+ export { makeDeepseekCall } from './llm-deepseek';
18
+ //# sourceMappingURL=index-frontend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-frontend.d.ts","sourceRoot":"","sources":["../../src/index-frontend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAI1C,YAAY,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,WAAW,EACX,aAAa,EACb,QAAQ,EACR,oBAAoB,EACpB,sBAAsB,EACtB,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,KAAK,EACN,MAAM,mBAAmB,CAAC;AAG3B,eAAO,MAAM,KAAK;;;;;;kBAYsiE,CAAC;iBAAmB,CAAC;;;CAL5kE,CAAC;AAGF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,150 @@
1
+ import * as tu from './time-utils';
2
+ import * as mt from './market-time';
3
+ import * as ft from './format-tools';
4
+ import * as Types from './types';
5
+ import * as misc from './misc-utils';
6
+ import * as polygon from './polygon';
7
+ import * as llm from './llm-openai';
8
+ import * as llmImages from './llm-images';
9
+ import * as ta from './technical-analysis';
10
+ import { AlpacaMarketDataConfig } from './alpaca-market-data-api';
11
+ export * from './types';
12
+ export { AlpacaTradingAPI } from './alpaca-trading-api';
13
+ export { AlpacaMarketDataAPI, AlpacaMarketDataConfig } from './alpaca-market-data-api';
14
+ export declare const createAlpacaTradingAPI: (credentials: Types.AlpacaCredentials, marketDataConfig: AlpacaMarketDataConfig) => Types.AlpacaTradingAPI;
15
+ export declare const createAlpacaMarketDataAPI: (config: AlpacaMarketDataConfig) => Types.AlpacaMarketDataAPI;
16
+ export declare const disco: {
17
+ types: typeof Types;
18
+ alpaca: {
19
+ TradingAPI: typeof Types.AlpacaTradingAPI;
20
+ MarketDataAPI: typeof Types.AlpacaMarketDataAPI;
21
+ };
22
+ format: {
23
+ capFirstLetter: typeof ft.capFirstLetter;
24
+ currency: typeof ft.formatCurrency;
25
+ number: typeof ft.formatNumber;
26
+ pct: typeof ft.formatPercentage;
27
+ dateTimeForGS: typeof ft.dateTimeForGS;
28
+ };
29
+ indices: {
30
+ fetchAggregates: (params: Types.PolygonIndicesAggregatesParams, options?: {
31
+ apiKey?: string;
32
+ }) => Promise<Types.PolygonIndicesAggregatesResponse>;
33
+ fetchPreviousClose: (indicesTicker: string, options?: {
34
+ apiKey?: string;
35
+ }) => Promise<Types.PolygonIndicesPrevCloseResponse>;
36
+ fetchDailyOpenClose: (indicesTicker: string, date: string, options?: {
37
+ apiKey?: string;
38
+ }) => Promise<Types.PolygonIndicesDailyOpenCloseResponse>;
39
+ fetchSnapshot: (params?: Types.PolygonIndicesSnapshotParams, options?: {
40
+ apiKey?: string;
41
+ }) => Promise<Types.PolygonIndicesSnapshotResponse>;
42
+ fetchUniversalSnapshot: (tickers: string[], options?: {
43
+ apiKey?: string;
44
+ type?: string;
45
+ order?: string;
46
+ limit?: number;
47
+ sort?: string;
48
+ }) => Promise<any>;
49
+ formatBarData: (data: Types.PolygonIndicesAggregatesResponse) => Array<{
50
+ date: string;
51
+ open: number;
52
+ high: number;
53
+ low: number;
54
+ close: number;
55
+ timestamp: number;
56
+ }>;
57
+ };
58
+ llm: {
59
+ call: typeof llm.makeLLMCall;
60
+ seek: <T = any>(content: string | import("openai/resources/index").ChatCompletionContentPart[], responseFormat?: Types.OpenAIResponseFormat, options?: Types.LLMOptions) => Promise<Types.LLMResponse<T>>;
61
+ images: typeof llmImages.makeImagesCall;
62
+ };
63
+ polygon: {
64
+ fetchTickerInfo: (symbol: string, options?: {
65
+ apiKey?: string;
66
+ }) => Promise<Types.PolygonTickerInfo | null>;
67
+ fetchGroupedDaily: (date: string, options?: {
68
+ apiKey?: string;
69
+ adjusted?: boolean;
70
+ includeOTC?: boolean;
71
+ }) => Promise<Types.PolygonGroupedDailyResponse>;
72
+ fetchLastTrade: (symbol: string, options?: {
73
+ apiKey?: string;
74
+ }) => Promise<Types.PolygonQuote>;
75
+ fetchTrades: (symbol: string, options?: {
76
+ apiKey?: string;
77
+ timestamp?: string | number;
78
+ timestampgt?: string | number;
79
+ timestampgte?: string | number;
80
+ timestamplt?: string | number;
81
+ timestamplte?: string | number;
82
+ order?: "asc" | "desc";
83
+ limit?: number;
84
+ sort?: string;
85
+ }) => Promise<Types.PolygonTradesResponse>;
86
+ fetchPrices: (params: {
87
+ ticker: string;
88
+ start: number;
89
+ end?: number;
90
+ multiplier: number;
91
+ timespan: string;
92
+ limit?: number;
93
+ }, options?: {
94
+ apiKey?: string;
95
+ }) => Promise<Types.PolygonPriceData[]>;
96
+ analysePolygonPriceData: typeof polygon.analysePolygonPriceData;
97
+ formatPriceData: typeof polygon.formatPriceData;
98
+ fetchDailyOpenClose: (symbol: string, date?: Date, options?: {
99
+ apiKey?: string;
100
+ adjusted?: boolean;
101
+ }) => Promise<Types.PolygonDailyOpenClose>;
102
+ getPreviousClose: typeof polygon.getPreviousClose;
103
+ };
104
+ ta: {
105
+ calculateEMA: typeof ta.calculateEMA;
106
+ calculateMACD: typeof ta.calculateMACD;
107
+ calculateRSI: typeof ta.calculateRSI;
108
+ calculateStochasticOscillator: typeof ta.calculateStochasticOscillator;
109
+ calculateBollingerBands: typeof ta.calculateBollingerBands;
110
+ calculateSupportAndResistance: typeof ta.calculateSupportAndResistance;
111
+ calculateFibonacciLevels: typeof ta.calculateFibonacciLevels;
112
+ };
113
+ time: {
114
+ toUnixTimestamp: (ts: string) => number;
115
+ getTimeAgo: typeof tu.getTimeAgo;
116
+ timeAgo: (timestamp?: Date) => string;
117
+ normalizeDate: typeof tu.normalizeDate;
118
+ getDateInNY: typeof mt.getDateInNY;
119
+ createMarketTimeUtil: typeof mt.createMarketTimeUtil;
120
+ getStartAndEndTimestamps: typeof mt.getStartAndEndTimestamps;
121
+ getStartAndEndDates: typeof mt.getStartAndEndDates;
122
+ getMarketOpenClose: typeof mt.getMarketOpenClose;
123
+ calculateTimeRange: typeof tu.calculateTimeRange;
124
+ calculateDaysLeft: (accountCreationDate: Date) => number;
125
+ formatDate: (dateString: string, updateDate?: boolean) => string;
126
+ currentTimeET: () => Date;
127
+ MarketTimeUtil: typeof mt.MarketTimeUtil;
128
+ MARKET_TIMES: Types.MarketTimesConfig;
129
+ getLastTradingDateYYYYMMDD: typeof mt.getLastTradingDateYYYYMMDD;
130
+ getLastFullTradingDate: typeof mt.getLastFullTradingDate;
131
+ getNextMarketDay: typeof mt.getNextMarketDay;
132
+ parseETDateFromAV: (dateString: string) => Date;
133
+ formatToUSEastern: (date: Date, justDate?: boolean) => string;
134
+ unixTimetoUSEastern: (timestamp: number) => {
135
+ date: Date;
136
+ timeString: string;
137
+ dateString: string;
138
+ };
139
+ getMarketStatus: typeof mt.getMarketStatus;
140
+ timeDiffString: (milliseconds: number) => string;
141
+ getNYTimeZone: (date?: Date) => "-04:00" | "-05:00";
142
+ getTradingDate: typeof mt.getTradingDate;
143
+ };
144
+ utils: {
145
+ logIfDebug: (message: string, data?: unknown, type?: "info" | "warn" | "error" | "debug" | "trace") => void;
146
+ fetchWithRetry: typeof misc.fetchWithRetry;
147
+ validatePolygonApiKey: typeof misc.validatePolygonApiKey;
148
+ };
149
+ };
150
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3C,OAAO,EAAuB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGvF,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGvF,eAAO,MAAM,sBAAsB,GAAI,aAAa,KAAK,CAAC,iBAAiB,EAAE,kBAAkB,sBAAsB,2BAEpH,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,QAAQ,sBAAsB,8BAEvE,CAAC;AAEF,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;kBAgBO,CAAA;;;kBAuCiB,CAAC;;;kBAwB4Y,CAAC;;;kBAAkwC,CAAC;;;kBAAisD,CAAC;gBAAkB,CAAC;iBAAmB,CAAC;iBAAmB,CAAC;gBAAkB,CAAC;;;;;;;;;;;;;;;;;;kBA/Ev8G,CAAC;;;kBA+EipQ,CAAC;oBAAsB,CAAC;sBAAyB,CAAC;;;kBAAhxP,CAAC;;;kBAA6jc,CAAC;qBAAuB,CAAC;uBAAkC,CAAC;wBAAmC,CAAC;uBAAkC,CAAC;wBAAmC,CAAC;iBAA4B,CAAC;iBAA2B,CAAC;gBAAkB,CAAC;;;;;eAAjgX,CAAC;;;iBAAiE,CAAC;;kBAAmC,CAAC;;;;;kBAA65Q,CAAC;oBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADnwX,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Fix a broken JSON string by attempting to extract and parse valid JSON content. This function is very lenient and will attempt to fix many types of JSON errors, including unbalanced brackets, missing or extra commas, improperly escaped $ signs, unquoted strings, trailing commas, missing closing brackets or braces, etc.
3
+ * @param {string} jsonStr - The broken JSON string to fix
4
+ * @returns {JsonValue} - The parsed JSON value
5
+ */
6
+ export declare function fixBrokenJson(jsonStr: string): JsonValue;
7
+ /**
8
+ * Returns true if the given JSON string is valid, false otherwise.
9
+ *
10
+ * This function simply attempts to parse the given string as JSON and returns true if successful, or false if an error is thrown.
11
+ *
12
+ * @param {string} jsonString The JSON string to validate.
13
+ * @returns {boolean} True if the JSON string is valid, false otherwise.
14
+ */
15
+ export declare function isValidJson(jsonString: string): boolean;
16
+ interface JsonObject {
17
+ [key: string]: JsonValue;
18
+ }
19
+ type JsonArray = JsonValue[];
20
+ type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
21
+ /**
22
+ * Fixes broken JSON by sending it to the OpenAI GPT-4.1-mini model as a chat completion.
23
+ * The GPT-4.1-mini model is a large language model that can understand and generate code,
24
+ * including JSON. The returned JSON is the fixed version of the input JSON.
25
+ * If the model fails to return valid JSON, an error is thrown.
26
+ * @param jsonStr - the broken JSON to fix
27
+ * @param apiKey - the OpenAI API key to use, or undefined to use the value of the OPENAI_API_KEY environment variable
28
+ * @returns the fixed JSON
29
+ * @throws an error if the model fails to return valid JSON
30
+ */
31
+ export declare function fixJsonWithAI(jsonStr: string, apiKey?: string): Promise<JsonValue>;
32
+ export {};
33
+ //# sourceMappingURL=json-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-tools.d.ts","sourceRoot":"","sources":["../../src/json-tools.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAmMxD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAOvD;AAGD,UAAU,UAAU;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AACD,KAAK,SAAS,GAAG,SAAS,EAAE,CAAC;AAC7B,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC;AAqB3E;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CA+BxF"}
@@ -0,0 +1,36 @@
1
+ export declare const DEFAULT_MODEL = "gpt-4.1-mini";
2
+ export declare const DEFAULT_DEVELOPER_PROMPT = "\n You are a highly experienced coding, business analyst, and financial analyst associate.\n Help with coding, business process design and analysis, data generation and refinement, content creation, financial analysis, and more.\n When presented with a coding problem, logic problem, or other problem benefiting from systematic thinking, think through it step by step before giving your final answer.\n Present complete, high-confidence, final answers only. Do not rephrase to be more brief or omit parts of answers.\n Respond only with final content (e.g. code, a json or yaml object, a formatted string, or a markdown document) and nothing else. Do not reply with a preamble, introduction, or conclusion.\n";
3
+ interface AIModelCosts {
4
+ [modelName: string]: {
5
+ inputCost: number;
6
+ outputCost: number;
7
+ cacheHitCost?: number;
8
+ };
9
+ }
10
+ /** Token costs in USD per 1M tokens. Last updated Feb 2025. */
11
+ export declare const openAiModelCosts: AIModelCosts;
12
+ export declare const deepseekModelCosts: AIModelCosts;
13
+ /** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
14
+ export declare const openAiImageCosts: Record<string, number>;
15
+ /**
16
+ * Calculates the cost of generating images using OpenAI's Images API.
17
+ *
18
+ * @param model The image generation model name.
19
+ * @param imageCount The number of images generated.
20
+ * @returns The cost of generating the images in USD.
21
+ */
22
+ export declare function calculateImageCost(model: string, imageCount: number): number;
23
+ /**
24
+ * Calculates the cost of calling a language model in USD based on the provider and model, tokens, and given costs per 1M tokens.
25
+ *
26
+ * @param provider The provider of the language model. Supported providers are 'openai' and 'deepseek'.
27
+ * @param model The name of the language model. Supported models are listed in the `openAiModelCosts` and `deepseekModelCosts` objects.
28
+ * @param inputTokens The number of input tokens passed to the language model.
29
+ * @param outputTokens The number of output tokens generated by the language model.
30
+ * @param reasoningTokens The number of output tokens generated by the language model for reasoning. This is only used for Deepseek models.
31
+ * @param cacheHitTokens The number of input tokens that were cache hits for Deepseek models.
32
+ * @returns The cost of calling the language model in USD.
33
+ */
34
+ export declare function calculateCost(provider: string, model: string, inputTokens: number, outputTokens: number, reasoningTokens?: number, cacheHitTokens?: number): number;
35
+ export {};
36
+ //# sourceMappingURL=llm-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-config.d.ts","sourceRoot":"","sources":["../../src/llm-config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAE5C,eAAO,MAAM,wBAAwB,wtBAMpC,CAAC;AAEF,UAAU,YAAY;IACpB,CAAC,SAAS,EAAE,MAAM,GAAG;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,EAAE,YAyC9B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,YAWhC,CAAC;AAEF,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAEnD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAS5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,eAAe,CAAC,EAAE,MAAM,EACxB,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,CA0BR"}
@@ -0,0 +1,12 @@
1
+ import { ChatCompletionContentPart } from 'openai/resources/chat';
2
+ import { LLMResponse, LLMOptions, OpenAIResponseFormat } from './types';
3
+ /**
4
+ * Makes a call to the Deepseek AI API.
5
+ *
6
+ * @param content The content to pass to the LLM. Can be a string or an array of content parts.
7
+ * @param responseFormat The format of the response. Defaults to 'json'.
8
+ * @param options Configuration options including model ('deepseek-chat' or 'deepseek-reasoner'), tools, and apiKey.
9
+ * @return A promise that resolves to the response from the Deepseek API.
10
+ */
11
+ export declare const makeDeepseekCall: <T = any>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions) => Promise<LLMResponse<T>>;
12
+ //# sourceMappingURL=llm-deepseek.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-deepseek.d.ts","sourceRoot":"","sources":["../../src/llm-deepseek.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EAG1B,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAe,oBAAoB,EAA2B,MAAM,SAAS,CAAC;AAyL9G;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAU,CAAC,GAAG,GAAG,EAC5C,SAAS,MAAM,GAAG,yBAAyB,EAAE,EAC7C,iBAAgB,oBAA6B,EAC7C,UAAS,UAAe,KACvB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAkIxB,CAAC"}