@ftshare-lab/dsh-kline 0.0.0-stage → 0.6.11
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/CHANGELOG.md +611 -0
- package/LICENSE +21 -0
- package/PROVENANCE.md +13 -0
- package/README.en.md +171 -0
- package/README.md +170 -2
- package/chart_service.py +687 -0
- package/config/basic-symbols.json +570 -0
- package/config/dsh-kline.patch.yml +4 -0
- package/config/dsh-tool-catalog.json +3875 -0
- package/cordis.patch.yml +33 -0
- package/core/__init__.py +0 -0
- package/core/adjustment.py +16 -0
- package/core/calc.py +691 -0
- package/core/rows.py +228 -0
- package/core/ta_engine.py +99 -0
- package/docs/anonymous-market-support.md +33 -0
- package/docs/automatic-drawing.md +24 -0
- package/docs/chart-functions.md +136 -0
- package/docs/drawing-examples.en.md +13 -0
- package/docs/drawing-examples.md +13 -0
- package/docs/embedding.md +77 -0
- package/docs/fixtures/price-pattern-real-v1.json +1 -0
- package/docs/free-foreign-daily.md +44 -0
- package/docs/guide.en.md +232 -0
- package/docs/guide.md +248 -0
- package/docs/images/abc-drawing-v0.5.0.jpg +0 -0
- package/docs/images/channel-drawing-v0.5.0.jpg +0 -0
- package/docs/images/drawing-workbench-v0.5.0.jpg +0 -0
- package/docs/images/dsh-kline-tab-workspace.png +0 -0
- package/docs/images/dsh-market.png +0 -0
- package/docs/images/kline-news.png +0 -0
- package/docs/images/kline-range-stats.png +0 -0
- package/docs/images/kline-support.png +0 -0
- package/docs/images/main-chart-comparison-v0.6.9.png +0 -0
- package/docs/images/market-overview-v0.6.9.png +0 -0
- package/docs/images/natural-language-abc-wolong-2026-10-27.png +0 -0
- package/docs/images/natural-language-descending-channel-wolong-2026-10-27.png +0 -0
- package/docs/images/platform-breakout-msft-v0.6.9.png +0 -0
- package/docs/npm-release.md +33 -0
- package/docs/price-pattern-rules-v1.md +40 -0
- package/docs/price-pattern-samples-v1.md +42 -0
- package/docs/provider-adaptation.md +73 -0
- package/docs/release-acceptance-v0.4.0.md +46 -0
- package/docs/release-acceptance-v0.4.1.md +43 -0
- package/docs/release-acceptance-v0.5.0.md +40 -0
- package/docs/release-acceptance-v0.6.0.md +33 -0
- package/docs/release-acceptance-v0.6.1.md +19 -0
- package/docs/release-acceptance-v0.6.10.md +21 -0
- package/docs/release-acceptance-v0.6.11.md +21 -0
- package/docs/release-acceptance-v0.6.2.md +31 -0
- package/docs/release-acceptance-v0.6.3.md +25 -0
- package/docs/release-acceptance-v0.6.4.md +24 -0
- package/docs/release-acceptance-v0.6.5.md +21 -0
- package/docs/release-acceptance-v0.6.6.md +21 -0
- package/docs/release-acceptance-v0.6.7.md +18 -0
- package/docs/release-acceptance-v0.6.8.md +18 -0
- package/docs/release-acceptance-v0.6.9.md +98 -0
- package/docs/release-notes-v0.5.0.md +23 -0
- package/docs/release-notes-v0.6.0.md +11 -0
- package/docs/release-notes-v0.6.1.md +20 -0
- package/docs/release-notes-v0.6.10.md +11 -0
- package/docs/release-notes-v0.6.11.md +16 -0
- package/docs/release-notes-v0.6.2.md +14 -0
- package/docs/release-notes-v0.6.3.md +26 -0
- package/docs/release-notes-v0.6.4.md +12 -0
- package/docs/release-notes-v0.6.5.md +13 -0
- package/docs/release-notes-v0.6.6.md +13 -0
- package/docs/release-notes-v0.6.7.md +17 -0
- package/docs/release-notes-v0.6.8.md +10 -0
- package/docs/release-notes-v0.6.9.md +16 -0
- package/lib/candle-sequence.js +15 -0
- package/lib/chart-adjustment.js +7 -0
- package/lib/chart-annotations.js +33 -0
- package/lib/chart-applications.js +171 -0
- package/lib/chart-context.js +164 -0
- package/lib/chart-observation.js +251 -0
- package/lib/chart-service-status.js +82 -0
- package/lib/chart-source-status.js +39 -0
- package/lib/chart-sources.js +354 -0
- package/lib/client/BetterSidebarTab.js +70 -0
- package/lib/client/ClassicShell.js +254 -0
- package/lib/client/KlineContent.js +155 -0
- package/lib/client/PanelHost.js +46 -0
- package/lib/client/chart-apply.js +73 -0
- package/lib/client/chart-context.js +233 -0
- package/lib/client/chart-handoff.js +34 -0
- package/lib/client/chart-session-resolver.js +74 -0
- package/lib/client/client-context.js +1 -0
- package/lib/client/conversation.js +88 -0
- package/lib/client/default-tab.js +83 -0
- package/lib/client/embed.js +50 -0
- package/lib/client/generated-view.js +12983 -0
- package/lib/client/horizontal-lines.js +19 -0
- package/lib/client/host-options.js +41 -0
- package/lib/client/host-panels.js +111 -0
- package/lib/client/index.js +77 -0
- package/lib/client/mode-preferences.js +48 -0
- package/lib/client/native-sidebar-contract.js +45 -0
- package/lib/client/native-sidebar-register.js +133 -0
- package/lib/client/native-sidebar-services.js +1 -0
- package/lib/client/native-sidebar.js +98 -0
- package/lib/client/sidebar-integration.js +93 -0
- package/lib/client/ui-onboarding.js +48 -0
- package/lib/client/version.js +14 -0
- package/lib/client.js +17581 -0
- package/lib/client.js.map +1 -0
- package/lib/drawing-feedback.js +284 -0
- package/lib/fibonacci.js +18 -0
- package/lib/ftshare-settings-bridge.js +159 -0
- package/lib/index.js +279 -0
- package/lib/labeled-polyline.js +17 -0
- package/lib/pattern-groups.js +91 -0
- package/lib/price-bands.js +55 -0
- package/lib/price-series.js +47 -0
- package/lib/price-sticks.js +32 -0
- package/lib/types/candle-sequence.d.ts +2 -0
- package/lib/types/chart-adjustment.d.ts +2 -0
- package/lib/types/chart-annotations.d.ts +4 -0
- package/lib/types/chart-applications.d.ts +26 -0
- package/lib/types/chart-context.d.ts +14 -0
- package/lib/types/chart-observation.d.ts +8 -0
- package/lib/types/chart-service-status.d.ts +22 -0
- package/lib/types/chart-source-status.d.ts +47 -0
- package/lib/types/chart-sources.d.ts +25 -0
- package/lib/types/client/BetterSidebarTab.d.ts +12 -0
- package/lib/types/client/ClassicShell.d.ts +4 -0
- package/lib/types/client/KlineContent.d.ts +37 -0
- package/lib/types/client/PanelHost.d.ts +25 -0
- package/lib/types/client/chart-apply.d.ts +13 -0
- package/lib/types/client/chart-context.d.ts +23 -0
- package/lib/types/client/chart-handoff.d.ts +5 -0
- package/lib/types/client/chart-session-resolver.d.ts +2 -0
- package/lib/types/client/client-context.d.ts +16 -0
- package/lib/types/client/conversation.d.ts +43 -0
- package/lib/types/client/default-tab.d.ts +3 -0
- package/lib/types/client/embed.d.ts +37 -0
- package/lib/types/client/generated-view.d.ts +2 -0
- package/lib/types/client/horizontal-lines.d.ts +1 -0
- package/lib/types/client/host-options.d.ts +38 -0
- package/lib/types/client/host-panels.d.ts +55 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/mode-preferences.d.ts +25 -0
- package/lib/types/client/native-sidebar-contract.d.ts +52 -0
- package/lib/types/client/native-sidebar-register.d.ts +46 -0
- package/lib/types/client/native-sidebar-services.d.ts +45 -0
- package/lib/types/client/native-sidebar.d.ts +47 -0
- package/lib/types/client/sidebar-integration.d.ts +12 -0
- package/lib/types/client/ui-onboarding.d.ts +7 -0
- package/lib/types/client/version.d.ts +1 -0
- package/lib/types/drawing-feedback.d.ts +5 -0
- package/lib/types/fibonacci.d.ts +5 -0
- package/lib/types/ftshare-settings-bridge.d.ts +50 -0
- package/lib/types/index.d.ts +26 -0
- package/lib/types/labeled-polyline.d.ts +11 -0
- package/lib/types/pattern-groups.d.ts +2 -0
- package/lib/types/price-bands.d.ts +3 -0
- package/lib/types/price-series.d.ts +5 -0
- package/lib/types/price-sticks.d.ts +3 -0
- package/package.json +155 -4
- package/requirements.txt +6 -0
- package/screenshots.json +8 -0
- package/scripts/bootstrap.sh +5 -0
- package/scripts/dsh-bootstrap.mjs +179 -0
- package/scripts/dsh-mcp-plugin.mjs +27 -0
- package/scripts/run-dsh-kline.mjs +658 -0
- package/scripts/run-dsh-kline.sh +5 -0
- package/server.py +1755 -0
- package/tools/__init__.py +0 -0
- package/tools/annotations.py +119 -0
- package/tools/automatic_analysis.py +158 -0
- package/tools/baostock_source.py +176 -0
- package/tools/calc.py +39 -0
- package/tools/channel_candidates.py +260 -0
- package/tools/channel_preview.py +82 -0
- package/tools/channels.py +104 -0
- package/tools/chart_applications.py +204 -0
- package/tools/chart_context.py +186 -0
- package/tools/chart_edits.py +363 -0
- package/tools/chart_functions.py +451 -0
- package/tools/chart_indicators.py +65 -0
- package/tools/chart_measurements.py +84 -0
- package/tools/chart_source_status.py +32 -0
- package/tools/chart_sources.py +31 -0
- package/tools/closed_daily.py +68 -0
- package/tools/draw.py +410 -0
- package/tools/drawing_feedback.py +45 -0
- package/tools/drawing_interaction.py +117 -0
- package/tools/drawing_verification.py +141 -0
- package/tools/fetch.py +4680 -0
- package/tools/fibonacci.py +83 -0
- package/tools/foreign_daily.py +185 -0
- package/tools/free_sources.py +483 -0
- package/tools/lines.py +91 -0
- package/tools/nine_count.py +66 -0
- package/tools/pattern_groups.py +103 -0
- package/tools/pivots.py +60 -0
- package/tools/polylines.py +131 -0
- package/tools/price_bands.py +165 -0
- package/tools/price_patterns.py +311 -0
- package/tools/price_series.py +162 -0
- package/tools/price_sticks.py +114 -0
- package/tools/range_candidates.py +170 -0
- package/tools/recent_drawing_candidates.py +123 -0
- package/tools/rectangles.py +76 -0
- package/tools/regression_channels.py +87 -0
- package/tools/ta_functions.py +228 -0
- package/tools/trend_lines.py +106 -0
- package/tools/watchlist.py +149 -0
- package/view/ft-logo.jpg +0 -0
- package/view/kline.html +12436 -0
- package/view/vendor/klinecharts.min.js +7 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { PACKAGE_VERSION } from './generated-view';
|
|
4
|
+
import { currentConversationId } from './conversation';
|
|
5
|
+
import { useChartReference } from './chart-session-resolver';
|
|
6
|
+
import { isNewerStableVersion } from './version';
|
|
7
|
+
import { NativeKlineApp, StandaloneKlineApp, standaloneChartSession, standaloneWorkspaceScope, isSymbolLikeName } from './KlineContent';
|
|
8
|
+
const PANEL_MIN = 420;
|
|
9
|
+
const PANEL_MAX = 920;
|
|
10
|
+
const PANEL_DEFAULT = 680;
|
|
11
|
+
const SESSION_ENDPOINT = '/dsh-kline/session';
|
|
12
|
+
const STORAGE_KEY = 'dsh-kline:sidebar:v1';
|
|
13
|
+
const CURRENT_VERSION = PACKAGE_VERSION;
|
|
14
|
+
const LATEST_RELEASE_URL = 'https://api.github.com/repos/FTShare-Lab/dsh_kline/releases/latest';
|
|
15
|
+
export function ClassicShell({ sessions }) {
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
installStyles();
|
|
18
|
+
return () => {
|
|
19
|
+
document.getElementById('dsh-kline-sidebar-styles')?.remove();
|
|
20
|
+
document.documentElement.style.removeProperty('--dsh-kline-sidebar-width');
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
const list = useSyncExternalStore(listener => sessions.list.subscribe(listener), () => sessions.list.getSnapshot());
|
|
24
|
+
const conversationId = currentConversationId(list);
|
|
25
|
+
return _jsx(KlineSidebar, { conversationId: conversationId, sessions: sessions }, conversationId ?? 'no-conversation');
|
|
26
|
+
}
|
|
27
|
+
function KlineSidebar({ conversationId, sessions }) {
|
|
28
|
+
const [state, setState] = useState(readState);
|
|
29
|
+
const reveal = useCallback(() => setState(current => ({ ...current, open: true })), []);
|
|
30
|
+
const reference = useChartReference(sessions, conversationId, reveal);
|
|
31
|
+
const [session, setSession] = useState();
|
|
32
|
+
const [workspaceIdentity, setWorkspaceIdentity] = useState();
|
|
33
|
+
const [available, setAvailable] = useState(true);
|
|
34
|
+
const [update, setUpdate] = useState();
|
|
35
|
+
const drag = useRef();
|
|
36
|
+
const compact = useCompactLayout();
|
|
37
|
+
const panelWidth = compact ? window.innerWidth : state.width;
|
|
38
|
+
const reservedWidth = state.open && !compact ? panelWidth : 0;
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
document.documentElement.style.setProperty('--dsh-kline-sidebar-width', `${reservedWidth}px`);
|
|
41
|
+
writeState(state);
|
|
42
|
+
}, [reservedWidth, state]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
let active = true;
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
setSession(undefined);
|
|
47
|
+
if (!reference)
|
|
48
|
+
return;
|
|
49
|
+
const refresh = async () => {
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(reference.recovery ? `/dsh-kline/recovery?conversation=${encodeURIComponent(conversationId ?? '')}`
|
|
52
|
+
: `${SESSION_ENDPOINT}?session=${encodeURIComponent(reference.session)}`, { cache: 'no-store', signal: controller.signal });
|
|
53
|
+
const payload = await response.json();
|
|
54
|
+
if (!active)
|
|
55
|
+
return;
|
|
56
|
+
if (response.ok && payload.ok === true && typeof payload.session === 'string') {
|
|
57
|
+
setSession({ ...payload, recovery: reference.recovery });
|
|
58
|
+
setAvailable(true);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
setAvailable(response.ok);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
if (active)
|
|
66
|
+
setAvailable(false);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
void refresh();
|
|
70
|
+
return () => {
|
|
71
|
+
active = false;
|
|
72
|
+
controller.abort();
|
|
73
|
+
};
|
|
74
|
+
}, [reference?.session]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
let active = true;
|
|
77
|
+
void checkForUpdate().then(result => {
|
|
78
|
+
if (active)
|
|
79
|
+
setUpdate(result);
|
|
80
|
+
});
|
|
81
|
+
return () => {
|
|
82
|
+
active = false;
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
const setOpen = (open) => setState(current => ({ ...current, open }));
|
|
86
|
+
const setStandaloneIdentity = useCallback((symbol, name) => {
|
|
87
|
+
setWorkspaceIdentity({ symbol, name });
|
|
88
|
+
}, []);
|
|
89
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: `dsh-kline-rail ${state.open ? 'is-open' : ''}`, "aria-label": state.open ? '收起 K 线侧栏' : '打开 K 线侧栏', "aria-expanded": state.open, title: state.open ? '收起 K 线侧栏' : '打开 K 线侧栏', onClick: () => setOpen(!state.open), children: _jsx("span", { "aria-hidden": "true", children: "K" }) }), _jsxs("aside", { className: `dsh-kline-panel ${state.open ? '' : 'is-hidden'}`, style: { width: panelWidth }, "aria-label": "K \u7EBF\u5206\u6790\u4FA7\u680F", "aria-hidden": !state.open, children: [!compact && (_jsx("div", { className: "dsh-kline-resize", role: "separator", "aria-label": "\u8C03\u6574 K \u7EBF\u4FA7\u680F\u5BBD\u5EA6", "aria-orientation": "vertical", "aria-valuemin": PANEL_MIN, "aria-valuemax": PANEL_MAX, "aria-valuenow": panelWidth, tabIndex: 0, onKeyDown: (event) => {
|
|
90
|
+
const next = keyboardWidth(event.key, state.width);
|
|
91
|
+
if (next === undefined)
|
|
92
|
+
return;
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
setState(current => ({ ...current, width: next }));
|
|
95
|
+
}, onPointerDown: (event) => {
|
|
96
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
97
|
+
drag.current = { startX: event.clientX, startWidth: state.width };
|
|
98
|
+
}, onPointerMove: (event) => {
|
|
99
|
+
if (!event.currentTarget.hasPointerCapture(event.pointerId) || drag.current === undefined)
|
|
100
|
+
return;
|
|
101
|
+
const width = clampWidth(drag.current.startWidth + drag.current.startX - event.clientX);
|
|
102
|
+
setState(current => ({ ...current, width }));
|
|
103
|
+
}, onPointerUp: (event) => {
|
|
104
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
105
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
106
|
+
}
|
|
107
|
+
drag.current = undefined;
|
|
108
|
+
} })), _jsxs("header", { className: "dsh-kline-header", children: [_jsxs("div", { children: [_jsx("strong", { children: session?.name && !isSymbolLikeName(session.name, session.symbol)
|
|
109
|
+
? session.name
|
|
110
|
+
: workspaceIdentity?.name && !isSymbolLikeName(workspaceIdentity.name, workspaceIdentity.symbol)
|
|
111
|
+
? workspaceIdentity.name
|
|
112
|
+
: 'K 线分析' }), (session?.symbol ?? workspaceIdentity?.symbol) && _jsx("small", { children: session?.symbol ?? workspaceIdentity?.symbol })] }), _jsx("button", { type: "button", "aria-label": "\u5173\u95ED K \u7EBF\u4FA7\u680F", title: "\u5173\u95ED", onClick: () => setOpen(false), children: "x" })] }), update && (_jsxs("div", { className: "dsh-kline-update", role: "status", children: [_jsxs("span", { children: ["\u53D1\u73B0\u65B0\u7248\u672C v", update.version] }), _jsx("a", { href: update.url, target: "_blank", rel: "noreferrer", children: "\u67E5\u770B\u66F4\u65B0" })] })), _jsx("div", { className: "dsh-kline-content", children: session ? (_jsx(NativeKlineApp, { session: session, conversationId: conversationId ?? 'standalone', ownerConversationId: conversationId, visible: state.open, onIdentity: (symbol, name) => setSession(current => current ? { ...current, symbol, name } : current) }, session.session)) : available ? (_jsx(StandaloneKlineApp, { conversationId: standaloneWorkspaceScope(conversationId), ownerConversationId: conversationId, visible: state.open, onIdentity: setStandaloneIdentity }, standaloneChartSession(conversationId))) : (_jsxs("div", { className: "dsh-kline-empty", role: "status", children: [_jsx("strong", { children: "\u56FE\u8868\u670D\u52A1\u672A\u8FDE\u63A5" }), _jsx("span", { children: "\u8BF7\u68C0\u67E5 dsh_kline MCP \u72B6\u6001" })] })) })] })] }));
|
|
113
|
+
}
|
|
114
|
+
async function checkForUpdate() {
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetch(LATEST_RELEASE_URL, {
|
|
117
|
+
cache: 'no-store',
|
|
118
|
+
headers: { Accept: 'application/vnd.github+json' },
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok)
|
|
121
|
+
return undefined;
|
|
122
|
+
const release = await response.json();
|
|
123
|
+
const version = typeof release.tag_name === 'string' ? release.tag_name.replace(/^v/i, '') : '';
|
|
124
|
+
const url = typeof release.html_url === 'string' ? release.html_url : '';
|
|
125
|
+
if (release.prerelease === true || !url.startsWith('https://github.com/FTShare-Lab/dsh_kline/releases/') || !isNewerStableVersion(version, CURRENT_VERSION))
|
|
126
|
+
return undefined;
|
|
127
|
+
return { version, url };
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function useCompactLayout() {
|
|
134
|
+
const [compact, setCompact] = useState(() => window.innerWidth <= 900);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const update = () => setCompact(window.innerWidth <= 900);
|
|
137
|
+
window.addEventListener('resize', update);
|
|
138
|
+
return () => window.removeEventListener('resize', update);
|
|
139
|
+
}, []);
|
|
140
|
+
return compact;
|
|
141
|
+
}
|
|
142
|
+
function keyboardWidth(key, width) {
|
|
143
|
+
if (key === 'Home')
|
|
144
|
+
return PANEL_MIN;
|
|
145
|
+
if (key === 'End')
|
|
146
|
+
return PANEL_MAX;
|
|
147
|
+
if (key === 'ArrowLeft')
|
|
148
|
+
return clampWidth(width - 20);
|
|
149
|
+
if (key === 'ArrowRight')
|
|
150
|
+
return clampWidth(width + 20);
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
function clampWidth(width) {
|
|
154
|
+
return Math.min(PANEL_MAX, Math.max(PANEL_MIN, Math.round(width)));
|
|
155
|
+
}
|
|
156
|
+
function readState() {
|
|
157
|
+
try {
|
|
158
|
+
const value = JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '{}');
|
|
159
|
+
return {
|
|
160
|
+
open: typeof value.open === 'boolean' ? value.open : true,
|
|
161
|
+
width: clampWidth(typeof value.width === 'number' ? value.width : PANEL_DEFAULT),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return { open: true, width: PANEL_DEFAULT };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function writeState(state) {
|
|
169
|
+
try {
|
|
170
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// The sidebar remains functional when browser storage is unavailable.
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function installStyles() {
|
|
177
|
+
if (document.getElementById('dsh-kline-sidebar-styles'))
|
|
178
|
+
return;
|
|
179
|
+
const style = document.createElement('style');
|
|
180
|
+
style.id = 'dsh-kline-sidebar-styles';
|
|
181
|
+
style.textContent = `
|
|
182
|
+
:root { --dsh-kline-sidebar-width: 0px; }
|
|
183
|
+
#root { margin-right: calc(var(--dsh-sidebar-width, 0px) + var(--dsh-kline-sidebar-width)); transition: margin-right .2s ease; }
|
|
184
|
+
.dsh-kline-panel { position: fixed; z-index: 52; top: 0; right: var(--dsh-sidebar-width, 0px); bottom: 0; display: flex; box-sizing: border-box; max-width: 100vw; flex-direction: column; overflow: hidden; border-left: 1px solid var(--dsw-alias-border-l2, #d9dde5); color: var(--dsw-alias-label-primary, #172033); background: var(--dsw-specific-sidebar-fill, #fff); box-shadow: -8px 0 24px rgb(19 32 54 / 8%); transition: transform .2s ease, visibility 0s; }
|
|
185
|
+
.dsh-kline-panel.is-hidden { visibility: hidden; pointer-events: none; transform: translateX(102%); transition: transform .2s ease, visibility 0s linear .2s; }
|
|
186
|
+
.dsh-kline-header { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 12px; padding: 0 14px 0 18px; border-bottom: 1px solid var(--dsw-alias-border-l2, #d9dde5); background: var(--dsw-specific-sidebar-fill, #fff); }
|
|
187
|
+
.dsh-kline-header > div { display: flex; min-width: 0; align-items: baseline; gap: 8px; }
|
|
188
|
+
.dsh-kline-header strong { overflow: hidden; font-size: 14px; line-height: 20px; text-overflow: ellipsis; white-space: nowrap; }
|
|
189
|
+
.dsh-kline-header small { color: var(--dsw-alias-label-tertiary, #7a8495); font-size: 11px; white-space: nowrap; }
|
|
190
|
+
.dsh-kline-header button { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 6px; color: inherit; background: transparent; cursor: pointer; font: 20px/1 system-ui; }
|
|
191
|
+
.dsh-kline-header button:hover { background: var(--dsw-alias-interactive-bg-hover, #eef1f5); }
|
|
192
|
+
.dsh-kline-update { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 14px 7px 18px; border-bottom: 1px solid #f4c48d; color: #8a4b08; background: #fff8ef; font-size: 12px; }
|
|
193
|
+
.dsh-kline-update a { color: #a65400; font-weight: 600; text-decoration: none; white-space: nowrap; }
|
|
194
|
+
.dsh-kline-update a:hover { text-decoration: underline; }
|
|
195
|
+
.dsh-kline-content { min-height: 0; flex: 1; overflow: hidden; background: #fff; }
|
|
196
|
+
.dsh-kline-native-host { display: block; width: 100%; height: 100%; overflow: hidden; background: #fff; }
|
|
197
|
+
.dsh-kline-native { display: flex; height: 100%; min-width: 340px; flex-direction: column; overflow: hidden; color: #20242b; background: #fff; font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
198
|
+
.dsh-kline-tabs, .dsh-kline-toolbar { display: flex; flex: 0 0 auto; align-items: center; gap: 6px; padding: 7px 10px; overflow-x: auto; border-bottom: 1px solid #e7ebef; scrollbar-width: none; }
|
|
199
|
+
.dsh-kline-tabs::-webkit-scrollbar, .dsh-kline-toolbar::-webkit-scrollbar { display: none; }
|
|
200
|
+
.dsh-kline-tabs button, .dsh-kline-toolbar button { min-width: 42px; height: 30px; padding: 0 10px; border: 1px solid #dfe4ea; border-radius: 4px; color: #20242b; background: #f7f9fb; cursor: pointer; white-space: nowrap; }
|
|
201
|
+
.dsh-kline-tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; font-weight: 600; }
|
|
202
|
+
.dsh-kline-tabs button.active { border-bottom-color: #ff6b00; color: #20242b; }
|
|
203
|
+
.dsh-kline-toolbar button.active { border-color: #ff6b00; color: #fff; background: #ff6b00; }
|
|
204
|
+
.dsh-kline-toolbar button:focus-visible, .dsh-kline-tabs button:focus-visible { outline: 2px solid #4d6bfe; outline-offset: 1px; }
|
|
205
|
+
.dsh-kline-toolbar-separator { width: 1px; height: 22px; flex: 0 0 1px; margin: 0 2px; background: #dfe4ea; }
|
|
206
|
+
.dsh-kline-indicators { padding-top: 5px; padding-bottom: 5px; }
|
|
207
|
+
.dsh-kline-chart-shell { position: relative; min-height: 320px; flex: 1 1 auto; overflow: hidden; }
|
|
208
|
+
.dsh-kline-chart { width: 100%; height: 100%; min-height: 320px; }
|
|
209
|
+
.dsh-kline-loading { position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; color: #677286; background: rgb(255 255 255 / 78%); }
|
|
210
|
+
.dsh-kline-error { flex: 0 0 auto; padding: 7px 12px; color: #b42318; background: #fff1f0; }
|
|
211
|
+
.dsh-kline-levels { display: flex; flex: 0 0 auto; gap: 6px; padding: 6px 10px; overflow-x: auto; border-top: 1px solid #e7ebef; scrollbar-width: none; }
|
|
212
|
+
.dsh-kline-levels span { padding: 2px 6px; border-radius: 3px; color: #516070; background: #f1f4f7; white-space: nowrap; }
|
|
213
|
+
.dsh-kline-pane-empty { display: grid; height: 100%; place-items: center; color: #7a8495; }
|
|
214
|
+
.dsh-kline-news, .dsh-kline-overview { min-height: 0; flex: 1; overflow-y: auto; padding: 12px 16px 24px; }
|
|
215
|
+
.dsh-kline-news article { padding: 12px 0; border-bottom: 1px solid #e7ebef; }
|
|
216
|
+
.dsh-kline-news article > div { display: flex; align-items: baseline; gap: 8px; }
|
|
217
|
+
.dsh-kline-news article span { flex: 0 0 auto; padding: 1px 5px; border-radius: 3px; color: #b54708; background: #fff3e8; font-size: 11px; }
|
|
218
|
+
.dsh-kline-news a, .dsh-kline-news strong { color: #20242b; font-weight: 650; text-decoration: none; }
|
|
219
|
+
.dsh-kline-news a:hover { color: #ff6b00; }
|
|
220
|
+
.dsh-kline-news time, .dsh-kline-news p, .dsh-kline-overview p, .dsh-kline-news footer, .dsh-kline-overview footer { color: #7a8495; }
|
|
221
|
+
.dsh-kline-news time { display: block; margin-top: 5px; font-size: 11px; }
|
|
222
|
+
.dsh-kline-news p { margin: 7px 0 0; }
|
|
223
|
+
.dsh-kline-overview h3 { margin: 0 0 12px; font-size: 17px; }
|
|
224
|
+
.dsh-kline-facts, .dsh-kline-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
|
|
225
|
+
.dsh-kline-facts > div, .dsh-kline-metrics > div { min-width: 0; padding: 9px 10px; border: 1px solid #e7ebef; border-radius: 4px; }
|
|
226
|
+
.dsh-kline-facts span, .dsh-kline-metrics span { display: block; color: #7a8495; font-size: 11px; }
|
|
227
|
+
.dsh-kline-facts strong, .dsh-kline-metrics strong { display: block; overflow: hidden; margin-top: 3px; text-overflow: ellipsis; white-space: nowrap; }
|
|
228
|
+
.dsh-kline-overview dl { margin: 0; }
|
|
229
|
+
.dsh-kline-overview dl > div { display: grid; grid-template-columns: minmax(90px, 30%) 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid #edf0f4; }
|
|
230
|
+
.dsh-kline-overview dt { color: #7a8495; }
|
|
231
|
+
.dsh-kline-overview dd { margin: 0; overflow-wrap: anywhere; }
|
|
232
|
+
.dsh-kline-news footer, .dsh-kline-overview footer { margin-top: 14px; padding-top: 10px; border-top: 1px solid #e7ebef; font-size: 11px; }
|
|
233
|
+
.dsh-kline-empty { display: flex; height: 100%; align-items: center; justify-content: center; flex-direction: column; gap: 6px; color: var(--dsw-alias-label-tertiary, #7a8495); text-align: center; }
|
|
234
|
+
.dsh-kline-empty strong { color: var(--dsw-alias-label-secondary, #505b6c); font-size: 14px; }
|
|
235
|
+
.dsh-kline-empty span { font-size: 12px; }
|
|
236
|
+
/* The rail sits outside the panel, so it stays clickable without painting
|
|
237
|
+
over fixed onboarding dialogs rendered inside the panel's shadow root. */
|
|
238
|
+
.dsh-kline-rail { position: fixed; z-index: 51; top: 50%; right: calc(var(--dsh-sidebar-width, 0px) + var(--dsh-kline-sidebar-width) + 10px); display: inline-flex; width: 32px; height: 88px; align-items: center; justify-content: center; padding: 0; border: 1px solid var(--dsw-alias-border-l2, #d9dde5); border-radius: 6px; color: var(--dsw-alias-label-primary, #172033); background: var(--dsw-specific-sidebar-fill, #fff); box-shadow: 0 4px 14px rgb(19 32 54 / 10%); cursor: pointer; transform: translateY(-50%); transition: right .2s ease; }
|
|
239
|
+
.dsh-kline-rail span { font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
240
|
+
.dsh-kline-rail:hover { background: var(--dsw-alias-interactive-bg-hover, #eef1f5); }
|
|
241
|
+
.dsh-kline-resize { position: absolute; z-index: 3; top: 0; bottom: 0; left: -4px; width: 8px; cursor: col-resize; touch-action: none; }
|
|
242
|
+
.dsh-kline-resize:hover, .dsh-kline-resize:focus-visible { background: var(--dsw-alias-interactive-bg-hover-accent, #4d6bfe); outline: 0; }
|
|
243
|
+
@media (max-width: 900px) {
|
|
244
|
+
#root { margin-right: var(--dsh-sidebar-width, 0px); }
|
|
245
|
+
.dsh-kline-panel { right: 0; width: 100vw !important; }
|
|
246
|
+
.dsh-kline-rail { top: 74px; right: 10px; width: 36px; height: 36px; transform: none; }
|
|
247
|
+
.dsh-kline-rail.is-open { display: none; }
|
|
248
|
+
.dsh-kline-chart-shell { min-height: 280px; }
|
|
249
|
+
.dsh-kline-chart { min-height: 280px; }
|
|
250
|
+
}
|
|
251
|
+
@media (prefers-reduced-motion: reduce) { #root, .dsh-kline-panel, .dsh-kline-rail { transition: none; } }
|
|
252
|
+
`;
|
|
253
|
+
document.head.appendChild(style);
|
|
254
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { mountKlineView } from './generated-view';
|
|
4
|
+
import { InterfaceContext } from './mode-preferences';
|
|
5
|
+
import { onboardingKind, acknowledgeOnboarding } from './ui-onboarding';
|
|
6
|
+
import { klineHostDataset, sameSymbol } from './embed';
|
|
7
|
+
// The chart view can load data itself through the loopback tool proxy. It
|
|
8
|
+
// therefore does not need an AI-produced chart session to present its search
|
|
9
|
+
// workspace; only AI-produced snapshots need the opaque session reference.
|
|
10
|
+
const STANDALONE_CHART_PAYLOAD = {
|
|
11
|
+
ok: true,
|
|
12
|
+
workspace_mode: 'launcher',
|
|
13
|
+
// A new conversation starts at the Market page. Keep a dormant default
|
|
14
|
+
// instrument so an explicit click on the empty Chart page has something
|
|
15
|
+
// useful to open; launcher initialization itself must not load it.
|
|
16
|
+
default_symbol: '000001.XSHG',
|
|
17
|
+
default_name: '上证指数',
|
|
18
|
+
symbol: '',
|
|
19
|
+
name: '',
|
|
20
|
+
interval: 'day',
|
|
21
|
+
range_key: 'ytd',
|
|
22
|
+
chartCommands: [],
|
|
23
|
+
};
|
|
24
|
+
export function standaloneChartSession(conversationId) {
|
|
25
|
+
return `standalone:${conversationId ?? 'global'}`;
|
|
26
|
+
}
|
|
27
|
+
export function standaloneWorkspaceScope(conversationId) {
|
|
28
|
+
return `direct:${conversationId ?? 'global'}`;
|
|
29
|
+
}
|
|
30
|
+
export function isSymbolLikeName(value, symbol) {
|
|
31
|
+
const text = String(value ?? '').trim();
|
|
32
|
+
const normalizedSymbol = String(symbol ?? '').trim().toUpperCase();
|
|
33
|
+
if (!text)
|
|
34
|
+
return true;
|
|
35
|
+
if (normalizedSymbol && text.toUpperCase() === normalizedSymbol)
|
|
36
|
+
return true;
|
|
37
|
+
const bareSymbol = normalizedSymbol.split('.', 1)[0];
|
|
38
|
+
return text.toUpperCase() === bareSymbol;
|
|
39
|
+
}
|
|
40
|
+
export function NativeKlineApp({ session, conversationId, ownerConversationId, visible = true, onIdentity }) {
|
|
41
|
+
const host = useRef(null);
|
|
42
|
+
const visibility = useRef(visible);
|
|
43
|
+
visibility.current = visible;
|
|
44
|
+
const contextNotice = useRef(() => { });
|
|
45
|
+
useEffect(() => contextNotice.current(), [visible]);
|
|
46
|
+
const interfaceMode = { ...useContext(InterfaceContext), onboardingKind, acknowledgeOnboarding };
|
|
47
|
+
const [error, setError] = useState('');
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
let active = true;
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
let dispose;
|
|
52
|
+
Promise.all([
|
|
53
|
+
fetch(session.recovery ? `/dsh-kline/recovery?conversation=${encodeURIComponent(ownerConversationId ?? '')}`
|
|
54
|
+
: `/dsh-kline/data?session=${encodeURIComponent(session.session)}`, { cache: 'no-store', signal: controller.signal }).then(response => response.json()),
|
|
55
|
+
loadKlinecharts(),
|
|
56
|
+
]).then(([result, klinecharts]) => {
|
|
57
|
+
if (!active || !host.current)
|
|
58
|
+
return;
|
|
59
|
+
if (!result?.ok || !result?.payload)
|
|
60
|
+
throw new Error(result?.message || '图表会话不可用');
|
|
61
|
+
if (session.recovery && (result.session !== session.session || result.conversation_id !== ownerConversationId))
|
|
62
|
+
throw new Error('图表恢复来源已变化,请重新打开当前对话。');
|
|
63
|
+
const root = host.current.shadowRoot || host.current.attachShadow({ mode: 'open' });
|
|
64
|
+
dispose = mountKlineView(root, result.payload, { klinecharts, conversationId, ownerConversationId, isVisible: () => visibility.current,
|
|
65
|
+
onContextPublisher: (publisher) => { contextNotice.current = publisher.notify; }, chartSession: session.session, onIdentity, interfaceMode });
|
|
66
|
+
}).catch(reason => active && setError(String(reason?.message || reason)));
|
|
67
|
+
return () => {
|
|
68
|
+
active = false;
|
|
69
|
+
controller.abort();
|
|
70
|
+
dispose?.();
|
|
71
|
+
};
|
|
72
|
+
}, [session.session, conversationId]);
|
|
73
|
+
return (_jsx("div", { className: "dsh-kline-native-host", style: { width: '100%', height: '100%', overflow: 'hidden' }, ref: host, children: error && _jsx("div", { className: "dsh-kline-error", role: "alert", children: error }) }));
|
|
74
|
+
}
|
|
75
|
+
export function StandaloneKlineApp({ conversationId, ownerConversationId, visible = true, onIdentity, embedded = false, chrome = 'full', theme, symbol, name }) {
|
|
76
|
+
const host = useRef(null);
|
|
77
|
+
const visibility = useRef(visible);
|
|
78
|
+
visibility.current = visible;
|
|
79
|
+
const contextNotice = useRef(() => { });
|
|
80
|
+
// The theme is read once at mount (the runtime needs it before first paint);
|
|
81
|
+
// later changes go through the bridge, so they never remount the view.
|
|
82
|
+
const themeAtMount = useRef(theme);
|
|
83
|
+
useEffect(() => contextNotice.current(), [visible]);
|
|
84
|
+
const interfaceMode = { ...useContext(InterfaceContext), onboardingKind, acknowledgeOnboarding };
|
|
85
|
+
const [error, setError] = useState('');
|
|
86
|
+
const [ready, setReady] = useState(false);
|
|
87
|
+
const bridge = useRef(null);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
let active = true;
|
|
90
|
+
let dispose;
|
|
91
|
+
setReady(false);
|
|
92
|
+
bridge.current = null;
|
|
93
|
+
loadKlinecharts().then(klinecharts => {
|
|
94
|
+
if (!active || !host.current)
|
|
95
|
+
return;
|
|
96
|
+
const root = host.current.shadowRoot || host.current.attachShadow({ mode: 'open' });
|
|
97
|
+
dispose = mountKlineView(root, STANDALONE_CHART_PAYLOAD, {
|
|
98
|
+
klinecharts,
|
|
99
|
+
conversationId,
|
|
100
|
+
ownerConversationId,
|
|
101
|
+
isVisible: () => visibility.current,
|
|
102
|
+
onContextPublisher: (publisher) => { contextNotice.current = publisher.notify; },
|
|
103
|
+
chartSession: standaloneChartSession(conversationId),
|
|
104
|
+
onIdentity,
|
|
105
|
+
interfaceMode,
|
|
106
|
+
embedded,
|
|
107
|
+
theme: themeAtMount.current,
|
|
108
|
+
onReady: (api) => { bridge.current = api; setReady(true); },
|
|
109
|
+
});
|
|
110
|
+
}).catch(reason => active && setError(String(reason?.message || reason)));
|
|
111
|
+
return () => {
|
|
112
|
+
active = false;
|
|
113
|
+
dispose?.();
|
|
114
|
+
};
|
|
115
|
+
}, [conversationId, onIdentity, embedded]);
|
|
116
|
+
// Follow an external selection once the view is live. A symbol the chart
|
|
117
|
+
// already shows is skipped: the panel publishes its own selection back, and
|
|
118
|
+
// that round trip through the host bus must not reopen the same instrument.
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!ready || symbol === undefined || symbol === '')
|
|
121
|
+
return;
|
|
122
|
+
if (sameSymbol(bridge.current?.currentSymbol(), symbol))
|
|
123
|
+
return;
|
|
124
|
+
void bridge.current?.openSymbol(symbol, name).catch(() => { });
|
|
125
|
+
}, [ready, symbol, name]);
|
|
126
|
+
// A host palette pins the chart theme; a change repaints without a remount.
|
|
127
|
+
// No theme means "follow the host document", which is the old behaviour.
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (!ready)
|
|
130
|
+
return;
|
|
131
|
+
bridge.current?.setTheme(theme ?? 'host');
|
|
132
|
+
}, [ready, theme]);
|
|
133
|
+
return (_jsx("div", { className: "dsh-kline-native-host", ...klineHostDataset({ embedded, chrome }), style: { width: '100%', height: '100%', overflow: 'hidden' }, ref: host, children: error && _jsx("div", { className: "dsh-kline-error", role: "alert", children: error }) }));
|
|
134
|
+
}
|
|
135
|
+
function loadKlinecharts() {
|
|
136
|
+
const loaded = () => typeof window.klinecharts?.init === 'function' ? window.klinecharts : undefined;
|
|
137
|
+
if (loaded())
|
|
138
|
+
return Promise.resolve(loaded());
|
|
139
|
+
if (window.__dshKlineVendorPromise)
|
|
140
|
+
return window.__dshKlineVendorPromise;
|
|
141
|
+
window.__dshKlineVendorPromise = new Promise((resolve, reject) => {
|
|
142
|
+
const script = document.createElement('script');
|
|
143
|
+
script.src = '/dsh-kline/vendor/klinecharts.min.js';
|
|
144
|
+
script.async = true;
|
|
145
|
+
script.dataset.dshKlineVendor = 'true';
|
|
146
|
+
script.onload = () => loaded() ? resolve(loaded()) : reject(new Error('KLineCharts 已下载但没有正确初始化'));
|
|
147
|
+
script.onerror = () => reject(new Error('KLineCharts 加载失败'));
|
|
148
|
+
document.head.appendChild(script);
|
|
149
|
+
}).catch(error => {
|
|
150
|
+
window.__dshKlineVendorPromise = undefined;
|
|
151
|
+
document.querySelector('script[data-dsh-kline-vendor="true"]')?.remove();
|
|
152
|
+
throw error;
|
|
153
|
+
});
|
|
154
|
+
return window.__dshKlineVendorPromise;
|
|
155
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useRef } from 'react';
|
|
3
|
+
import { StandaloneKlineApp } from './KlineContent';
|
|
4
|
+
import { createPanelMountRegistry, createPanelMounts } from "./host-panels.js";
|
|
5
|
+
/**
|
|
6
|
+
* The chart as a host panel body.
|
|
7
|
+
*
|
|
8
|
+
* The host declares a slot, renders it with `{ symbol, name, onIdentity }` and
|
|
9
|
+
* asks the chart to fill it through `klinePanels.mount(seat)`. The body is the
|
|
10
|
+
* same chart the sidebar and the tab draw, only bounded and without the
|
|
11
|
+
* workspace chrome that belongs to the sidebar.
|
|
12
|
+
*/
|
|
13
|
+
export function KlinePanelHost({ seat, chrome = 'chart-search', symbol, name, onIdentity }) {
|
|
14
|
+
// The host may hand over a fresh callback per render; keep the chart's effect
|
|
15
|
+
// dependencies stable through a ref so a re-render never remounts it.
|
|
16
|
+
const identity = useRef(onIdentity);
|
|
17
|
+
identity.current = onIdentity;
|
|
18
|
+
const publishIdentity = useCallback((nextSymbol, nextName) => {
|
|
19
|
+
identity.current?.(nextSymbol, nextName);
|
|
20
|
+
}, []);
|
|
21
|
+
return (_jsx("div", { "data-symbol": symbol ?? '', style: { width: '100%', height: '100%', minHeight: 360 }, children: _jsx(StandaloneKlineApp, { conversationId: 'host-panel:' + seat, embedded: true, chrome: chrome, symbol: symbol, name: name, onIdentity: publishIdentity }) }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Register the optional host panel contract.
|
|
25
|
+
*
|
|
26
|
+
* The `klinePanels` service exists for every host, but it registers nothing
|
|
27
|
+
* until a host mounts a seat: without a caller no slot is injected, so a host
|
|
28
|
+
* that does not know this contract sees the plugin exactly as before. Mounts
|
|
29
|
+
* requested before the `slots` service settles are applied once it does.
|
|
30
|
+
* @param ctx - the client context to register on.
|
|
31
|
+
*/
|
|
32
|
+
export function registerPanelHosts(ctx) {
|
|
33
|
+
const panels = createPanelMountRegistry();
|
|
34
|
+
const panelBody = (seat, chrome) => (props) => _jsx(KlinePanelHost, { seat: seat, chrome: chrome, ...props });
|
|
35
|
+
ctx.inject(['slots'], scoped => {
|
|
36
|
+
scoped.effect(() => {
|
|
37
|
+
const slots = scoped.get('slots');
|
|
38
|
+
if (slots === undefined)
|
|
39
|
+
return () => { };
|
|
40
|
+
return panels.connect(createPanelMounts({ slots }, panelBody));
|
|
41
|
+
}, 'dsh-kline: host panels');
|
|
42
|
+
});
|
|
43
|
+
ctx.provide('klinePanels', {
|
|
44
|
+
mount: panels.mount,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Synchronous local-state guard; receipts are not proof of screen pixels. */
|
|
2
|
+
import { drawingInventory, observationKey } from "../chart-observation.js";
|
|
3
|
+
import { sanitizeDrawingFeedback } from "../drawing-feedback.js";
|
|
4
|
+
const TOKEN = /^[A-Za-z0-9_-]{32}$/;
|
|
5
|
+
export function createChartApplyController(options) {
|
|
6
|
+
const seen = new Map();
|
|
7
|
+
let applying = false;
|
|
8
|
+
return {
|
|
9
|
+
consume(command, publication) {
|
|
10
|
+
const token = command?.candidate_chart_session, lease = command?.lease_id;
|
|
11
|
+
if (typeof token !== 'string' || !TOKEN.test(token) || typeof lease !== 'string' || !TOKEN.test(lease))
|
|
12
|
+
return undefined;
|
|
13
|
+
const previous = seen.get(token);
|
|
14
|
+
if (previous)
|
|
15
|
+
return previous.lease_id === lease ? previous : undefined;
|
|
16
|
+
const receipt = { candidate_chart_session: token, lease_id: lease, status: 'rejected', reason: 'invalid_delivery' };
|
|
17
|
+
seen.set(token, receipt);
|
|
18
|
+
if (seen.size > 64 || applying || !options.conversationId || command.conversation_id !== options.conversationId
|
|
19
|
+
|| command.view_id !== options.viewId || command.context_ref !== publication.context_ref
|
|
20
|
+
|| command.expected_revision !== publication.revision || !Number.isSafeInteger(command.expires_at_ms)
|
|
21
|
+
|| command.expires_at_ms < Date.now())
|
|
22
|
+
return receipt;
|
|
23
|
+
if (!options.isActive()) {
|
|
24
|
+
receipt.reason = 'inactive';
|
|
25
|
+
return receipt;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
if (observationKey(options.capture()) !== observationKey(command.base_state)) {
|
|
29
|
+
receipt.reason = 'local_state_changed';
|
|
30
|
+
return receipt;
|
|
31
|
+
}
|
|
32
|
+
applying = true;
|
|
33
|
+
const result = options.apply(command.payload, token);
|
|
34
|
+
if (result?.then)
|
|
35
|
+
throw Error('async_apply_not_supported');
|
|
36
|
+
const allowed = [...new Map([...command.base_state.drawings.filter((d) => d.origin === 'ai'),
|
|
37
|
+
...drawingInventory(command.payload)].map((d) => [d.id, d])).values()];
|
|
38
|
+
receipt.drawing_feedback = sanitizeDrawingFeedback(result, allowed);
|
|
39
|
+
const expected = { ...command.base_state, source_chart_session: token,
|
|
40
|
+
drawings: [...command.base_state.drawings.filter((d) => d.origin !== 'ai'), ...drawingInventory(command.payload)] };
|
|
41
|
+
if (observationKey(options.capture()) !== observationKey(expected)) {
|
|
42
|
+
receipt.status = 'outcome_unknown';
|
|
43
|
+
receipt.reason = 'apply_failed';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
receipt.status = 'applied';
|
|
47
|
+
delete receipt.reason;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
receipt.status = error?.rolledBack === true ? 'failed' : 'outcome_unknown';
|
|
52
|
+
receipt.reason = error?.rolledBack === true ? 'apply_failed' : 'rollback_failed';
|
|
53
|
+
const allowed = [...new Map([...command.base_state.drawings.filter((d) => d.origin === 'ai'),
|
|
54
|
+
...drawingInventory(command.payload)].map((d) => [d.id, d])).values()];
|
|
55
|
+
receipt.drawing_feedback = sanitizeDrawingFeedback(error?.drawing_feedback, allowed);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
applying = false;
|
|
59
|
+
}
|
|
60
|
+
return receipt;
|
|
61
|
+
},
|
|
62
|
+
confirm(ack) {
|
|
63
|
+
const local = seen.get(ack?.candidate_chart_session);
|
|
64
|
+
if (!local || local.lease_id !== ack.lease_id || ack.apply_status !== 'applied' || local.status !== 'applied'
|
|
65
|
+
|| ack.confirmed_chart_session !== ack.candidate_chart_session)
|
|
66
|
+
return;
|
|
67
|
+
if (!local.confirmed) {
|
|
68
|
+
options.confirm?.(ack.candidate_chart_session);
|
|
69
|
+
local.confirmed = true;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|