@discomedia/utils 1.0.25 → 1.0.27

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 (50) hide show
  1. package/dist/alpaca-trading-api-6NxNgQBn.js +1413 -0
  2. package/dist/alpaca-trading-api-6NxNgQBn.js.map +1 -0
  3. package/dist/index-frontend.cjs +105 -12
  4. package/dist/index-frontend.cjs.map +1 -1
  5. package/dist/index-frontend.mjs +105 -13
  6. package/dist/index-frontend.mjs.map +1 -1
  7. package/dist/index.cjs +257 -43
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.mjs +257 -44
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/package.json +3 -3
  12. package/dist/test.js +868 -5517
  13. package/dist/test.js.map +1 -1
  14. package/dist/types/alpaca-trading-api.d.ts +33 -0
  15. package/dist/types/alpaca-trading-api.d.ts.map +1 -1
  16. package/dist/types/index-frontend.d.ts +1 -1
  17. package/dist/types/index.d.ts +3 -1
  18. package/dist/types/index.d.ts.map +1 -1
  19. package/dist/types/json-tools.d.ts.map +1 -1
  20. package/dist/types/llm-deepseek.d.ts +1 -1
  21. package/dist/types/llm-deepseek.d.ts.map +1 -1
  22. package/dist/types/llm-images.d.ts.map +1 -1
  23. package/dist/types/llm-openai.d.ts +2 -2
  24. package/dist/types/llm-openai.d.ts.map +1 -1
  25. package/dist/types/llm-openrouter.d.ts +28 -0
  26. package/dist/types/llm-openrouter.d.ts.map +1 -0
  27. package/dist/types/misc-utils.d.ts.map +1 -1
  28. package/dist/types/types/llm-types.d.ts +26 -3
  29. package/dist/types/types/llm-types.d.ts.map +1 -1
  30. package/dist/types/types/logging-types.d.ts +1 -1
  31. package/dist/types/types/logging-types.d.ts.map +1 -1
  32. package/dist/types-frontend/alpaca-trading-api.d.ts +33 -0
  33. package/dist/types-frontend/alpaca-trading-api.d.ts.map +1 -1
  34. package/dist/types-frontend/index-frontend.d.ts +1 -1
  35. package/dist/types-frontend/index.d.ts +3 -1
  36. package/dist/types-frontend/index.d.ts.map +1 -1
  37. package/dist/types-frontend/json-tools.d.ts.map +1 -1
  38. package/dist/types-frontend/llm-deepseek.d.ts +1 -1
  39. package/dist/types-frontend/llm-deepseek.d.ts.map +1 -1
  40. package/dist/types-frontend/llm-images.d.ts.map +1 -1
  41. package/dist/types-frontend/llm-openai.d.ts +2 -2
  42. package/dist/types-frontend/llm-openai.d.ts.map +1 -1
  43. package/dist/types-frontend/llm-openrouter.d.ts +28 -0
  44. package/dist/types-frontend/llm-openrouter.d.ts.map +1 -0
  45. package/dist/types-frontend/misc-utils.d.ts.map +1 -1
  46. package/dist/types-frontend/types/llm-types.d.ts +26 -3
  47. package/dist/types-frontend/types/llm-types.d.ts.map +1 -1
  48. package/dist/types-frontend/types/logging-types.d.ts +1 -1
  49. package/dist/types-frontend/types/logging-types.d.ts.map +1 -1
  50. package/package.json +3 -3
@@ -12,8 +12,28 @@ import require$$0$4 from 'fs';
12
12
  import require$$1$1 from 'path';
13
13
  import require$$2$1 from 'os';
14
14
 
15
+ /**
16
+ * Type guard to check if a model is an OpenRouter model
17
+ */
18
+ function isOpenRouterModel(model) {
19
+ const openRouterModels = [
20
+ 'openai/gpt-5',
21
+ 'openai/gpt-5-mini',
22
+ 'openai/gpt-5-nano',
23
+ 'openai/gpt-oss-120b',
24
+ 'z.ai/glm-4.5',
25
+ 'z.ai/glm-4.5-air',
26
+ 'google/gemini-2.5-flash',
27
+ 'google/gemini-2.5-flash-lite',
28
+ 'deepseek/deepseek-r1-0528',
29
+ 'deepseek/deepseek-chat-v3-0324',
30
+ ];
31
+ return openRouterModels.includes(model);
32
+ }
33
+
15
34
  var Types = /*#__PURE__*/Object.freeze({
16
- __proto__: null
35
+ __proto__: null,
36
+ isOpenRouterModel: isOpenRouterModel
17
37
  });
18
38
 
19
39
  function __classPrivateFieldSet(receiver, state, value, kind, f) {
@@ -247,7 +267,7 @@ const safeJSON = (text) => {
247
267
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
248
268
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
249
269
 
250
- const VERSION = '5.12.1'; // x-release-please-version
270
+ const VERSION = '5.12.2'; // x-release-please-version
251
271
 
252
272
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
253
273
  const isRunningInBrowser = () => {
@@ -7042,7 +7062,8 @@ function fixBrokenJson(jsonStr) {
7042
7062
  return parse();
7043
7063
  }
7044
7064
  catch (error) {
7045
- console.error(`Error parsing JSON at position ${index}: ${error.message}`);
7065
+ const msg = error instanceof Error ? error.message : String(error);
7066
+ console.error(`Error parsing JSON at position ${index}: ${msg}`);
7046
7067
  return null;
7047
7068
  }
7048
7069
  }
@@ -7586,7 +7607,13 @@ async function makeImagesCall(prompt, options = {}) {
7586
7607
  const enhancedResponse = {
7587
7608
  ...response,
7588
7609
  usage: {
7589
- ...response.usage,
7610
+ // OpenAI Images response may not include usage details per image; preserve if present
7611
+ ...(response.usage ?? {
7612
+ input_tokens: 0,
7613
+ input_tokens_details: { image_tokens: 0, text_tokens: 0 },
7614
+ output_tokens: 0,
7615
+ total_tokens: 0,
7616
+ }),
7590
7617
  provider: 'openai',
7591
7618
  model: 'gpt-image-1',
7592
7619
  cost,
@@ -7595,7 +7622,8 @@ async function makeImagesCall(prompt, options = {}) {
7595
7622
  return enhancedResponse;
7596
7623
  }
7597
7624
  catch (error) {
7598
- throw new Error(`OpenAI Images API call failed: ${error.message}`);
7625
+ const message = error instanceof Error ? error.message : 'Unknown error';
7626
+ throw new Error(`OpenAI Images API call failed: ${message}`);
7599
7627
  }
7600
7628
  }
7601
7629
 
@@ -7820,14 +7848,15 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
7820
7848
  const completion = await createDeepseekCompletion(content, responseFormat, mergedOptions);
7821
7849
  // Handle tool calls similarly to OpenAI
7822
7850
  if (completion.tool_calls && completion.tool_calls.length > 0) {
7851
+ const fnCalls = completion.tool_calls
7852
+ .filter((tc) => tc.type === 'function')
7853
+ .map((tc) => ({
7854
+ id: tc.id,
7855
+ name: tc.function.name,
7856
+ arguments: JSON.parse(tc.function.arguments),
7857
+ }));
7823
7858
  return {
7824
- response: {
7825
- tool_calls: completion.tool_calls.map((tc) => ({
7826
- id: tc.id,
7827
- name: tc.function.name,
7828
- arguments: JSON.parse(tc.function.arguments),
7829
- })),
7830
- },
7859
+ response: { tool_calls: fnCalls },
7831
7860
  usage: {
7832
7861
  prompt_tokens: completion.usage.prompt_tokens,
7833
7862
  completion_tokens: completion.usage.completion_tokens,
@@ -14650,6 +14679,18 @@ Websocket example
14650
14679
  this.log(`Received trade update: event ${update.event} for an order to ${update.order.side} ${update.order.qty} of ${update.order.symbol}`);
14651
14680
  });
14652
14681
  alpacaAPI.connectWebsocket(); // necessary to connect to the WebSocket
14682
+
14683
+ Portfolio History examples
14684
+ // Get standard portfolio history
14685
+ const portfolioHistory = await alpacaAPI.getPortfolioHistory({
14686
+ timeframe: '1D',
14687
+ period: '1M'
14688
+ });
14689
+
14690
+ // Get daily portfolio history with current day included (if available from hourly data)
14691
+ const dailyHistory = await alpacaAPI.getPortfolioDailyHistory({
14692
+ period: '1M'
14693
+ });
14653
14694
  */
14654
14695
  class AlpacaTradingAPI {
14655
14696
  static new(credentials) {
@@ -15349,6 +15390,57 @@ class AlpacaTradingAPI {
15349
15390
  const response = await this.makeRequest(`/account/portfolio/history?${queryParams.toString()}`);
15350
15391
  return response;
15351
15392
  }
15393
+ /**
15394
+ * Get portfolio daily history for the account, ensuring the most recent day is included
15395
+ * by combining daily and hourly history if needed.
15396
+ *
15397
+ * This function performs two API calls:
15398
+ * 1. Retrieves daily portfolio history
15399
+ * 2. Retrieves hourly portfolio history to check for more recent data
15400
+ *
15401
+ * If hourly history has timestamps more recent than the last timestamp in daily history,
15402
+ * it appends one additional day to the daily history using the most recent hourly values.
15403
+ *
15404
+ * @param params Parameters for the portfolio history request (same as getPortfolioHistory except timeframe is forced to '1D')
15405
+ * @returns Portfolio history data with daily timeframe, including the most recent day if available from hourly data
15406
+ */
15407
+ async getPortfolioDailyHistory(params) {
15408
+ // Get daily history
15409
+ const dailyParams = { ...params, timeframe: '1D' };
15410
+ const dailyHistory = await this.getPortfolioHistory(dailyParams);
15411
+ // Get hourly history for the last day to check for more recent data
15412
+ const hourlyParams = { timeframe: '1H', period: '1D' };
15413
+ const hourlyHistory = await this.getPortfolioHistory(hourlyParams);
15414
+ // If no hourly history, return daily as-is
15415
+ if (!hourlyHistory.timestamp || hourlyHistory.timestamp.length === 0) {
15416
+ return dailyHistory;
15417
+ }
15418
+ // Get the last timestamp from daily history
15419
+ const lastDailyTimestamp = dailyHistory.timestamp[dailyHistory.timestamp.length - 1];
15420
+ // Check if hourly history has more recent data
15421
+ const recentHourlyData = hourlyHistory.timestamp
15422
+ .map((timestamp, index) => ({ timestamp, index }))
15423
+ .filter(({ timestamp }) => timestamp > lastDailyTimestamp);
15424
+ // If no more recent hourly data, return daily history as-is
15425
+ if (recentHourlyData.length === 0) {
15426
+ return dailyHistory;
15427
+ }
15428
+ // Get the most recent hourly data point
15429
+ const mostRecentHourly = recentHourlyData[recentHourlyData.length - 1];
15430
+ const mostRecentIndex = mostRecentHourly.index;
15431
+ // Calculate the timestamp for the new daily entry (most recent day + 1 day worth of seconds)
15432
+ const oneDayInSeconds = 24 * 60 * 60;
15433
+ const newDailyTimestamp = mostRecentHourly.timestamp + oneDayInSeconds;
15434
+ // Create a new daily history entry with the most recent hourly values
15435
+ const updatedDailyHistory = {
15436
+ ...dailyHistory,
15437
+ timestamp: [...dailyHistory.timestamp, newDailyTimestamp],
15438
+ equity: [...dailyHistory.equity, hourlyHistory.equity[mostRecentIndex]],
15439
+ profit_loss: [...dailyHistory.profit_loss, hourlyHistory.profit_loss[mostRecentIndex]],
15440
+ profit_loss_pct: [...dailyHistory.profit_loss_pct, hourlyHistory.profit_loss_pct[mostRecentIndex]],
15441
+ };
15442
+ return updatedDailyHistory;
15443
+ }
15352
15444
  /**
15353
15445
  * Get option contracts based on specified parameters
15354
15446
  * @param params Parameters to filter option contracts
@@ -15984,5 +16076,5 @@ const disco = {
15984
16076
  },
15985
16077
  };
15986
16078
 
15987
- export { AlpacaMarketDataAPI, AlpacaTradingAPI, disco };
16079
+ export { AlpacaMarketDataAPI, AlpacaTradingAPI, disco, isOpenRouterModel };
15988
16080
  //# sourceMappingURL=index-frontend.mjs.map