@tradejs/app 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/app",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Installable Next.js UI for the TradeJS TypeScript framework: dashboards, backtests, charts, and runtime data.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -49,15 +49,11 @@
49
49
  "@chakra-ui/charts": "3.36.1",
50
50
  "@chakra-ui/react": "3.36.1",
51
51
  "@emotion/react": "^11.14.0",
52
- "@langchain/core": "^1.2.3",
53
- "@langchain/openai": "^1.5.5",
54
- "@tradejs/connectors": "^3.0.0",
55
- "@tradejs/core": "^3.0.0",
56
- "@tradejs/indicators": "^3.0.0",
57
- "@tradejs/infra": "^3.0.0",
58
- "@tradejs/node": "^3.0.0",
59
- "@tradejs/strategies": "^3.0.0",
60
- "@tradejs/types": "^3.0.0",
52
+ "@tradejs/core": "^3.1.0",
53
+ "@tradejs/indicators": "^3.1.0",
54
+ "@tradejs/infra": "^3.1.0",
55
+ "@tradejs/node": "^3.1.0",
56
+ "@tradejs/types": "^3.1.0",
61
57
  "@types/bcryptjs": "2.4.6",
62
58
  "@types/lodash": "4.17.24",
63
59
  "@types/node": "24.13.3",
@@ -1,6 +1,8 @@
1
1
  import { API } from '@tradejs/core/api';
2
- import type { StrategyChartsSnapshotResponse } from '@tradejs/types';
3
- import type { RuntimeStrategiesResponse } from '#app/lib/runtimeStrategyContracts';
2
+ import type {
3
+ RuntimeStrategiesResponse,
4
+ StrategyChartsSnapshotResponse,
5
+ } from '@tradejs/types';
4
6
 
5
7
  const API_PATH = '/api/strategies/runtime';
6
8
  const REPLAY_API_PATH = '/api/strategies/replay';
@@ -1,19 +1,11 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { ChatOpenAI } from '@langchain/openai';
3
- import {
4
- BaseMessage,
5
- HumanMessage,
6
- SystemMessage,
7
- } from '@langchain/core/messages';
8
2
  import { TTL_1M } from '@tradejs/core/constants';
9
3
  import { toJson } from '@tradejs/core/data';
10
4
  import {
11
5
  getAiResponseLanguagePromptName,
12
6
  normalizeAiResponseLanguage,
13
7
  } from '@tradejs/core/aiLanguages';
14
- import { normalizeAiEndpoint } from '@tradejs/core/aiEndpoints';
15
- import { normalizeAiModel } from '@tradejs/core/aiModels';
16
- import { DEFAULT_AI_MODEL, getOpenRouterModelKwargs } from '@tradejs/node/ai';
8
+ import { invokeAiChat, type AiChatMessage } from '@tradejs/node/ai';
17
9
  import {
18
10
  AIChatHistory,
19
11
  AIChatMessage,
@@ -74,56 +66,31 @@ const buildMessages = (
74
66
  historyData: unknown,
75
67
  responseLanguage: string,
76
68
  ) => {
77
- const messages = new Array<BaseMessage>();
78
-
79
- messages.push(
80
- new SystemMessage(
81
- `You are a crypto trader assistant. Reply in ${getAiResponseLanguagePromptName(
82
- responseLanguage,
83
- )}.`,
84
- ),
85
- );
86
-
87
- messages.push(
88
- new SystemMessage(
89
- `Here is the market data for ${filters.symbol}: ${toJson(historyData)}`,
90
- ),
91
- );
69
+ const messages: AiChatMessage[] = [];
70
+
71
+ messages.push({
72
+ role: 'system',
73
+ content: `You are a crypto trader assistant. Reply in ${getAiResponseLanguagePromptName(
74
+ responseLanguage,
75
+ )}.`,
76
+ });
77
+
78
+ messages.push({
79
+ role: 'system',
80
+ content: `Here is the market data for ${filters.symbol}: ${toJson(historyData)}`,
81
+ });
92
82
 
93
83
  if (historyEntry.command === '/line') {
94
- messages.push(new HumanMessage(historyEntry.text));
84
+ messages.push({ role: 'user', content: historyEntry.text });
95
85
  }
96
86
 
97
87
  if (historyEntry.command === 'prompt') {
98
- messages.push(new HumanMessage(historyEntry.text));
88
+ messages.push({ role: 'user', content: historyEntry.text });
99
89
  }
100
90
 
101
91
  return messages;
102
92
  };
103
93
 
104
- const invokeChatModel = async (messages: BaseMessage[], userName: string) => {
105
- const settings = await getUserSettings(userName);
106
- const endpoint = normalizeAiEndpoint(settings.AI_API_ENDPOINT);
107
- if (!settings.AI_API_KEY || !endpoint) {
108
- throw new Error(`AI settings are incomplete for user ${userName}`);
109
- }
110
-
111
- const modelKwargs = getOpenRouterModelKwargs(endpoint);
112
-
113
- const model = new ChatOpenAI({
114
- temperature: 0.7,
115
- modelName:
116
- normalizeAiModel(settings.AI_MODEL, endpoint) || DEFAULT_AI_MODEL,
117
- apiKey: settings.AI_API_KEY,
118
- ...(Object.keys(modelKwargs).length ? { modelKwargs } : {}),
119
- configuration: {
120
- baseURL: endpoint,
121
- },
122
- });
123
-
124
- return model.invoke(messages);
125
- };
126
-
127
94
  export const GET = async (request: NextRequest) => {
128
95
  try {
129
96
  const userName = await getCurrentUserName();
@@ -210,7 +177,11 @@ export const POST = async (request: NextRequest) => {
210
177
  normalizeAiResponseLanguage(settings.AI_RESPONSE_LANGUAGE),
211
178
  );
212
179
 
213
- const response = await invokeChatModel(chatMessages, userName);
180
+ const response = await invokeAiChat({
181
+ messages: chatMessages,
182
+ userName,
183
+ temperature: 0.7,
184
+ });
214
185
 
215
186
  const responseMessage: AIChatMessage = {
216
187
  from: 'ai',
@@ -1,7 +1,7 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
  import { logger } from '@tradejs/infra/logger';
3
+ import { loadRuntimeDashboard } from '@tradejs/node/runtimeDashboard';
3
4
  import { getCurrentUserName } from '#app/lib/currentUser';
4
- import { loadRuntimeDashboard } from '#app/lib/runtimeDashboard';
5
5
 
6
6
  export const dynamic = 'force-dynamic';
7
7
 
@@ -3,7 +3,11 @@ import {
3
3
  getFormatted,
4
4
  type AdvancedTradeInput,
5
5
  } from '@tradejs/core/backtest';
6
- import type { TestThresholdsKey, ThresholdLevel } from '@tradejs/types';
6
+ import type {
7
+ RuntimeStrategyView,
8
+ TestThresholdsKey,
9
+ ThresholdLevel,
10
+ } from '@tradejs/types';
7
11
  import {
8
12
  formatCompactNumber,
9
13
  formatFee,
@@ -16,7 +20,6 @@ import {
16
20
  type OrdersDrawerOrder,
17
21
  type OrdersDrawerSummaryItem,
18
22
  } from '#components/Shared/OrdersDrawer';
19
- import type { RuntimeStrategyView } from '#app/lib/runtimeStrategyContracts';
20
23
  import {
21
24
  buildStrategyPerformanceViewModel,
22
25
  calculateMaxLossStreak,
@@ -13,12 +13,11 @@ import {
13
13
  Text,
14
14
  } from '@chakra-ui/react';
15
15
  import { getFormatted } from '@tradejs/core/backtest';
16
- import type { TestThresholdsKey } from '@tradejs/types';
16
+ import type { RuntimeStrategyView, TestThresholdsKey } from '@tradejs/types';
17
17
  import {
18
18
  formatDateTime,
19
19
  OrdersDrawerPanel,
20
20
  } from '#components/Shared/OrdersDrawer';
21
- import type { RuntimeStrategyView } from '#app/lib/runtimeStrategyContracts';
22
21
  import { RuntimeStrategyChart } from './RuntimeStrategyChart';
23
22
  import { RuntimeStrategyConfigDrawer } from './RuntimeStrategyConfigDrawer';
24
23
  import { RuntimeStrategyStatsDrawer } from './RuntimeStrategyStatsDrawer';
@@ -21,8 +21,7 @@ import {
21
21
  Text,
22
22
  Textarea,
23
23
  } from '@chakra-ui/react';
24
- import type { MarketUniverse } from '@tradejs/types';
25
- import type { RuntimeStrategyView } from '#app/lib/runtimeStrategyContracts';
24
+ import type { MarketUniverse, RuntimeStrategyView } from '@tradejs/types';
26
25
  import {
27
26
  DEFAULT_RUNTIME_STRATEGY_MANAGED_PARAMETERS,
28
27
  mergeRuntimeStrategyManagedParameters,
@@ -10,7 +10,7 @@ import {
10
10
  SimpleGrid,
11
11
  Text,
12
12
  } from '@chakra-ui/react';
13
- import type { ThresholdLevel } from '@tradejs/types';
13
+ import type { RuntimeStrategyView, ThresholdLevel } from '@tradejs/types';
14
14
  import {
15
15
  formatInteger,
16
16
  formatPercent,
@@ -18,7 +18,6 @@ import {
18
18
  getPnlColor,
19
19
  type OrdersDrawerSummaryItem,
20
20
  } from '#components/Shared/OrdersDrawer';
21
- import type { RuntimeStrategyView } from '#app/lib/runtimeStrategyContracts';
22
21
  import { buildQuarterlyMonthlyStats } from '#app/lib/strategyPerformance';
23
22
  import { AdvancedMetricsPanel } from './AdvancedMetricsPanel';
24
23
  import {
@@ -1,4 +1,3 @@
1
- import { getConnectorCreatorByProvider as getBuiltinConnectorCreatorByProvider } from '@tradejs/connectors';
2
1
  import { resolveTradingAccount } from '@tradejs/infra/tradingAccounts';
3
2
  import { getConnectorCreatorByProvider as getRegisteredConnectorCreatorByProvider } from '@tradejs/node/connectors';
4
3
  import { ConnectorCreator, MarketUniverse } from '@tradejs/types';
@@ -35,13 +34,5 @@ export const resolveConnectorCreatorByProvider = async (
35
34
  projectRoot,
36
35
  ));
37
36
 
38
- if (registeredConnector) {
39
- return registeredConnector as ConnectorCreator;
40
- }
41
-
42
- return (
43
- getBuiltinConnectorCreatorByProvider(provider) ||
44
- getBuiltinConnectorCreatorByProvider(fallbackProvider) ||
45
- null
46
- );
37
+ return (registeredConnector as ConnectorCreator | null) ?? null;
47
38
  };