@dsh-ft/dsh-fft-paper-trading 0.7.1 → 0.7.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.
Files changed (130) hide show
  1. package/lib/client.js +1 -1
  2. package/package.json +1 -4
  3. package/node_modules/@ftshare-lab/dsh-kline/CHANGELOG.md +0 -611
  4. package/node_modules/@ftshare-lab/dsh-kline/LICENSE +0 -21
  5. package/node_modules/@ftshare-lab/dsh-kline/PROVENANCE.md +0 -13
  6. package/node_modules/@ftshare-lab/dsh-kline/README.en.md +0 -171
  7. package/node_modules/@ftshare-lab/dsh-kline/README.md +0 -171
  8. package/node_modules/@ftshare-lab/dsh-kline/chart_service.py +0 -687
  9. package/node_modules/@ftshare-lab/dsh-kline/config/basic-symbols.json +0 -570
  10. package/node_modules/@ftshare-lab/dsh-kline/config/dsh-kline.patch.yml +0 -4
  11. package/node_modules/@ftshare-lab/dsh-kline/config/dsh-tool-catalog.json +0 -3875
  12. package/node_modules/@ftshare-lab/dsh-kline/cordis.patch.yml +0 -33
  13. package/node_modules/@ftshare-lab/dsh-kline/core/__init__.py +0 -0
  14. package/node_modules/@ftshare-lab/dsh-kline/core/adjustment.py +0 -16
  15. package/node_modules/@ftshare-lab/dsh-kline/core/calc.py +0 -691
  16. package/node_modules/@ftshare-lab/dsh-kline/core/rows.py +0 -228
  17. package/node_modules/@ftshare-lab/dsh-kline/core/ta_engine.py +0 -99
  18. package/node_modules/@ftshare-lab/dsh-kline/lib/candle-sequence.js +0 -15
  19. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-adjustment.js +0 -7
  20. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-annotations.js +0 -33
  21. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-applications.js +0 -171
  22. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-context.js +0 -164
  23. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-observation.js +0 -251
  24. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-service-status.js +0 -82
  25. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-source-status.js +0 -39
  26. package/node_modules/@ftshare-lab/dsh-kline/lib/chart-sources.js +0 -354
  27. package/node_modules/@ftshare-lab/dsh-kline/lib/client.js +0 -17581
  28. package/node_modules/@ftshare-lab/dsh-kline/lib/drawing-feedback.js +0 -284
  29. package/node_modules/@ftshare-lab/dsh-kline/lib/fibonacci.js +0 -18
  30. package/node_modules/@ftshare-lab/dsh-kline/lib/ftshare-settings-bridge.js +0 -159
  31. package/node_modules/@ftshare-lab/dsh-kline/lib/index.js +0 -279
  32. package/node_modules/@ftshare-lab/dsh-kline/lib/labeled-polyline.js +0 -17
  33. package/node_modules/@ftshare-lab/dsh-kline/lib/pattern-groups.js +0 -91
  34. package/node_modules/@ftshare-lab/dsh-kline/lib/price-bands.js +0 -55
  35. package/node_modules/@ftshare-lab/dsh-kline/lib/price-series.js +0 -47
  36. package/node_modules/@ftshare-lab/dsh-kline/lib/price-sticks.js +0 -32
  37. package/node_modules/@ftshare-lab/dsh-kline/lib/types/candle-sequence.d.ts +0 -2
  38. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-adjustment.d.ts +0 -2
  39. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-annotations.d.ts +0 -4
  40. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-applications.d.ts +0 -26
  41. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-context.d.ts +0 -14
  42. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-observation.d.ts +0 -8
  43. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-service-status.d.ts +0 -22
  44. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-source-status.d.ts +0 -47
  45. package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-sources.d.ts +0 -25
  46. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/BetterSidebarTab.d.ts +0 -12
  47. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/ClassicShell.d.ts +0 -4
  48. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/KlineContent.d.ts +0 -37
  49. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/PanelHost.d.ts +0 -25
  50. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-apply.d.ts +0 -13
  51. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-context.d.ts +0 -23
  52. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-handoff.d.ts +0 -5
  53. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-session-resolver.d.ts +0 -2
  54. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/client-context.d.ts +0 -16
  55. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/conversation.d.ts +0 -43
  56. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/default-tab.d.ts +0 -3
  57. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/embed.d.ts +0 -37
  58. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/generated-view.d.ts +0 -2
  59. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/horizontal-lines.d.ts +0 -1
  60. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/host-options.d.ts +0 -38
  61. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/host-panels.d.ts +0 -55
  62. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/index.d.ts +0 -4
  63. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/mode-preferences.d.ts +0 -25
  64. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-contract.d.ts +0 -52
  65. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-register.d.ts +0 -46
  66. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-services.d.ts +0 -45
  67. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar.d.ts +0 -47
  68. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/sidebar-integration.d.ts +0 -12
  69. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/ui-onboarding.d.ts +0 -7
  70. package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/version.d.ts +0 -1
  71. package/node_modules/@ftshare-lab/dsh-kline/lib/types/drawing-feedback.d.ts +0 -5
  72. package/node_modules/@ftshare-lab/dsh-kline/lib/types/fibonacci.d.ts +0 -5
  73. package/node_modules/@ftshare-lab/dsh-kline/lib/types/ftshare-settings-bridge.d.ts +0 -50
  74. package/node_modules/@ftshare-lab/dsh-kline/lib/types/index.d.ts +0 -26
  75. package/node_modules/@ftshare-lab/dsh-kline/lib/types/labeled-polyline.d.ts +0 -11
  76. package/node_modules/@ftshare-lab/dsh-kline/lib/types/pattern-groups.d.ts +0 -2
  77. package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-bands.d.ts +0 -3
  78. package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-series.d.ts +0 -5
  79. package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-sticks.d.ts +0 -3
  80. package/node_modules/@ftshare-lab/dsh-kline/package.json +0 -157
  81. package/node_modules/@ftshare-lab/dsh-kline/requirements.txt +0 -6
  82. package/node_modules/@ftshare-lab/dsh-kline/scripts/bootstrap.sh +0 -5
  83. package/node_modules/@ftshare-lab/dsh-kline/scripts/dsh-bootstrap.mjs +0 -179
  84. package/node_modules/@ftshare-lab/dsh-kline/scripts/dsh-mcp-plugin.mjs +0 -27
  85. package/node_modules/@ftshare-lab/dsh-kline/scripts/run-dsh-kline.mjs +0 -658
  86. package/node_modules/@ftshare-lab/dsh-kline/scripts/run-dsh-kline.sh +0 -5
  87. package/node_modules/@ftshare-lab/dsh-kline/server.py +0 -1755
  88. package/node_modules/@ftshare-lab/dsh-kline/tools/__init__.py +0 -0
  89. package/node_modules/@ftshare-lab/dsh-kline/tools/annotations.py +0 -119
  90. package/node_modules/@ftshare-lab/dsh-kline/tools/automatic_analysis.py +0 -158
  91. package/node_modules/@ftshare-lab/dsh-kline/tools/baostock_source.py +0 -176
  92. package/node_modules/@ftshare-lab/dsh-kline/tools/calc.py +0 -39
  93. package/node_modules/@ftshare-lab/dsh-kline/tools/channel_candidates.py +0 -260
  94. package/node_modules/@ftshare-lab/dsh-kline/tools/channel_preview.py +0 -82
  95. package/node_modules/@ftshare-lab/dsh-kline/tools/channels.py +0 -104
  96. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_applications.py +0 -204
  97. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_context.py +0 -186
  98. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_edits.py +0 -363
  99. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_functions.py +0 -451
  100. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_indicators.py +0 -65
  101. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_measurements.py +0 -84
  102. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_source_status.py +0 -32
  103. package/node_modules/@ftshare-lab/dsh-kline/tools/chart_sources.py +0 -31
  104. package/node_modules/@ftshare-lab/dsh-kline/tools/closed_daily.py +0 -68
  105. package/node_modules/@ftshare-lab/dsh-kline/tools/draw.py +0 -410
  106. package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_feedback.py +0 -45
  107. package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_interaction.py +0 -117
  108. package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_verification.py +0 -141
  109. package/node_modules/@ftshare-lab/dsh-kline/tools/fetch.py +0 -4680
  110. package/node_modules/@ftshare-lab/dsh-kline/tools/fibonacci.py +0 -83
  111. package/node_modules/@ftshare-lab/dsh-kline/tools/foreign_daily.py +0 -185
  112. package/node_modules/@ftshare-lab/dsh-kline/tools/free_sources.py +0 -483
  113. package/node_modules/@ftshare-lab/dsh-kline/tools/lines.py +0 -91
  114. package/node_modules/@ftshare-lab/dsh-kline/tools/nine_count.py +0 -66
  115. package/node_modules/@ftshare-lab/dsh-kline/tools/pattern_groups.py +0 -103
  116. package/node_modules/@ftshare-lab/dsh-kline/tools/pivots.py +0 -60
  117. package/node_modules/@ftshare-lab/dsh-kline/tools/polylines.py +0 -131
  118. package/node_modules/@ftshare-lab/dsh-kline/tools/price_bands.py +0 -165
  119. package/node_modules/@ftshare-lab/dsh-kline/tools/price_patterns.py +0 -311
  120. package/node_modules/@ftshare-lab/dsh-kline/tools/price_series.py +0 -162
  121. package/node_modules/@ftshare-lab/dsh-kline/tools/price_sticks.py +0 -114
  122. package/node_modules/@ftshare-lab/dsh-kline/tools/range_candidates.py +0 -170
  123. package/node_modules/@ftshare-lab/dsh-kline/tools/recent_drawing_candidates.py +0 -123
  124. package/node_modules/@ftshare-lab/dsh-kline/tools/rectangles.py +0 -76
  125. package/node_modules/@ftshare-lab/dsh-kline/tools/regression_channels.py +0 -87
  126. package/node_modules/@ftshare-lab/dsh-kline/tools/ta_functions.py +0 -228
  127. package/node_modules/@ftshare-lab/dsh-kline/tools/trend_lines.py +0 -106
  128. package/node_modules/@ftshare-lab/dsh-kline/tools/watchlist.py +0 -149
  129. package/node_modules/@ftshare-lab/dsh-kline/view/ft-logo.jpg +0 -0
  130. package/node_modules/@ftshare-lab/dsh-kline/view/vendor/klinecharts.min.js +0 -7
@@ -1,279 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { homedir } from 'node:os';
3
- import { join, resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { ChartServiceUnavailable, readServiceLocator, probeChartService, unavailableService } from "./chart-service-status.js";
6
- import { ChartContextBroker } from "./chart-context.js";
7
- import { ChartApplications } from "./chart-applications.js";
8
- import { startFtshareSettingsBridge } from "./ftshare-settings-bridge.js";
9
- export const name = 'dsh-kline-sidebar';
10
- export const inject = ['webServer'];
11
- const RUNTIME_DIR = runtimeDirectory();
12
- const RUNTIME_FILE = join(RUNTIME_DIR, 'services', `${process.pid}.json`);
13
- const STATE_DIR = stateDirectory();
14
- const SESSION_DIR = join(RUNTIME_DIR, 'sessions');
15
- const VENDOR_FILE = fileURLToPath(new URL('../view/vendor/klinecharts.min.js', import.meta.url));
16
- const LOGO_FILE = fileURLToPath(new URL('../view/ft-logo.jpg', import.meta.url));
17
- const MAX_PROXY_BYTES = 8 * 1024 * 1024;
18
- const CHART_ACTIONS = new Set([
19
- 'analyze_kline',
20
- 'analyze_key_levels',
21
- 'calc_range',
22
- 'calculate_chart_indicators',
23
- 'fetch_candles',
24
- 'fetch_comparison_candles',
25
- 'fetch_security_workspace',
26
- 'fetch_market_pulse',
27
- 'fetch_market_board_detail',
28
- 'fetch_security_intelligence',
29
- 'watchlist_get',
30
- 'watchlist_save',
31
- 'market_ticker',
32
- 'search_symbols',
33
- 'symbol_directory',
34
- 'data_source_status',
35
- 'configure_ftshare',
36
- 'test_ftshare_connection',
37
- 'workbench_run_ta',
38
- 'workbench_run_chart_function',
39
- 'workbench_prepare_edit',
40
- 'workbench_apply_edit',
41
- 'workbench_edit_status',
42
- ]);
43
- export function apply(ctx) {
44
- const contexts = new ChartContextBroker(join(RUNTIME_DIR, 'views', String(process.pid)), () => Date.now(), RUNTIME_DIR);
45
- ctx.effect(() => ctx.webServer.register({
46
- kind: 'prefix',
47
- path: '/dsh-kline',
48
- handler: (request, response) => serveRuntimeSession(request, response, contexts),
49
- }), 'dsh-kline: chart session route');
50
- ctx.inject?.(['systemPrompt'], scoped => {
51
- if (typeof scoped.systemPrompt?.context !== 'function')
52
- return;
53
- scoped.effect(() => scoped.systemPrompt.context({ name: 'dsh-kline:current-view', order: 350,
54
- text: context => contexts.prompt(context) }), 'dsh-kline: current chart context');
55
- });
56
- ctx.inject?.(['ftshareSettings'], scoped => {
57
- if (!scoped.ftshareSettings?.apiKey)
58
- return;
59
- const bridge = startFtshareSettingsBridge({ settings: scoped.ftshareSettings, runtimeDirectory: RUNTIME_DIR });
60
- scoped.effect(() => () => { void bridge.dispose(); }, 'dsh-kline: FTShare settings credential bridge');
61
- });
62
- }
63
- async function serveRuntimeSession(request, response, contexts) {
64
- const url = new URL(request.url ?? '/', 'http://localhost');
65
- const pathname = url.pathname;
66
- try {
67
- if (pathname === '/dsh-kline/healthz') {
68
- if (request.method !== 'GET' && request.method !== 'HEAD') {
69
- sendJson(response, 405, { ok: false, error: 'method_not_allowed' });
70
- return;
71
- }
72
- const version = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')).version;
73
- const diagnostics = { version, host_process_id: process.pid, locator_path: RUNTIME_FILE,
74
- log_path: join(STATE_DIR, 'logs', `backend-${process.pid}.log`) };
75
- try {
76
- const locator = await readServiceLocator(RUNTIME_FILE, process.pid);
77
- await probeChartService(locator);
78
- sendJson(response, 200, { ok: true, ...diagnostics, process_id: locator.process_id,
79
- service_url: locator.service_url }, request.method === 'HEAD');
80
- }
81
- catch (error) {
82
- let reason = error instanceof ChartServiceUnavailable ? error.reason : 'service_locator_invalid';
83
- if (reason === 'service_locator_missing') {
84
- try {
85
- const status = JSON.parse(await readFile(join(STATE_DIR, 'logs', `backend-${process.pid}.json`), 'utf8'));
86
- if (status.host_process_id === process.pid && Number.isSafeInteger(status.launcher_process_id)) {
87
- process.kill(status.launcher_process_id, 0);
88
- if (status.phase === 'preparing')
89
- reason = 'runtime_preparing';
90
- else if (status.phase === 'recovering')
91
- reason = 'runtime_recovering';
92
- }
93
- }
94
- catch { /* A missing or stale diagnostic cannot prove readiness. */ }
95
- }
96
- sendJson(response, 503, { ...unavailableService(reason), ...diagnostics }, request.method === 'HEAD');
97
- }
98
- return;
99
- }
100
- if (pathname === '/dsh-kline/recovery' && request.method === 'GET') {
101
- try {
102
- const recovery = await new ChartApplications(RUNTIME_DIR).recover(url.searchParams.get('conversation') ?? '');
103
- sendJson(response, 200, recovery);
104
- }
105
- catch {
106
- sendJson(response, 200, { ok: false, error: 'confirmed_chart_recovery_unavailable' });
107
- }
108
- return;
109
- }
110
- if (pathname === '/dsh-kline/context') {
111
- if (request.method !== 'POST') {
112
- sendJson(response, 405, { ok: false, error: 'method_not_allowed' });
113
- return;
114
- }
115
- if (request.headers['content-type']?.split(';')[0] !== 'application/json'
116
- || request.headers.origin && new URL(request.headers.origin).host !== request.headers.host) {
117
- sendJson(response, 403, { ok: false, error: 'invalid_context_origin' });
118
- return;
119
- }
120
- try {
121
- const result = await contexts.publish(JSON.parse((await readRequestBody(request)).toString('utf8')));
122
- sendJson(response, 200, result);
123
- }
124
- catch (error) {
125
- if (error instanceof Error && error.message === 'context_state_required') {
126
- sendJson(response, 409, { ok: false, error: 'context_state_required' });
127
- }
128
- else {
129
- sendJson(response, 400, { ok: false, error: 'context_publication_rejected' });
130
- }
131
- }
132
- return;
133
- }
134
- // Static browser assets must remain available before the first chart session exists.
135
- if (pathname === '/dsh-kline/vendor/klinecharts.min.js' && (request.method === 'GET' || request.method === 'HEAD')) {
136
- const body = await readFile(VENDOR_FILE);
137
- sendBytes(response, 200, body, 'text/javascript; charset=utf-8', request.method === 'HEAD');
138
- return;
139
- }
140
- if (pathname === '/dsh-kline/logo.jpg' && (request.method === 'GET' || request.method === 'HEAD')) {
141
- const body = await readFile(LOGO_FILE);
142
- sendBytes(response, 200, body, 'image/jpeg', request.method === 'HEAD');
143
- return;
144
- }
145
- // Never infer a chart from the global latest publication. The browser
146
- // obtains this opaque reference from the owning conversation's result.
147
- if (pathname === '/dsh-kline/session' || pathname === '/dsh-kline/data') {
148
- if (request.method !== 'GET' && request.method !== 'HEAD') {
149
- sendJson(response, 405, { ok: false, error: 'method_not_allowed' });
150
- return;
151
- }
152
- const token = url.searchParams.get('session') ?? '';
153
- if (!/^[A-Za-z0-9_-]{32}$/.test(token)) {
154
- sendJson(response, 200, { ok: false, error: 'chart_session_required' });
155
- return;
156
- }
157
- const saved = JSON.parse(await readFile(join(SESSION_DIR, `${token}.json`), 'utf8'));
158
- if (saved.session !== token || saved.ok !== true)
159
- throw new Error('invalid_chart_snapshot');
160
- if (pathname === '/dsh-kline/data') {
161
- sendJson(response, 200, { ok: true, session: token, payload: saved.payload }, request.method === 'HEAD');
162
- }
163
- else {
164
- sendJson(response, 200, { ok: true, session: token, symbol: saved.symbol, name: saved.name, published_at: saved.published_at }, request.method === 'HEAD');
165
- }
166
- return;
167
- }
168
- // Unknown paths have a stable routing result, independent of backend state.
169
- if (!pathname.startsWith('/dsh-kline/api/tools/')) {
170
- sendJson(response, 404, { ok: false, error: 'not_found' }, request.method === 'HEAD');
171
- return;
172
- }
173
- const session = await readLiveSession();
174
- if (pathname.startsWith('/dsh-kline/api/tools/') && request.method === 'POST') {
175
- const action = pathname.slice('/dsh-kline/api/tools/'.length).replaceAll('/', '');
176
- if (!CHART_ACTIONS.has(action)) {
177
- sendJson(response, 404, { ok: false, error: 'unsupported_chart_action' });
178
- return;
179
- }
180
- if (action.startsWith('workbench_') && (request.headers['content-type']?.split(';')[0] !== 'application/json'
181
- || request.headers.origin && new URL(request.headers.origin).host !== request.headers.host
182
- || request.headers['sec-fetch-site'] && !['same-origin', 'none'].includes(String(request.headers['sec-fetch-site'])))) {
183
- sendJson(response, 403, { ok: false, error: 'invalid_workbench_origin' });
184
- return;
185
- }
186
- const body = await readRequestBody(request);
187
- await proxyJson(response, `${serviceOrigin(session)}/api/tools/${encodeURIComponent(action)}`, {
188
- method: 'POST',
189
- headers: { ...chartServiceHeaders(session), 'Content-Type': 'application/json' },
190
- body: body.toString('utf8'),
191
- });
192
- return;
193
- }
194
- if (pathname.startsWith('/dsh-kline/api/tools/')) {
195
- response.writeHead(405, { Allow: 'POST' });
196
- response.end();
197
- return;
198
- }
199
- sendJson(response, 404, { ok: false, error: 'not_found' });
200
- }
201
- catch (error) {
202
- if (error instanceof ChartServiceUnavailable) {
203
- sendJson(response, 200, unavailableService(error.reason), request.method === 'HEAD');
204
- return;
205
- }
206
- const code = error instanceof Error && 'code' in error ? String(error.code) : '';
207
- sendJson(response, code === 'ENOENT' ? 200 : 500, code === 'ENOENT'
208
- ? (pathname === '/dsh-kline/data' || pathname === '/dsh-kline/session'
209
- ? { ok: false, error: 'chart_session_unavailable', message: '这张图表的快照已不可用,请在当前对话重新分析该标的。' }
210
- : unavailableService())
211
- : { ok: false, error: 'chart_session_manifest_failed' }, request.method === 'HEAD');
212
- }
213
- }
214
- export function runtimeDirectory(env = process.env) {
215
- const explicit = String(env.DSH_KLINE_RUNTIME_DIR || '').trim();
216
- if (explicit)
217
- return resolve(explicit);
218
- return join(stateDirectory(env), 'runtime');
219
- }
220
- function stateDirectory(env = process.env) {
221
- const explicit = String(env.DSH_KLINE_CACHE_DIR || '').trim();
222
- if (explicit)
223
- return resolve(explicit);
224
- if (process.platform === 'win32') {
225
- const local = String(env.LOCALAPPDATA || env.APPDATA || '').trim();
226
- return join(local || join(homedir(), 'AppData', 'Local'), 'dsh_kline');
227
- }
228
- const cache = String(env.XDG_CACHE_HOME || '').trim();
229
- return join(cache || join(homedir(), '.cache'), 'dsh_kline');
230
- }
231
- function chartServiceHeaders(session) {
232
- return { 'X-DSH-Kline-Token': session.service_token };
233
- }
234
- async function readLiveSession() {
235
- return readServiceLocator(RUNTIME_FILE, process.pid);
236
- }
237
- function serviceOrigin(session) {
238
- return new URL(session.service_url).origin;
239
- }
240
- async function proxyJson(response, url, init) {
241
- let upstream;
242
- try {
243
- upstream = await fetch(url, { ...init, signal: AbortSignal.timeout(120000) });
244
- }
245
- catch (error) {
246
- throw new ChartServiceUnavailable(error instanceof Error && error.name === 'TimeoutError' ? 'backend_timeout' : 'backend_unreachable');
247
- }
248
- const body = Buffer.from(await upstream.arrayBuffer());
249
- if (body.length > MAX_PROXY_BYTES) {
250
- sendJson(response, 502, { ok: false, error: 'chart_response_too_large' });
251
- return;
252
- }
253
- sendBytes(response, upstream.status, body, 'application/json; charset=utf-8');
254
- }
255
- async function readRequestBody(request) {
256
- const chunks = [];
257
- let size = 0;
258
- for await (const chunk of request) {
259
- const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
260
- size += buffer.length;
261
- if (size > MAX_PROXY_BYTES)
262
- throw new Error('request_too_large');
263
- chunks.push(buffer);
264
- }
265
- return Buffer.concat(chunks);
266
- }
267
- function sendJson(response, status, value, head = false) {
268
- const body = Buffer.from(JSON.stringify(value));
269
- sendBytes(response, status, body, 'application/json; charset=utf-8', head);
270
- }
271
- function sendBytes(response, status, body, contentType, head = false) {
272
- response.writeHead(status, {
273
- 'Content-Type': contentType,
274
- 'Content-Length': String(body.length),
275
- 'Cache-Control': 'no-store',
276
- 'X-Content-Type-Options': 'nosniff',
277
- });
278
- response.end(head ? undefined : body);
279
- }
@@ -1,17 +0,0 @@
1
- export function sanitizePolylinePoints(raw) {
2
- if (!Array.isArray(raw) || raw.length < 2 || raw.length > 8)
3
- throw Error('invalid_polyline_points');
4
- const seen = new Set();
5
- return raw.map((p, i) => {
6
- if (typeof p?.label !== 'string' || !p.label.length || [...p.label].length > 16 || p.label !== p.label.trim()
7
- || /[\x00-\x1f]/.test(p.label) || seen.has(p.label) || !Number.isSafeInteger(p.time) || p.time <= 0
8
- || typeof p.price !== 'number' || !Number.isFinite(p.price) || p.price <= 0
9
- || i > 0 && p.time <= raw[i - 1].time)
10
- throw Error('invalid_polyline_points');
11
- seen.add(p.label);
12
- return { label: p.label, time: p.time, price: p.price };
13
- });
14
- }
15
- export function polylineOverlayPoints(command) {
16
- return sanitizePolylinePoints(command.points).map(p => ({ timestamp: p.time * 1000, value: p.price }));
17
- }
@@ -1,91 +0,0 @@
1
- /** Bounded, atomic snapshots produced by the shared Python analyses. */
2
- const HEX = /^[a-f0-9]{64}$/;
3
- const COLORS = new Set(['info', 'warning', 'success', 'danger']);
4
- const TYPES = new Set(['double_top', 'double_bottom', 'head_shoulders_top', 'head_shoulders_bottom', 'platform']);
5
- const STATUSES = new Set(['candidate', 'pending_confirmation', 'price_confirmed', 'structurally_invalid', 'breakout_failed', 'expired']);
6
- function time(value) {
7
- if (!Number.isSafeInteger(value) || value <= 0)
8
- throw Error('invalid_pattern_time');
9
- return value;
10
- }
11
- function price(value) {
12
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
13
- throw Error('invalid_pattern_price');
14
- return value;
15
- }
16
- function nonnegative(value) {
17
- if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
18
- throw Error('invalid_pattern_ratio');
19
- return value;
20
- }
21
- function label(value, limit) {
22
- if (typeof value !== 'string' || value.length > limit || /[\x00-\x1f]/.test(value))
23
- throw Error('invalid_pattern_label');
24
- return value;
25
- }
26
- export function patternGroupObservation(raw) {
27
- return { geometry_hash: raw.geometry_hash, bar_count: raw.bar_count, rule_version: raw.rule_version, as_of: raw.as_of };
28
- }
29
- export function sanitizePatternGroupCommand(raw, interval) {
30
- const pattern = raw?.type === 'DRAW_AGENT_PRICE_PATTERN';
31
- const nine = raw?.type === 'DRAW_AGENT_NINE_COUNT';
32
- if (!pattern && !nine || raw.interval !== interval || !COLORS.has(raw.color)
33
- || typeof raw.id !== 'string' || !new RegExp(`^${pattern ? 'pattern' : 'nine'}_[a-f0-9]{24}$`).test(raw.id)
34
- || !HEX.test(raw.geometry_hash) || raw.rule_version !== (pattern ? 'price_patterns_v1' : 'nine_count_v1')
35
- || !Number.isSafeInteger(raw.bar_count) || raw.bar_count < 0 || raw.bar_count > (pattern ? 5 : 240))
36
- throw Error('invalid_pattern_group');
37
- const result = { type: raw.type, id: raw.id, interval, label: label(raw.label ?? '', 48), color: raw.color,
38
- geometry_hash: raw.geometry_hash, bar_count: raw.bar_count, rule_version: raw.rule_version, as_of: time(raw.as_of) };
39
- if (raw.create_request_id !== undefined)
40
- result.create_request_id = label(raw.create_request_id, 160);
41
- if (pattern) {
42
- const p = raw.pattern;
43
- if (!p || !TYPES.has(p.type) || !STATUSES.has(p.status)
44
- || !Array.isArray(p.anchors) || p.anchors.length !== (p.type === 'platform' ? 0 : p.type.startsWith('double') ? 3 : 5)
45
- || raw.bar_count !== p.anchors.length || !Array.isArray(p.events) || p.events.length > 128
46
- || !['up', 'down', null].includes(p.direction) || !['up', 'down', null].includes(p.break_direction))
47
- throw Error('invalid_pattern_geometry');
48
- const anchors = p.anchors.map((a) => ({ index: a.index, side: a.side, time: time(a.time), price: price(a.price) }));
49
- if (anchors.some((a, i) => !Number.isSafeInteger(a.index) || a.index < 0 || !['high', 'low'].includes(a.side)
50
- || i > 0 && (a.index <= anchors[i - 1].index || a.time <= anchors[i - 1].time)))
51
- throw Error('invalid_pattern_anchors');
52
- const events = p.events.map((e) => ({ type: label(e.type, 40), time: time(e.time), index: e.index }));
53
- if (events.some((e) => !Number.isSafeInteger(e.index) || e.index < 0))
54
- throw Error('invalid_pattern_events');
55
- const geometry = { type: p.type, anchors, status: p.status, direction: p.direction, break_direction: p.break_direction,
56
- atr: price(p.atr), buffer: price(p.buffer), available_at: time(p.available_at), as_of: time(p.as_of),
57
- confirmed_at: p.confirmed_at == null ? null : time(p.confirmed_at), invalidated_at: p.invalidated_at == null ? null : time(p.invalidated_at),
58
- outer: p.outer == null ? undefined : price(p.outer), events,
59
- volume_evidence: p.volume_evidence?.status === 'known' ? { status: 'known', relative_to_preceding_20: nonnegative(p.volume_evidence.relative_to_preceding_20), unit: label(p.volume_evidence.unit, 16) } :
60
- { status: 'unknown', reason: label(p.volume_evidence?.reason ?? 'unavailable', 80) } };
61
- if (p.type === 'platform') {
62
- geometry.box = { start_time: time(p.box?.start_time), end_time: time(p.box?.end_time),
63
- lower_price: price(p.box?.lower_price), upper_price: price(p.box?.upper_price) };
64
- if (geometry.box.start_time >= geometry.box.end_time || geometry.box.lower_price >= geometry.box.upper_price)
65
- throw Error('invalid_pattern_box');
66
- }
67
- else if (p.neckline?.type === 'horizontal')
68
- geometry.neckline = { type: 'horizontal', price: price(p.neckline.price) };
69
- else if (p.neckline?.type === 'sloped')
70
- geometry.neckline = { type: 'sloped', from: { index: p.neckline.from?.index, time: time(p.neckline.from?.time), price: price(p.neckline.from?.price) },
71
- to: { index: p.neckline.to?.index, time: time(p.neckline.to?.time), price: price(p.neckline.to?.price) } };
72
- else
73
- throw Error('invalid_pattern_neckline');
74
- result.pattern = geometry;
75
- }
76
- else {
77
- if (!Array.isArray(raw.marks) || raw.marks.length > 240 || raw.bar_count !== raw.marks.length
78
- || !Array.isArray(raw.events) || raw.events.length > 30)
79
- throw Error('invalid_nine_group');
80
- result.marks = raw.marks.map((m) => ({ time: time(m.time), index: m.index, direction: m.direction, count: m.count,
81
- label: label(m.label, 2), price: price(m.price) }));
82
- if (result.marks.some((m, i) => !Number.isSafeInteger(m.index) || m.index < 0 || !['up', 'down'].includes(m.direction)
83
- || !Number.isSafeInteger(m.count) || m.count < 1 || m.count > 9 || m.label !== String(m.count)
84
- || i > 0 && m.time <= result.marks[i - 1].time))
85
- throw Error('invalid_nine_marks');
86
- result.events = raw.events.map((e) => ({ time: time(e.time), direction: e.direction, label: label(e.label, 20) }));
87
- if (result.events.some((e) => !['up', 'down'].includes(e.direction)))
88
- throw Error('invalid_nine_events');
89
- }
90
- return result;
91
- }
@@ -1,55 +0,0 @@
1
- import { sanitizePriceSource, sanitizePriceCondition } from "./price-series.js";
2
- const COLORS = new Set(['info', 'warning', 'success', 'danger']);
3
- const INTERVALS = new Set(['minute', 'day', 'week', 'month', 'quarter', 'year']);
4
- function bandSource(raw, output) {
5
- if (raw?.kind !== 'bbands')
6
- return sanitizePriceSource(raw);
7
- if (!raw || typeof raw !== 'object' || Array.isArray(raw) || Object.keys(raw).length !== 6
8
- || raw.output !== output || !Number.isSafeInteger(raw.period) || raw.period < 2 || raw.period > 200
9
- || typeof raw.deviation_up !== 'number' || !Number.isFinite(raw.deviation_up)
10
- || raw.deviation_up <= 0 || raw.deviation_up > 5
11
- || typeof raw.deviation_down !== 'number' || !Number.isFinite(raw.deviation_down)
12
- || raw.deviation_down <= 0 || raw.deviation_down > 5 || raw.matype !== 0)
13
- throw Error('invalid_source_band');
14
- return { kind: 'bbands', output, period: raw.period, deviation_up: raw.deviation_up,
15
- deviation_down: raw.deviation_down, matype: 0 };
16
- }
17
- /** One bounded object; null pairs are explicit gaps and crossed bounds are refused. */
18
- export function sanitizePriceBandCommand(raw, expectedBars, interval) {
19
- if (raw?.type !== 'DRAW_AGENT_PRICE_BAND' || typeof raw.id !== 'string' || !/^band_[a-f0-9]{24}$/.test(raw.id)
20
- || !INTERVALS.has(raw.interval) || !COLORS.has(raw.color) || typeof raw.label !== 'string' || raw.label.length > 48
21
- || !/^[a-f0-9]{64}$/.test(raw.band_hash) || raw.row_hash != null && !/^[a-f0-9]{16}$/.test(raw.row_hash)
22
- || !Number.isSafeInteger(raw.bar_count)
23
- || raw.bar_count < 1 || raw.bar_count > 4000 || raw.interval === interval && raw.bar_count !== expectedBars
24
- || !Array.isArray(raw.upper_values) || !Array.isArray(raw.lower_values)
25
- || raw.upper_values.length !== raw.bar_count || raw.lower_values.length !== raw.bar_count)
26
- throw Error('invalid_source_band');
27
- const upperSource = bandSource(raw.upper_source, 'upperband');
28
- const lowerSource = bandSource(raw.lower_source, 'lowerband');
29
- const boll = upperSource.kind === 'bbands';
30
- if (boll !== (lowerSource.kind === 'bbands') || boll && (raw.condition != null || JSON.stringify({ ...upperSource, output: null }) !== JSON.stringify({ ...lowerSource, output: null })
31
- || !Array.isArray(raw.middle_values) || raw.middle_values.length !== raw.bar_count)
32
- || !boll && raw.middle_values !== undefined)
33
- throw Error('invalid_source_band');
34
- let present = 0;
35
- for (let i = 0; i < raw.bar_count; i++) {
36
- const upper = raw.upper_values[i], lower = raw.lower_values[i];
37
- const middle = boll ? raw.middle_values[i] : null;
38
- if (upper === null && lower === null && middle === null)
39
- continue;
40
- if (typeof upper !== 'number' || typeof lower !== 'number' || !Number.isFinite(upper) || !Number.isFinite(lower)
41
- || lower <= 0 || upper <= lower || boll && (typeof middle !== 'number' || !Number.isFinite(middle)
42
- || !(lower < middle && middle < upper)))
43
- throw Error('invalid_source_band');
44
- present++;
45
- }
46
- if (!present)
47
- throw Error('invalid_source_band');
48
- return { type: 'DRAW_AGENT_PRICE_BAND', id: raw.id, interval: raw.interval, label: raw.label, color: raw.color,
49
- bar_count: raw.bar_count, upper_source: upperSource,
50
- lower_source: lowerSource, condition: sanitizePriceCondition(raw.condition),
51
- upper_values: [...raw.upper_values], lower_values: [...raw.lower_values], band_hash: raw.band_hash,
52
- ...(boll ? { middle_values: [...raw.middle_values] } : {}),
53
- ...(raw.row_hash ? { row_hash: raw.row_hash } : {}) };
54
- }
55
- export function bandObservation(raw) { return { band_hash: raw.band_hash, bar_count: raw.bar_count }; }
@@ -1,47 +0,0 @@
1
- /** Bounded, candle-index-aligned AI price line. No formula source or arbitrary arrays from the host. */
2
- const COLORS = new Set(['info', 'warning', 'success', 'danger']);
3
- const FIELDS = new Set(['open', 'high', 'low', 'close']);
4
- const OPS = new Set(['gt', 'gte', 'lt', 'lte']);
5
- function source(raw) {
6
- if (!raw || typeof raw !== 'object' || Array.isArray(raw))
7
- throw Error('invalid_series_source');
8
- const keys = Object.keys(raw);
9
- if (FIELDS.has(raw.kind) && keys.length === 1)
10
- return { kind: raw.kind };
11
- if ((raw.kind === 'sma' || raw.kind === 'ema') && keys.length === 2 && Number.isSafeInteger(raw.period) && raw.period >= 2 && raw.period <= 200)
12
- return { kind: raw.kind, period: raw.period };
13
- throw Error('invalid_series_source');
14
- }
15
- function condition(raw) {
16
- if (raw == null)
17
- return null;
18
- if (!raw || typeof raw !== 'object' || Array.isArray(raw) || Object.keys(raw).length !== 3 || !OPS.has(raw.op))
19
- throw Error('invalid_series_condition');
20
- const left = source(raw.left), right = raw.right;
21
- if (!right || typeof right !== 'object' || Array.isArray(right) || Object.keys(right).length !== 1)
22
- throw Error('invalid_series_condition');
23
- if (right.source !== undefined)
24
- return { left, op: raw.op, right: { source: source(right.source) } };
25
- if (typeof right.constant === 'number' && Number.isFinite(right.constant) && right.constant > 0)
26
- return { left, op: raw.op, right: { constant: right.constant } };
27
- throw Error('invalid_series_condition');
28
- }
29
- export { source as sanitizePriceSource, condition as sanitizePriceCondition };
30
- export function sanitizePriceSeriesCommand(raw, expectedBars, interval) {
31
- if (raw?.type !== 'DRAW_AGENT_SERIES_LINE' || typeof raw.id !== 'string' || !/^series_[a-f0-9]{24}$/.test(raw.id)
32
- || !['minute', 'day', 'week', 'month', 'quarter', 'year'].includes(raw.interval)
33
- || !COLORS.has(raw.color) || typeof raw.label !== 'string' || raw.label.length > 48
34
- || !/^[a-f0-9]{64}$/.test(raw.series_hash) || raw.row_hash != null && !/^[a-f0-9]{16}$/.test(raw.row_hash)
35
- || !Number.isSafeInteger(raw.bar_count)
36
- || raw.bar_count < 1 || raw.bar_count > 4000 || raw.interval === interval && raw.bar_count !== expectedBars
37
- || !Array.isArray(raw.values) || raw.values.length !== raw.bar_count
38
- || raw.values.some((value) => value !== null && (typeof value !== 'number' || !Number.isFinite(value) || value <= 0))
39
- || !raw.values.some((value) => value !== null))
40
- throw Error('invalid_source_series');
41
- return { type: 'DRAW_AGENT_SERIES_LINE', id: raw.id, interval: raw.interval, label: raw.label, color: raw.color,
42
- bar_count: raw.bar_count, source: source(raw.source), condition: condition(raw.condition),
43
- values: [...raw.values], series_hash: raw.series_hash, ...(raw.row_hash ? { row_hash: raw.row_hash } : {}) };
44
- }
45
- export function seriesObservation(raw) {
46
- return { series_hash: raw.series_hash, bar_count: raw.bar_count };
47
- }
@@ -1,32 +0,0 @@
1
- import { sanitizePriceSource, sanitizePriceCondition } from "./price-series.js";
2
- const COLORS = new Set(['info', 'warning', 'success', 'danger']);
3
- const INTERVALS = new Set(['minute', 'day', 'week', 'month', 'quarter', 'year']);
4
- /** A bounded sequence of independent vertical price sticks. */
5
- export function sanitizePriceSticksCommand(raw, expectedBars, interval) {
6
- if (raw?.type !== 'DRAW_AGENT_PRICE_STICKS' || typeof raw.id !== 'string' || !/^sticks_[a-f0-9]{24}$/.test(raw.id)
7
- || !INTERVALS.has(raw.interval) || !COLORS.has(raw.color) || typeof raw.label !== 'string' || raw.label.length > 48
8
- || !/^[a-f0-9]{64}$/.test(raw.sticks_hash) || raw.row_hash != null && !/^[a-f0-9]{16}$/.test(raw.row_hash)
9
- || !Number.isSafeInteger(raw.bar_count) || raw.bar_count < 1 || raw.bar_count > 4000
10
- || raw.interval === interval && raw.bar_count !== expectedBars
11
- || !Array.isArray(raw.start_values) || !Array.isArray(raw.end_values)
12
- || raw.start_values.length !== raw.bar_count || raw.end_values.length !== raw.bar_count)
13
- throw Error('invalid_source_sticks');
14
- let present = 0;
15
- for (let i = 0; i < raw.bar_count; i++) {
16
- const start = raw.start_values[i], end = raw.end_values[i];
17
- if (start === null && end === null)
18
- continue;
19
- if (typeof start !== 'number' || typeof end !== 'number' || !Number.isFinite(start) || !Number.isFinite(end)
20
- || start <= 0 || end <= 0 || start === end)
21
- throw Error('invalid_source_sticks');
22
- present++;
23
- }
24
- if (!present)
25
- throw Error('invalid_source_sticks');
26
- return { type: 'DRAW_AGENT_PRICE_STICKS', id: raw.id, interval: raw.interval, label: raw.label, color: raw.color,
27
- bar_count: raw.bar_count, start_source: sanitizePriceSource(raw.start_source),
28
- end_source: sanitizePriceSource(raw.end_source), condition: sanitizePriceCondition(raw.condition),
29
- start_values: [...raw.start_values], end_values: [...raw.end_values], sticks_hash: raw.sticks_hash,
30
- ...(raw.row_hash ? { row_hash: raw.row_hash } : {}) };
31
- }
32
- export function sticksObservation(raw) { return { sticks_hash: raw.sticks_hash, bar_count: raw.bar_count }; }
@@ -1,2 +0,0 @@
1
- /** Non-authorizing row identity for candle-index-aligned drawings. */
2
- export declare function candleSequenceHash(rows: any[]): string;
@@ -1,2 +0,0 @@
1
- /** Metadata aliases only; never transform prices or guess missing adjustment. */
2
- export declare function normalizeAdjustment(value: unknown): string | null;
@@ -1,4 +0,0 @@
1
- /** Canonical AI-owned text, numeric and icon annotations anchored to exact chart bars. */
2
- export declare const CHART_ANNOTATION_ICONS: readonly ["arrow_up", "arrow_down", "diamond"];
3
- export declare function sanitizeChartAnnotation(raw: any): any;
4
- export declare function chartAnnotationText(command: any): string;
@@ -1,26 +0,0 @@
1
- export interface ApplicationView {
2
- ref: string;
3
- conversation: string;
4
- view: string;
5
- revision: number;
6
- active: boolean;
7
- ambiguous: boolean;
8
- applyCapable?: boolean;
9
- state: any;
10
- }
11
- export declare class ChartApplications {
12
- private runtime;
13
- private now;
14
- constructor(runtime: string, now?: () => number);
15
- private directory;
16
- private path;
17
- private read;
18
- private write;
19
- private recoveryPath;
20
- recover(conversation: string): Promise<any>;
21
- private validate;
22
- private candidate;
23
- private publicReceipt;
24
- acknowledge(view: ApplicationView, receipt: any): Promise<any>;
25
- dispatch(view: ApplicationView): Promise<any>;
26
- }
@@ -1,14 +0,0 @@
1
- export { sanitizeChartContext } from './chart-observation.ts';
2
- export declare const CONTEXT_TTL_MS = 90000;
3
- export declare class ChartContextBroker {
4
- private records;
5
- private queue;
6
- private directory;
7
- private now;
8
- private applications?;
9
- private sources?;
10
- constructor(directory: string, now?: () => number, runtime?: string);
11
- publish(raw: any): Promise<any>;
12
- private accept;
13
- prompt(context: any): string;
14
- }
@@ -1,8 +0,0 @@
1
- export declare function text(value: unknown, max?: number): string;
2
- /** Describes browser input -> display only, never vendor-native history or edit authority. */
3
- export declare function sanitizeDataProvenance(raw: any): any;
4
- export declare function sanitizeChartContext(raw: any): any;
5
- export declare function observationKey(raw: any): string;
6
- /** Identity required for editing the current source, excluding transient UI state. */
7
- export declare function drawingSourceKey(raw: any): string;
8
- export declare function drawingInventory(payload: any): any[];
@@ -1,22 +0,0 @@
1
- export declare class ChartServiceUnavailable extends Error {
2
- readonly reason: string;
3
- constructor(reason: string);
4
- }
5
- export interface ServiceLocator extends Record<string, unknown> {
6
- ok: true;
7
- process_id: number;
8
- host_process_id: number;
9
- session: string;
10
- service_url: string;
11
- service_token: string;
12
- published_at: number;
13
- instance_id?: string;
14
- }
15
- export declare function readServiceLocator(path: string, hostPid: number): Promise<ServiceLocator>;
16
- export declare function probeChartService(locator: ServiceLocator, timeoutMs?: number): Promise<void>;
17
- export declare function unavailableService(reason?: string): {
18
- ok: boolean;
19
- error: string;
20
- reason: string;
21
- message: string;
22
- };