@ftshare-lab/dsh-kline 0.0.0-stage → 0.6.10
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 +601 -0
- package/LICENSE +21 -0
- package/PROVENANCE.md +13 -0
- package/README.en.md +116 -0
- package/README.md +115 -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 +43 -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.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.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/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/index.js +62 -0
- package/lib/client/mode-preferences.js +28 -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 +96 -0
- package/lib/client/sidebar-integration.js +93 -0
- package/lib/client/ui-onboarding.js +42 -0
- package/lib/client/version.js +14 -0
- package/lib/client.js +17382 -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/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 +14 -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/index.d.ts +4 -0
- package/lib/types/client/mode-preferences.d.ts +13 -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 +6 -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 +153 -4
- package/requirements.txt +6 -0
- package/screenshots.json +11 -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,19 @@
|
|
|
1
|
+
/** Merge a drawing-only result into its owning view, preserving candles and toggles. */
|
|
2
|
+
const AI_DRAWING_COMMANDS = new Set(['DRAW_HORIZONTAL_LINE', 'DRAW_AGENT_TREND_LINE', 'DRAW_AGENT_CHANNEL', 'DRAW_AGENT_RECTANGLE', 'DRAW_AGENT_FIBONACCI', 'DRAW_AGENT_POLYLINE', 'DRAW_AGENT_ANNOTATION']);
|
|
3
|
+
export function mergeHorizontalLineSnapshot(payload, saved) {
|
|
4
|
+
if (payload?.drawing_guard || payload?.view_source_guard || !payload?.drawing_only || saved?.session !== payload.drawing_parent_session
|
|
5
|
+
|| saved?.payload?.symbol !== payload.symbol || saved?.payload?.interval !== payload.interval
|
|
6
|
+
|| !Array.isArray(saved?.payload?.chartCommands))
|
|
7
|
+
return undefined;
|
|
8
|
+
const { _live_chart_session, _live_application_pending, ...savedPayload } = saved.payload;
|
|
9
|
+
return {
|
|
10
|
+
...savedPayload,
|
|
11
|
+
drawing_only: true,
|
|
12
|
+
drawing_parent_session: payload.drawing_parent_session,
|
|
13
|
+
indicators_explicit: false,
|
|
14
|
+
chartCommands: [
|
|
15
|
+
...saved.payload.chartCommands.filter((command) => !AI_DRAWING_COMMANDS.has(command.type)),
|
|
16
|
+
...payload.chartCommands.filter((command) => AI_DRAWING_COMMANDS.has(command.type)),
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { currentConversationId } from './conversation';
|
|
5
|
+
import { ClassicShell } from './ClassicShell';
|
|
6
|
+
import { BetterSidebarBridge } from './BetterSidebarTab';
|
|
7
|
+
import { NativeSidebarBridgeView, registerNativeSidebar } from './native-sidebar';
|
|
8
|
+
import { cleanClassicTabs, isSidebarUsable } from './sidebar-integration';
|
|
9
|
+
import { InterfaceContext, readDisplayMode, resolveDisplayMode } from './mode-preferences';
|
|
10
|
+
import { captureOnboarding } from './ui-onboarding';
|
|
11
|
+
export const inject = ['sessions'];
|
|
12
|
+
export function apply(ctx) {
|
|
13
|
+
let service;
|
|
14
|
+
const listeners = new Set();
|
|
15
|
+
const emit = () => listeners.forEach(listener => listener());
|
|
16
|
+
const subscribe = (listener) => { listeners.add(listener); return () => { listeners.delete(listener); }; };
|
|
17
|
+
const subscribeSessions = (listener) => ctx.sessions.list.subscribe(listener);
|
|
18
|
+
const preference = readDisplayMode();
|
|
19
|
+
captureOnboarding();
|
|
20
|
+
// Registered before the router paints, so the first frame already knows
|
|
21
|
+
// whether the host owns a right column this plugin can put a tab in.
|
|
22
|
+
const native = registerNativeSidebar(ctx, emit);
|
|
23
|
+
function Router() {
|
|
24
|
+
const sidebar = useSyncExternalStore(subscribe, () => service);
|
|
25
|
+
const nativeTab = useSyncExternalStore(subscribe, () => native.available());
|
|
26
|
+
const conversation = useSyncExternalStore(subscribeSessions, () => currentConversationId(ctx.sessions.list.getSnapshot()));
|
|
27
|
+
const available = nativeTab || isSidebarUsable(sidebar);
|
|
28
|
+
const mode = resolveDisplayMode(preference, available);
|
|
29
|
+
// A tab body lives in a Session, so before one exists the chart has no
|
|
30
|
+
// tab to live in — whichever column the host owns. The classic launcher
|
|
31
|
+
// covers that screen, which is what the old aria-label probe approximated
|
|
32
|
+
// and only ever got right in an English UI.
|
|
33
|
+
const showClassicLauncher = mode === 'classic' || conversation === undefined;
|
|
34
|
+
return _jsxs(InterfaceContext.Provider, { value: { preference, mode, available }, children: [nativeTab && mode === 'better-sidebar' && _jsx(NativeSidebarBridgeView, { bridge: native, sessions: ctx.sessions }), !nativeTab && sidebar && _jsx(BetterSidebarBridge, { service: sidebar, sessions: ctx.sessions }), nativeTab && sidebar && _jsx(RetireBetterSidebarTabs, { service: sidebar }), showClassicLauncher && _jsx(ClassicShell, { sessions: ctx.sessions })] });
|
|
35
|
+
}
|
|
36
|
+
ctx.effect(() => {
|
|
37
|
+
const host = document.createElement('div');
|
|
38
|
+
host.dataset.dshKlineRouter = '';
|
|
39
|
+
document.body.appendChild(host);
|
|
40
|
+
const root = createRoot(host);
|
|
41
|
+
root.render(_jsx(Router, {}));
|
|
42
|
+
return () => { root.unmount(); host.remove(); listeners.clear(); };
|
|
43
|
+
}, 'dsh-kline: interface router');
|
|
44
|
+
// A separate dependency scope does not block the parent when absent.
|
|
45
|
+
ctx.inject(['betterSidebar'], scoped => {
|
|
46
|
+
scoped.effect(() => {
|
|
47
|
+
service = scoped.get('betterSidebar');
|
|
48
|
+
emit();
|
|
49
|
+
return () => { service = undefined; emit(); };
|
|
50
|
+
}, 'dsh-kline: optional sidebar');
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Remove the tabs this plugin saved into Better Sidebar's workbench once the
|
|
55
|
+
* native tab takes the same kind over. Better Sidebar draws a saved tab of an
|
|
56
|
+
* unregistered type as "plugin not loaded", so an upgrade would otherwise
|
|
57
|
+
* leave a broken-looking tab behind.
|
|
58
|
+
*/
|
|
59
|
+
function RetireBetterSidebarTabs({ service }) {
|
|
60
|
+
useEffect(() => cleanClassicTabs(service), [service]);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
export const DISPLAY_MODE_KEY = 'dsh-kline:display-mode:v1';
|
|
3
|
+
export const AUTO_OPEN_KEY = 'dsh-kline:auto-open-after-analysis:v1';
|
|
4
|
+
export const UI_SEEN_KEY = 'dsh-kline:ui-change-seen:v0.2.0';
|
|
5
|
+
export const InterfaceContext = createContext({ preference: 'classic', mode: 'classic', available: false });
|
|
6
|
+
export function readDisplayMode(storage = globalThis.localStorage) {
|
|
7
|
+
try {
|
|
8
|
+
const value = storage.getItem(DISPLAY_MODE_KEY);
|
|
9
|
+
return value === 'better-sidebar' ? value : 'classic';
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return 'classic';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function resolveDisplayMode(preference, available) {
|
|
16
|
+
// A chart should be available before a new DSH conversation has created a
|
|
17
|
+
// workbench session. The native tab is therefore opt-in; the classic K
|
|
18
|
+
// launcher remains the dependable default.
|
|
19
|
+
return preference === 'better-sidebar' && available ? 'better-sidebar' : 'classic';
|
|
20
|
+
}
|
|
21
|
+
export function readAutoOpen(storage = globalThis.localStorage) {
|
|
22
|
+
try {
|
|
23
|
+
return storage.getItem(AUTO_OPEN_KEY) !== 'false';
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { KLINE_TAB_ID, klineTabTitle } from "./sidebar-integration.js";
|
|
2
|
+
/**
|
|
3
|
+
* The static half of the native right-Sidebar integration.
|
|
4
|
+
*
|
|
5
|
+
* Kept free of JSX so the tests can import it directly: the registration itself
|
|
6
|
+
* needs a host context, but what this plugin contributes — the tab kind, the
|
|
7
|
+
* band it registers in, the chip title and the guide entry — is plain data.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Implementation identity of the tab type; also the key its body registers
|
|
11
|
+
* under. The host only requires it to be unique across every registration, and
|
|
12
|
+
* a package name is the natural value for a type shipped from another package.
|
|
13
|
+
*/
|
|
14
|
+
export const NATIVE_TAB_ID = '@ftshare-lab/dsh-kline';
|
|
15
|
+
/**
|
|
16
|
+
* The type definition this plugin contributes.
|
|
17
|
+
*
|
|
18
|
+
* A page type (no address `patterns`) is opened by kind, which is what the
|
|
19
|
+
* auto-open path does; the guide entry is how a person reaches the chart from
|
|
20
|
+
* the host's own add-tab page. Both keep the product label separate from the
|
|
21
|
+
* internal kind, exactly like the Better Sidebar title does.
|
|
22
|
+
*
|
|
23
|
+
* `keepMounted` matters for the chart: collapsing the right column or
|
|
24
|
+
* switching tabs must not tear the chart down, because the view keeps its
|
|
25
|
+
* own state (last instrument reference, zoom, drawings) that a remount loses.
|
|
26
|
+
*/
|
|
27
|
+
export function nativeTabDefinition() {
|
|
28
|
+
return {
|
|
29
|
+
id: NATIVE_TAB_ID,
|
|
30
|
+
kind: KLINE_TAB_ID,
|
|
31
|
+
keepMounted: true,
|
|
32
|
+
priority: 'extension',
|
|
33
|
+
title: () => klineTabTitle(),
|
|
34
|
+
guide: [{
|
|
35
|
+
id: NATIVE_TAB_ID,
|
|
36
|
+
order: 120,
|
|
37
|
+
title: () => klineTabTitle(),
|
|
38
|
+
description: nativeTabDescription,
|
|
39
|
+
}],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** One line under the guide capsule: what picking it opens, in the host language. */
|
|
43
|
+
export function nativeTabDescription(locale = globalThis.navigator?.language ?? '') {
|
|
44
|
+
return /^zh(?:-|$)/i.test(locale) ? '行情图表与关键点位分析' : 'Market chart and key-level analysis';
|
|
45
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { NATIVE_TAB_ID, nativeTabDefinition } from "./native-sidebar-contract.js";
|
|
2
|
+
import { KLINE_TAB_ID } from "./sidebar-integration.js";
|
|
3
|
+
/**
|
|
4
|
+
* The native right-Sidebar registration, without React and without a host
|
|
5
|
+
* context: a pure function over the three host services, so the bootstrap
|
|
6
|
+
* policy (both stages, their teardown order, the deferred body seat) is
|
|
7
|
+
* testable with fakes.
|
|
8
|
+
*
|
|
9
|
+
* A DSH host that owns its right column publishes `sidebarRightTabs` (stage
|
|
10
|
+
* one — what the tab type is) and a keyed `sidebar.right.pane.tab` seat
|
|
11
|
+
* (stage two — the body), navigated by `sidebarRight`. A type without a body
|
|
12
|
+
* makes the host draw "nothing can view this", so the two stages are one unit
|
|
13
|
+
* and any failure backs the type out again.
|
|
14
|
+
*/
|
|
15
|
+
/** The seat a tab type's body registers under. */
|
|
16
|
+
export const BODY_SEAT = 'sidebar.right.pane.tab';
|
|
17
|
+
/**
|
|
18
|
+
* Register the chart as a tab type of the host's right column.
|
|
19
|
+
* @param host - the resolved host services.
|
|
20
|
+
* @param options - the body, its props, and the availability callback.
|
|
21
|
+
* @returns the registration, live until `dispose()`.
|
|
22
|
+
*/
|
|
23
|
+
export function registerNativeTab(host, options) {
|
|
24
|
+
const onChange = options.onChange ?? (() => { });
|
|
25
|
+
let typeDispose;
|
|
26
|
+
let seatDispose;
|
|
27
|
+
let bodyDispose;
|
|
28
|
+
let available = false;
|
|
29
|
+
let disposed = false;
|
|
30
|
+
/** One teardown step: a failing disposer must not block the rest of the rollback. */
|
|
31
|
+
const runSafely = (dispose, what) => {
|
|
32
|
+
if (dispose === undefined)
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
dispose();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`[dsh-kline] native tab ${what} teardown failed:`, error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const settle = (next) => {
|
|
42
|
+
if (available === next)
|
|
43
|
+
return;
|
|
44
|
+
available = next;
|
|
45
|
+
try {
|
|
46
|
+
onChange();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error('[dsh-kline] native tab change handler failed:', error);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const closeBody = () => {
|
|
53
|
+
const dispose = bodyDispose;
|
|
54
|
+
bodyDispose = undefined;
|
|
55
|
+
if (dispose !== undefined)
|
|
56
|
+
runSafely(dispose, 'body');
|
|
57
|
+
};
|
|
58
|
+
const release = () => {
|
|
59
|
+
if (disposed)
|
|
60
|
+
return;
|
|
61
|
+
disposed = true;
|
|
62
|
+
// The body goes first, so the type never outlives the thing that draws it.
|
|
63
|
+
closeBody();
|
|
64
|
+
runSafely(seatDispose, 'body seat');
|
|
65
|
+
seatDispose = undefined;
|
|
66
|
+
runSafely(typeDispose, 'type');
|
|
67
|
+
typeDispose = undefined;
|
|
68
|
+
settle(false);
|
|
69
|
+
};
|
|
70
|
+
const failed = () => ({ available: () => false, open: () => { }, dispose: () => { } });
|
|
71
|
+
try {
|
|
72
|
+
typeDispose = host.tabs.register(nativeTabDefinition());
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error('[dsh-kline] native right sidebar tab type registration failed:', error);
|
|
76
|
+
return failed();
|
|
77
|
+
}
|
|
78
|
+
// Stage two may settle after this call: a host declares the seat when its
|
|
79
|
+
// sidebar mounts, which can be later than the plugin boot. A failure inside
|
|
80
|
+
// the factory therefore has to roll the type back itself, once the
|
|
81
|
+
// injection attempt has settled (calling our own seat disposer from inside
|
|
82
|
+
// its factory would re-enter the registry).
|
|
83
|
+
const mountBody = () => {
|
|
84
|
+
if (disposed)
|
|
85
|
+
return () => { };
|
|
86
|
+
let dispose;
|
|
87
|
+
try {
|
|
88
|
+
dispose = host.slots.register({
|
|
89
|
+
name: BODY_SEAT,
|
|
90
|
+
key: NATIVE_TAB_ID,
|
|
91
|
+
...options.bodyProps === undefined ? {} : { inject: options.bodyProps },
|
|
92
|
+
}, options.body);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('[dsh-kline] native right sidebar tab body registration failed:', error);
|
|
96
|
+
queueMicrotask(release);
|
|
97
|
+
return () => { };
|
|
98
|
+
}
|
|
99
|
+
let closed = false;
|
|
100
|
+
bodyDispose = () => {
|
|
101
|
+
if (closed)
|
|
102
|
+
return;
|
|
103
|
+
closed = true;
|
|
104
|
+
runSafely(dispose, 'body');
|
|
105
|
+
};
|
|
106
|
+
settle(true);
|
|
107
|
+
return () => { closeBody(); settle(false); };
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
seatDispose = host.slots.inject(BODY_SEAT, mountBody);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error('[dsh-kline] native right sidebar body seat failed:', error);
|
|
114
|
+
release();
|
|
115
|
+
return failed();
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
available: () => available && !disposed,
|
|
119
|
+
open: () => {
|
|
120
|
+
if (!available || disposed)
|
|
121
|
+
return;
|
|
122
|
+
try {
|
|
123
|
+
host.navigation.openTab(KLINE_TAB_ID);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
// Opening is a navigation request: a host with no Session on screen
|
|
127
|
+
// refuses it, and the next analysis result or the guide entry retries.
|
|
128
|
+
console.warn('[dsh-kline] could not open the native chart tab:', error);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
dispose: release,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useSyncExternalStore } from 'react';
|
|
3
|
+
import { useChartReference } from './chart-session-resolver';
|
|
4
|
+
import { KlineTabContent } from './BetterSidebarTab';
|
|
5
|
+
import { currentConversationId } from './conversation';
|
|
6
|
+
import { InterfaceContext, readAutoOpen, readDisplayMode, resolveDisplayMode } from './mode-preferences';
|
|
7
|
+
import { registerNativeTab } from './native-sidebar-register';
|
|
8
|
+
/**
|
|
9
|
+
* The chart as a tab of the host's own right column.
|
|
10
|
+
*
|
|
11
|
+
* The registration policy lives in `native-sidebar-register.ts`; this module
|
|
12
|
+
* owns the two things that need React or the client context: the tab body and
|
|
13
|
+
* the auto-open trigger. The body is the same chart the Better Sidebar tab
|
|
14
|
+
* draws, mounted against the tab's own conversation.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* One tab body: the chart of the tab's session.
|
|
18
|
+
*
|
|
19
|
+
* A registered tab can still be opened while the user chose Classic mode, or
|
|
20
|
+
* remain mounted while the host changes Sessions. Only the active conversation
|
|
21
|
+
* in Tab mode may publish a chart; otherwise show a harmless explanation.
|
|
22
|
+
* When that conversation owns the tab, visibility is passed through so a
|
|
23
|
+
* collapsed column does not discard the chart's viewport.
|
|
24
|
+
*/
|
|
25
|
+
export function NativeKlineTabBody({ sessionId, sessions, useTabInfo }) {
|
|
26
|
+
const visible = useTabInfo().tab.visible;
|
|
27
|
+
const preference = useMemo(readDisplayMode, []);
|
|
28
|
+
const mode = resolveDisplayMode(preference, true);
|
|
29
|
+
const subscribe = useCallback((listener) => sessions.list.subscribe(listener), [sessions]);
|
|
30
|
+
const activeConversation = useSyncExternalStore(subscribe, () => currentConversationId(sessions.list.getSnapshot()));
|
|
31
|
+
return (_jsx(InterfaceContext.Provider, { value: { preference, mode, available: true }, children: _jsx("div", { "data-dsh-kline-tab": "", style: { width: '100%', height: '100%', minHeight: 0, overflow: 'hidden' }, children: mode !== 'better-sidebar'
|
|
32
|
+
? _jsx("div", { role: "status", style: { padding: 16 }, children: "\u5F53\u524D\u4F7F\u7528\u7ECF\u5178 K \u7EBF\u4FA7\u680F\uFF1B\u8BF7\u5728\u56FE\u8868\u53F3\u4E0A\u89D2\u300CUI\u300D\u5207\u6362\u4E3A Tab \u6A21\u5F0F\u3002 / Switch to Tab mode in the chart UI." })
|
|
33
|
+
: activeConversation !== sessionId
|
|
34
|
+
? _jsx("div", { role: "status", style: { padding: 16 }, children: "\u8BF7\u5148\u6253\u5F00\u6B64 Tab \u6240\u5C5E\u7684\u5BF9\u8BDD\u3002 / Open the conversation that owns this tab." })
|
|
35
|
+
: _jsx(KlineTabContent, { sessions: sessions, conversationId: sessionId, visible: visible }, sessionId) }) }));
|
|
36
|
+
}
|
|
37
|
+
/** Reveal the chart tab when an analysis result lands in the conversation on screen. */
|
|
38
|
+
function NativeAutoOpen({ sessions, conversationId, bridge }) {
|
|
39
|
+
const onNewChart = useCallback(() => {
|
|
40
|
+
if (readAutoOpen())
|
|
41
|
+
bridge.open();
|
|
42
|
+
}, [bridge]);
|
|
43
|
+
useChartReference(sessions, conversationId, onNewChart);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Auto-open lives in the tab's own session, exactly like the Better Sidebar
|
|
48
|
+
* path; the router decides whether this path is the active interface.
|
|
49
|
+
*/
|
|
50
|
+
export function NativeSidebarBridgeView({ bridge, sessions }) {
|
|
51
|
+
const subscribe = useCallback((listener) => sessions.list.subscribe(listener), [sessions]);
|
|
52
|
+
const list = useSyncExternalStore(subscribe, () => sessions.list.getSnapshot());
|
|
53
|
+
const activeConversation = currentConversationId(list);
|
|
54
|
+
return activeConversation
|
|
55
|
+
? _jsx(NativeAutoOpen, { bridge: bridge, sessions: sessions, conversationId: activeConversation }, activeConversation)
|
|
56
|
+
: null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Register the chart tab into the host's native right Sidebar.
|
|
60
|
+
*
|
|
61
|
+
* Every host service is optional: a host without `sidebarRightTabs`,
|
|
62
|
+
* `sidebarRight` or `slots` keeps `available() === false` and the plugin's
|
|
63
|
+
* existing interfaces untouched.
|
|
64
|
+
* @param ctx - the client context to register on.
|
|
65
|
+
* @param onChange - called whenever availability changes, so the router repaints.
|
|
66
|
+
* @returns the handle the router and the auto-open path share.
|
|
67
|
+
*/
|
|
68
|
+
export function registerNativeSidebar(ctx, onChange) {
|
|
69
|
+
let registration;
|
|
70
|
+
const bridge = {
|
|
71
|
+
available: () => registration?.available() ?? false,
|
|
72
|
+
open: () => registration?.open(),
|
|
73
|
+
};
|
|
74
|
+
ctx.inject(['sidebarRightTabs', 'sidebarRight', 'slots'], scope => {
|
|
75
|
+
scope.effect(() => {
|
|
76
|
+
const tabs = scope.get('sidebarRightTabs');
|
|
77
|
+
const navigation = scope.get('sidebarRight');
|
|
78
|
+
const slots = scope.get('slots');
|
|
79
|
+
if (tabs === undefined || navigation === undefined || slots === undefined)
|
|
80
|
+
return () => { };
|
|
81
|
+
const next = registerNativeTab({ tabs, navigation, slots }, {
|
|
82
|
+
body: NativeKlineTabBody,
|
|
83
|
+
bodyProps: (sessionId) => ({ sessions: ctx.sessions, sessionId }),
|
|
84
|
+
onChange,
|
|
85
|
+
});
|
|
86
|
+
registration = next;
|
|
87
|
+
onChange();
|
|
88
|
+
return () => {
|
|
89
|
+
registration = undefined;
|
|
90
|
+
next.dispose();
|
|
91
|
+
onChange();
|
|
92
|
+
};
|
|
93
|
+
}, 'dsh-kline: native right sidebar tab');
|
|
94
|
+
});
|
|
95
|
+
return bridge;
|
|
96
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const KLINE_TAB_ID = 'ftshare-kline:chart';
|
|
2
|
+
export const KLINE_TAB_TITLE_ZH = '非凸 K 线助手';
|
|
3
|
+
export const KLINE_TAB_TITLE_EN = 'FtAI K-Line';
|
|
4
|
+
// The tab belongs to the host interface. Keep its product label separate from
|
|
5
|
+
// the internal package id, and follow the host/browser language.
|
|
6
|
+
export function klineTabTitle(locale = globalThis.navigator?.language ?? '') {
|
|
7
|
+
return /^zh(?:-|$)/i.test(locale) ? KLINE_TAB_TITLE_ZH : KLINE_TAB_TITLE_EN;
|
|
8
|
+
}
|
|
9
|
+
export function migrateKlineTabTitle(service, tab, sessionId) {
|
|
10
|
+
if (tab.type !== KLINE_TAB_ID || !['K线分析 / K-line', 'K线分析', '非凸K线助手 / dsh_kline', KLINE_TAB_TITLE_ZH, KLINE_TAB_TITLE_EN].includes(tab.title ?? '')
|
|
11
|
+
|| !service.features?.includes('updateTab') || !service.features?.includes('stateSubscription')
|
|
12
|
+
|| typeof service.updateTab !== 'function' || typeof service.getSnapshot !== 'function')
|
|
13
|
+
return;
|
|
14
|
+
try {
|
|
15
|
+
// updateTab is current-session-only in the public API. Never mutate a
|
|
16
|
+
// foreign floating tab or a user-customized title while migrating labels.
|
|
17
|
+
if (sessionId && service.getSnapshot()?.sessionId === sessionId)
|
|
18
|
+
service.updateTab(tab.id, { title: klineTabTitle() });
|
|
19
|
+
}
|
|
20
|
+
catch { /* Older/disposed integrations keep their saved title harmlessly. */ }
|
|
21
|
+
}
|
|
22
|
+
export function isSidebarUsable(service) {
|
|
23
|
+
// Some DSH Desktop builds expose the stable public methods through a
|
|
24
|
+
// compatibility proxy but omit (or stale-cache) Better Sidebar's optional
|
|
25
|
+
// feature list. The tab itself can still be registered and opened, so use
|
|
26
|
+
// the callable public contract as the availability test. Optional helpers
|
|
27
|
+
// below remain individually feature-gated.
|
|
28
|
+
return Boolean(service && typeof service.registerTab === 'function' && typeof service.openTab === 'function');
|
|
29
|
+
}
|
|
30
|
+
// The framework persists open tabs across reloads. In Classic mode remove only
|
|
31
|
+
// our old tab shells, otherwise it displays a misleading "plugin unavailable"
|
|
32
|
+
// placeholder. Chart/workspace storage is separate and is never deleted here.
|
|
33
|
+
export function cleanClassicTabs(service) {
|
|
34
|
+
if (!service.features?.includes('stateSubscription') || typeof service.closeTab !== 'function'
|
|
35
|
+
|| typeof service.getSnapshot !== 'function' || typeof service.subscribeState !== 'function')
|
|
36
|
+
return () => { };
|
|
37
|
+
let stopped = false, pending = false;
|
|
38
|
+
const schedule = () => {
|
|
39
|
+
if (stopped || pending)
|
|
40
|
+
return;
|
|
41
|
+
pending = true;
|
|
42
|
+
queueMicrotask(() => {
|
|
43
|
+
pending = false;
|
|
44
|
+
if (stopped)
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const snapshot = service.getSnapshot();
|
|
48
|
+
const { sessionId, state } = snapshot ?? {};
|
|
49
|
+
if (typeof sessionId !== 'string' || !sessionId || !state)
|
|
50
|
+
return;
|
|
51
|
+
const ids = new Set();
|
|
52
|
+
const record = (value) => typeof value === 'object' && value !== null;
|
|
53
|
+
const collect = (tab) => {
|
|
54
|
+
if (record(tab) && tab.type === KLINE_TAB_ID && typeof tab.id === 'string' && tab.id)
|
|
55
|
+
ids.add(tab.id);
|
|
56
|
+
};
|
|
57
|
+
// Layouts belong to another plugin and may contain older/incomplete
|
|
58
|
+
// nodes. Iterate defensively, including protection against cycles.
|
|
59
|
+
// Since Better Sidebar 0.19, DSH owns the right-sidebar layout.
|
|
60
|
+
// Our registered tab can only be in Better Sidebar's workbench.
|
|
61
|
+
const pendingNodes = [state.bottomSplits];
|
|
62
|
+
const seen = new Set();
|
|
63
|
+
while (pendingNodes.length) {
|
|
64
|
+
const node = pendingNodes.pop();
|
|
65
|
+
if (!record(node) || seen.has(node))
|
|
66
|
+
continue;
|
|
67
|
+
seen.add(node);
|
|
68
|
+
if (node.kind === 'split' && Array.isArray(node.children))
|
|
69
|
+
pendingNodes.push(...[...node.children].reverse());
|
|
70
|
+
else if (Array.isArray(node.tabs))
|
|
71
|
+
node.tabs.forEach(collect);
|
|
72
|
+
}
|
|
73
|
+
for (const id of ids) {
|
|
74
|
+
try {
|
|
75
|
+
service.closeTab(id, { sessionId });
|
|
76
|
+
}
|
|
77
|
+
catch { /* A stale tab must not block the remaining cleanup. */ }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch { /* Optional layout cleanup must never break the classic shell. */ }
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
let unsubscribe;
|
|
84
|
+
try {
|
|
85
|
+
unsubscribe = service.subscribeState(schedule);
|
|
86
|
+
}
|
|
87
|
+
catch { /* Still attempt one initial cleanup. */ }
|
|
88
|
+
schedule();
|
|
89
|
+
return () => { stopped = true; try {
|
|
90
|
+
unsubscribe?.();
|
|
91
|
+
}
|
|
92
|
+
catch { /* Service may already have been disposed. */ } };
|
|
93
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { UI_SEEN_KEY } from "./mode-preferences.js";
|
|
2
|
+
export const ONBOARDING_KEY = 'dsh-kline:onboarding-version:v2';
|
|
3
|
+
let existingUser;
|
|
4
|
+
export function hasPreviousUsage(storage) {
|
|
5
|
+
try {
|
|
6
|
+
if (storage.getItem('dsh_kline_welcome_seen_v1') === '1')
|
|
7
|
+
return true;
|
|
8
|
+
for (let i = 0; i < storage.length; i++) {
|
|
9
|
+
const key = storage.key(i) || '';
|
|
10
|
+
if (key.startsWith('dsh-kline:conversation:') || key === 'dsh-kline.workspace.v1')
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// Capture before the launcher writes any new conversation data.
|
|
18
|
+
export function captureOnboarding(storage = globalThis.localStorage) {
|
|
19
|
+
existingUser ??= hasPreviousUsage(storage);
|
|
20
|
+
}
|
|
21
|
+
export function onboardingKind(storage = globalThis.localStorage) {
|
|
22
|
+
captureOnboarding(storage);
|
|
23
|
+
return classifyOnboarding(storage, existingUser === true);
|
|
24
|
+
}
|
|
25
|
+
export function classifyOnboarding(storage, previousUsage) {
|
|
26
|
+
try {
|
|
27
|
+
if (storage.getItem(UI_SEEN_KEY))
|
|
28
|
+
return 'none';
|
|
29
|
+
return previousUsage ? 'upgrade' : 'first';
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return 'none';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function acknowledgeOnboarding(storage = globalThis.localStorage) {
|
|
36
|
+
try {
|
|
37
|
+
storage.setItem(UI_SEEN_KEY, '1');
|
|
38
|
+
storage.setItem(ONBOARDING_KEY, '0.2.0');
|
|
39
|
+
storage.setItem('dsh_kline_welcome_seen_v1', '1');
|
|
40
|
+
}
|
|
41
|
+
catch { }
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The update channel offers stable releases only. A stable release of the same
|
|
2
|
+
// base version must still be offered to users running its release candidate.
|
|
3
|
+
export function isNewerStableVersion(candidate, current) {
|
|
4
|
+
const next = /^(\d+)\.(\d+)\.(\d+)$/.exec(candidate);
|
|
5
|
+
const installed = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(current);
|
|
6
|
+
if (!next || !installed)
|
|
7
|
+
return false;
|
|
8
|
+
for (let index = 1; index <= 3; index++) {
|
|
9
|
+
const difference = Number(next[index]) - Number(installed[index]);
|
|
10
|
+
if (difference)
|
|
11
|
+
return difference > 0;
|
|
12
|
+
}
|
|
13
|
+
return Boolean(installed[4]);
|
|
14
|
+
}
|