@dsh-ft/dsh-fft-paper-trading 0.7.0 → 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.
- package/lib/client.js +9 -1
- package/package.json +2 -5
- package/src/client/index.js +8 -0
- package/node_modules/@ftshare-lab/dsh-kline/CHANGELOG.md +0 -564
- package/node_modules/@ftshare-lab/dsh-kline/LICENSE +0 -21
- package/node_modules/@ftshare-lab/dsh-kline/PROVENANCE.md +0 -13
- package/node_modules/@ftshare-lab/dsh-kline/README.en.md +0 -265
- package/node_modules/@ftshare-lab/dsh-kline/README.md +0 -281
- package/node_modules/@ftshare-lab/dsh-kline/chart_service.py +0 -686
- package/node_modules/@ftshare-lab/dsh-kline/config/basic-symbols.json +0 -570
- package/node_modules/@ftshare-lab/dsh-kline/config/dsh-kline.patch.yml +0 -4
- package/node_modules/@ftshare-lab/dsh-kline/config/dsh-tool-catalog.json +0 -3783
- package/node_modules/@ftshare-lab/dsh-kline/cordis.patch.yml +0 -33
- package/node_modules/@ftshare-lab/dsh-kline/core/__init__.py +0 -0
- package/node_modules/@ftshare-lab/dsh-kline/core/adjustment.py +0 -16
- package/node_modules/@ftshare-lab/dsh-kline/core/calc.py +0 -683
- package/node_modules/@ftshare-lab/dsh-kline/core/rows.py +0 -228
- package/node_modules/@ftshare-lab/dsh-kline/core/ta_engine.py +0 -99
- package/node_modules/@ftshare-lab/dsh-kline/lib/candle-sequence.js +0 -15
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-adjustment.js +0 -7
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-annotations.js +0 -33
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-applications.js +0 -171
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-context.js +0 -164
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-observation.js +0 -241
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-service-status.js +0 -82
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-source-status.js +0 -39
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-sources.js +0 -349
- package/node_modules/@ftshare-lab/dsh-kline/lib/client.js +0 -15445
- package/node_modules/@ftshare-lab/dsh-kline/lib/drawing-feedback.js +0 -252
- package/node_modules/@ftshare-lab/dsh-kline/lib/fibonacci.js +0 -18
- package/node_modules/@ftshare-lab/dsh-kline/lib/ftshare-settings-bridge.js +0 -159
- package/node_modules/@ftshare-lab/dsh-kline/lib/index.js +0 -279
- package/node_modules/@ftshare-lab/dsh-kline/lib/labeled-polyline.js +0 -17
- package/node_modules/@ftshare-lab/dsh-kline/lib/price-bands.js +0 -55
- package/node_modules/@ftshare-lab/dsh-kline/lib/price-series.js +0 -47
- package/node_modules/@ftshare-lab/dsh-kline/lib/price-sticks.js +0 -32
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/candle-sequence.d.ts +0 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-adjustment.d.ts +0 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-annotations.d.ts +0 -4
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-applications.d.ts +0 -26
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-context.d.ts +0 -14
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-observation.d.ts +0 -8
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-service-status.d.ts +0 -22
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-source-status.d.ts +0 -47
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-sources.d.ts +0 -25
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/BetterSidebarTab.d.ts +0 -12
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/ClassicShell.d.ts +0 -4
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/KlineContent.d.ts +0 -37
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/PaperKlinePanel.d.ts +0 -15
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/canvas-panel.d.ts +0 -33
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-apply.d.ts +0 -13
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-context.d.ts +0 -23
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-session-resolver.d.ts +0 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/client-context.d.ts +0 -14
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/conversation.d.ts +0 -39
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/default-tab.d.ts +0 -3
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/embed.d.ts +0 -37
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/generated-view.d.ts +0 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/horizontal-lines.d.ts +0 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/host-services.d.ts +0 -55
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/index.d.ts +0 -4
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/mode-preferences.d.ts +0 -13
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-contract.d.ts +0 -52
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-register.d.ts +0 -46
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-services.d.ts +0 -45
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar.d.ts +0 -47
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/sidebar-integration.d.ts +0 -12
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/ui-onboarding.d.ts +0 -13
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/version.d.ts +0 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/drawing-feedback.d.ts +0 -5
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/fibonacci.d.ts +0 -5
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/ftshare-settings-bridge.d.ts +0 -50
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/index.d.ts +0 -26
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/labeled-polyline.d.ts +0 -11
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-bands.d.ts +0 -3
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-series.d.ts +0 -5
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-sticks.d.ts +0 -3
- package/node_modules/@ftshare-lab/dsh-kline/package.json +0 -136
- package/node_modules/@ftshare-lab/dsh-kline/requirements.txt +0 -6
- package/node_modules/@ftshare-lab/dsh-kline/scripts/bootstrap.sh +0 -5
- package/node_modules/@ftshare-lab/dsh-kline/scripts/dsh-bootstrap.mjs +0 -179
- package/node_modules/@ftshare-lab/dsh-kline/scripts/dsh-mcp-plugin.mjs +0 -27
- package/node_modules/@ftshare-lab/dsh-kline/scripts/run-dsh-kline.mjs +0 -655
- package/node_modules/@ftshare-lab/dsh-kline/scripts/run-dsh-kline.sh +0 -5
- package/node_modules/@ftshare-lab/dsh-kline/server.py +0 -1734
- package/node_modules/@ftshare-lab/dsh-kline/tools/__init__.py +0 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/annotations.py +0 -119
- package/node_modules/@ftshare-lab/dsh-kline/tools/baostock_source.py +0 -176
- package/node_modules/@ftshare-lab/dsh-kline/tools/calc.py +0 -39
- package/node_modules/@ftshare-lab/dsh-kline/tools/channel_candidates.py +0 -260
- package/node_modules/@ftshare-lab/dsh-kline/tools/channel_preview.py +0 -82
- package/node_modules/@ftshare-lab/dsh-kline/tools/channels.py +0 -104
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_applications.py +0 -204
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_context.py +0 -186
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_edits.py +0 -345
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_functions.py +0 -466
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_indicators.py +0 -63
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_measurements.py +0 -84
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_source_status.py +0 -32
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_sources.py +0 -31
- package/node_modules/@ftshare-lab/dsh-kline/tools/draw.py +0 -394
- package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_feedback.py +0 -45
- package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_interaction.py +0 -117
- package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_verification.py +0 -141
- package/node_modules/@ftshare-lab/dsh-kline/tools/fetch.py +0 -4681
- package/node_modules/@ftshare-lab/dsh-kline/tools/fibonacci.py +0 -83
- package/node_modules/@ftshare-lab/dsh-kline/tools/foreign_daily.py +0 -185
- package/node_modules/@ftshare-lab/dsh-kline/tools/free_sources.py +0 -483
- package/node_modules/@ftshare-lab/dsh-kline/tools/lines.py +0 -91
- package/node_modules/@ftshare-lab/dsh-kline/tools/pivots.py +0 -60
- package/node_modules/@ftshare-lab/dsh-kline/tools/polylines.py +0 -125
- package/node_modules/@ftshare-lab/dsh-kline/tools/price_bands.py +0 -165
- package/node_modules/@ftshare-lab/dsh-kline/tools/price_series.py +0 -162
- package/node_modules/@ftshare-lab/dsh-kline/tools/price_sticks.py +0 -114
- package/node_modules/@ftshare-lab/dsh-kline/tools/range_candidates.py +0 -170
- package/node_modules/@ftshare-lab/dsh-kline/tools/rectangles.py +0 -76
- package/node_modules/@ftshare-lab/dsh-kline/tools/regression_channels.py +0 -87
- package/node_modules/@ftshare-lab/dsh-kline/tools/ta_functions.py +0 -228
- package/node_modules/@ftshare-lab/dsh-kline/tools/trend_lines.py +0 -106
- package/node_modules/@ftshare-lab/dsh-kline/tools/watchlist.py +0 -149
- package/node_modules/@ftshare-lab/dsh-kline/view/ft-logo.jpg +0 -0
- package/node_modules/@ftshare-lab/dsh-kline/view/vendor/klinecharts.min.js +0 -7
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"""Allowlisted diagnostic metadata, never edit authority or a replacement for guards."""
|
|
2
|
-
SOURCE_STATUS_REASONS = {
|
|
3
|
-
"not_checked": ("not_checked", "retry_observation"),
|
|
4
|
-
"chart_not_ready": ("not_checked", "wait_for_chart"),
|
|
5
|
-
"client_unsupported": ("blocked", "reload_client"),
|
|
6
|
-
"view_inactive": ("blocked", "activate_view"),
|
|
7
|
-
"ambiguous_views": ("blocked", "keep_one_active_view"),
|
|
8
|
-
"source_missing": ("blocked", "reopen_chart"),
|
|
9
|
-
"source_unavailable": ("blocked", "reopen_chart"),
|
|
10
|
-
"source_owner_mismatch": ("blocked", "reopen_chart"),
|
|
11
|
-
"source_unconfirmed": ("blocked", "check_drawing_status"),
|
|
12
|
-
"source_metadata_unknown": ("blocked", "check_chart_settings"),
|
|
13
|
-
"source_limit_exceeded": ("blocked", "reduce_range"),
|
|
14
|
-
"drawing_pending": ("checking", "check_drawing_status"),
|
|
15
|
-
"drawing_outcome_unknown": ("blocked", "check_drawing_status"),
|
|
16
|
-
"source_snapshot_mismatch": ("blocked", "retry_observation"),
|
|
17
|
-
"source_payload_invalid": ("blocked", "retry_observation"),
|
|
18
|
-
"source_handoff_pending": ("checking", "wait_for_report"),
|
|
19
|
-
"source_handoff_rejected": ("blocked", "retry_observation"),
|
|
20
|
-
"source_matches_view": ("aligned", "continue_guarded_workflow"),
|
|
21
|
-
"context_transport_unavailable": ("blocked", "retry_observation"),
|
|
22
|
-
"source_handoff_unavailable": ("blocked", "retry_observation"),
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def sanitize_source_status(raw):
|
|
27
|
-
reason = raw.get("reason") if isinstance(raw, dict) and type(raw.get("schema_version")) is int and raw["schema_version"] == 1 else None
|
|
28
|
-
if not isinstance(reason, str) or reason not in SOURCE_STATUS_REASONS:
|
|
29
|
-
reason = "not_checked"
|
|
30
|
-
phase, action = SOURCE_STATUS_REASONS[reason]
|
|
31
|
-
return {"schema_version": 1, "scope": "source_handoff", "phase": phase, "reason": reason,
|
|
32
|
-
"next_action": action, "edit_authorized": False}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""Validate browser-confirmed current-view source identity; never fetch or bind here."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
import re
|
|
6
|
-
|
|
7
|
-
import chart_service
|
|
8
|
-
from tools.lines import LineError
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def require_confirmed_view_source(payload: dict, context: dict, token: str) -> None:
|
|
12
|
-
guard = payload.get("view_source_guard")
|
|
13
|
-
if not guard:
|
|
14
|
-
return
|
|
15
|
-
try:
|
|
16
|
-
if (not isinstance(guard, dict) or guard.get("protocol") != "browser-source-v1"
|
|
17
|
-
or guard.get("chart_session") != token or guard.get("conversation_id") != context.get("conversation_id")
|
|
18
|
-
or not isinstance(guard.get("context_ref"), str)
|
|
19
|
-
or not re.fullmatch(r"[A-Za-z0-9_-]{32}", guard["context_ref"])
|
|
20
|
-
or not isinstance(token, str) or not re.fullmatch(r"[A-Za-z0-9_-]{32}", token)):
|
|
21
|
-
raise ValueError("owner")
|
|
22
|
-
path = chart_service.RUNTIME_DIR / "sources" / str(chart_service.HOST_PROCESS_ID) / guard["context_ref"] / (token + ".json")
|
|
23
|
-
if path.stat().st_size > chart_service.MAX_REQUEST_BYTES:
|
|
24
|
-
raise ValueError("size")
|
|
25
|
-
proof = json.loads(path.read_text(encoding="utf-8"))
|
|
26
|
-
if (proof.get("status") != "confirmed" or proof.get("host_process_id") != chart_service.HOST_PROCESS_ID
|
|
27
|
-
or proof.get("chart_session") != token or proof.get("context_ref") != guard["context_ref"]
|
|
28
|
-
or proof.get("conversation_id") != guard["conversation_id"] or proof.get("view_id") != guard.get("view_id")):
|
|
29
|
-
raise ValueError("proof")
|
|
30
|
-
except (OSError, ValueError, TypeError, KeyError, AttributeError):
|
|
31
|
-
raise LineError("chart_source_not_confirmed", "当前图来源尚未由所属网页核对绑定;请等待重新上报并读取新上下文,不重取行情或使用旧图绕过。") from None
|
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
"""Build standalone dsh_kline chart payloads and indicator commands.
|
|
2
|
-
|
|
3
|
-
All indicator series come from core.calc (same module as calc_metrics).
|
|
4
|
-
Public times are unix **seconds**; view multiplies by 1000 for klinecharts.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
from typing import Any
|
|
10
|
-
from urllib.parse import urlparse
|
|
11
|
-
|
|
12
|
-
from core.calc import (
|
|
13
|
-
DEFAULT_ATR_PERIOD,
|
|
14
|
-
DEFAULT_BOLL_PERIOD,
|
|
15
|
-
DEFAULT_BOLL_STD,
|
|
16
|
-
DEFAULT_KDJ,
|
|
17
|
-
DEFAULT_MACD,
|
|
18
|
-
DEFAULT_MA_PERIODS,
|
|
19
|
-
DEFAULT_RSI_PERIOD,
|
|
20
|
-
DEFAULT_VOLUME_MA,
|
|
21
|
-
series_atr,
|
|
22
|
-
series_boll,
|
|
23
|
-
series_kdj,
|
|
24
|
-
series_ma,
|
|
25
|
-
series_macd,
|
|
26
|
-
series_rsi,
|
|
27
|
-
series_vwap,
|
|
28
|
-
series_vol_ma,
|
|
29
|
-
)
|
|
30
|
-
from core.rows import validate_rows
|
|
31
|
-
from core.ta_engine import ENGINE_VERSION, NATIVE_VERSION
|
|
32
|
-
|
|
33
|
-
SUPPORTED_INDICATORS = ("ma", "vwap", "vol", "macd", "kdj", "boll", "rsi", "atr")
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def _safe_https_url(value: Any) -> str | None:
|
|
37
|
-
"""Accept attribution URLs only when they are absolute HTTPS URLs."""
|
|
38
|
-
candidate = str(value or "").strip()
|
|
39
|
-
if not candidate or len(candidate) > 500:
|
|
40
|
-
return None
|
|
41
|
-
parsed = urlparse(candidate)
|
|
42
|
-
return candidate if parsed.scheme == "https" and parsed.netloc else None
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _map_to_str_keys(m: dict[int, float]) -> dict[str, float]:
|
|
46
|
-
"""JSON object keys must be strings; values stay numbers. Keys are seconds."""
|
|
47
|
-
return {str(int(k)): float(v) for k, v in m.items()}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _normalize_marks(marks: Any) -> list[dict[str, Any]]:
|
|
51
|
-
out: list[dict[str, Any]] = []
|
|
52
|
-
if not isinstance(marks, list):
|
|
53
|
-
return out
|
|
54
|
-
for index, m in enumerate(marks):
|
|
55
|
-
if not isinstance(m, dict):
|
|
56
|
-
continue
|
|
57
|
-
try:
|
|
58
|
-
t = int(m.get("time") or m.get("timestamp") or 0)
|
|
59
|
-
except Exception:
|
|
60
|
-
continue
|
|
61
|
-
if t > 10_000_000_000:
|
|
62
|
-
t = int(t / 1000)
|
|
63
|
-
if t <= 0:
|
|
64
|
-
continue
|
|
65
|
-
price = m.get("price")
|
|
66
|
-
try:
|
|
67
|
-
price_f = float(price) if price is not None else None
|
|
68
|
-
except Exception:
|
|
69
|
-
price_f = None
|
|
70
|
-
out.append(
|
|
71
|
-
{
|
|
72
|
-
"id": str(m.get("id") or f"marker:{t}:{index}")[:128],
|
|
73
|
-
"time": t,
|
|
74
|
-
"price": price_f,
|
|
75
|
-
"text": str(m.get("text") or m.get("label") or "标注")[:48],
|
|
76
|
-
"color": str(m.get("color") or "warning"),
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
return out
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _normalize_lines(lines: Any) -> list[dict[str, Any]]:
|
|
83
|
-
out: list[dict[str, Any]] = []
|
|
84
|
-
if not isinstance(lines, list):
|
|
85
|
-
return out
|
|
86
|
-
for index, ln in enumerate(lines):
|
|
87
|
-
if not isinstance(ln, dict):
|
|
88
|
-
continue
|
|
89
|
-
fr = ln.get("from") or {}
|
|
90
|
-
to = ln.get("to") or {}
|
|
91
|
-
try:
|
|
92
|
-
t0 = int(fr.get("time") or 0)
|
|
93
|
-
t1 = int(to.get("time") or 0)
|
|
94
|
-
p0 = float(fr.get("price"))
|
|
95
|
-
p1 = float(to.get("price"))
|
|
96
|
-
except Exception:
|
|
97
|
-
continue
|
|
98
|
-
if t0 > 10_000_000_000:
|
|
99
|
-
t0 = int(t0 / 1000)
|
|
100
|
-
if t1 > 10_000_000_000:
|
|
101
|
-
t1 = int(t1 / 1000)
|
|
102
|
-
if t0 <= 0 or t1 <= 0 or t0 == t1:
|
|
103
|
-
continue
|
|
104
|
-
out.append(
|
|
105
|
-
{
|
|
106
|
-
"id": str(ln.get("id") or f"line:{t0}:{t1}:{index}")[:128],
|
|
107
|
-
"from": {"time": t0, "price": p0},
|
|
108
|
-
"to": {"time": t1, "price": p1},
|
|
109
|
-
"label": str(ln.get("label") or ln.get("text") or ""),
|
|
110
|
-
"color": str(ln.get("color") or "danger"),
|
|
111
|
-
}
|
|
112
|
-
)
|
|
113
|
-
return out
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def _normalize_comparisons(comparisons: Any) -> list[dict[str, Any]]:
|
|
117
|
-
"""Validate optional benchmark series for direct, one-shot chart rendering."""
|
|
118
|
-
if not isinstance(comparisons, list):
|
|
119
|
-
return []
|
|
120
|
-
normalized: list[dict[str, Any]] = []
|
|
121
|
-
for item in comparisons[:3]:
|
|
122
|
-
if not isinstance(item, dict):
|
|
123
|
-
continue
|
|
124
|
-
symbol = str(item.get("symbol") or "").strip()
|
|
125
|
-
rows = item.get("rows")
|
|
126
|
-
if not symbol or not isinstance(rows, list):
|
|
127
|
-
continue
|
|
128
|
-
try:
|
|
129
|
-
normalized_rows = validate_rows(rows, min_len=2)
|
|
130
|
-
except (TypeError, ValueError):
|
|
131
|
-
continue
|
|
132
|
-
normalized.append(
|
|
133
|
-
{
|
|
134
|
-
"symbol": symbol[:48],
|
|
135
|
-
"name": str(item.get("name") or symbol)[:120],
|
|
136
|
-
"rows": normalized_rows,
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
return normalized
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def build_chart_commands(
|
|
143
|
-
rows: list[dict[str, Any]],
|
|
144
|
-
*,
|
|
145
|
-
indicators: list[str] | None = None,
|
|
146
|
-
ma_periods: list[int] | None = None,
|
|
147
|
-
marks: Any = None,
|
|
148
|
-
lines: Any = None,
|
|
149
|
-
boll_period: int = DEFAULT_BOLL_PERIOD,
|
|
150
|
-
boll_std: float = DEFAULT_BOLL_STD,
|
|
151
|
-
volume_ma: int = DEFAULT_VOLUME_MA,
|
|
152
|
-
rsi_period: int = DEFAULT_RSI_PERIOD,
|
|
153
|
-
atr_period: int = DEFAULT_ATR_PERIOD,
|
|
154
|
-
) -> list[dict[str, Any]]:
|
|
155
|
-
"""Build chartCommands. Indicator series keys are **seconds** (view ×1000)."""
|
|
156
|
-
requested_indicators = ["ma", "vol"] if indicators is None else indicators
|
|
157
|
-
inds = [str(x).lower() for x in requested_indicators if str(x).lower() in SUPPORTED_INDICATORS]
|
|
158
|
-
periods = list(ma_periods or DEFAULT_MA_PERIODS)
|
|
159
|
-
cmds: list[dict[str, Any]] = []
|
|
160
|
-
|
|
161
|
-
if rows:
|
|
162
|
-
cmds.append(
|
|
163
|
-
{
|
|
164
|
-
"type": "SET_CANDLES",
|
|
165
|
-
"rows": rows, # view needs candles; host LLM content should still not dump them
|
|
166
|
-
}
|
|
167
|
-
)
|
|
168
|
-
cmds.append(
|
|
169
|
-
{
|
|
170
|
-
"type": "SET_RANGE",
|
|
171
|
-
"start": int(rows[0]["time"]),
|
|
172
|
-
"end": int(rows[-1]["time"]),
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
# MA series
|
|
177
|
-
if "ma" in inds:
|
|
178
|
-
ma_maps = series_ma(rows, periods)
|
|
179
|
-
data = {name: _map_to_str_keys(m) for name, m in ma_maps.items()}
|
|
180
|
-
cmds.append(
|
|
181
|
-
{
|
|
182
|
-
"type": "SET_INDICATOR_SERIES",
|
|
183
|
-
"name": "ma",
|
|
184
|
-
"pane": "candle",
|
|
185
|
-
"params": {"periods": periods},
|
|
186
|
-
"data": data, # keys = seconds (stringified)
|
|
187
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
188
|
-
}
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
if "vwap" in inds:
|
|
192
|
-
cmds.append(
|
|
193
|
-
{
|
|
194
|
-
"type": "SET_INDICATOR_SERIES",
|
|
195
|
-
"name": "vwap",
|
|
196
|
-
"pane": "candle",
|
|
197
|
-
"params": {"anchor": "loaded_context"},
|
|
198
|
-
"data": {"vwap": _map_to_str_keys(series_vwap(rows))},
|
|
199
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
200
|
-
}
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
if "vol" in inds:
|
|
204
|
-
vol_map = series_vol_ma(rows, volume_ma)
|
|
205
|
-
# raw volume is already on candles; only pass MA for overlay reference if needed
|
|
206
|
-
cmds.append(
|
|
207
|
-
{
|
|
208
|
-
"type": "SET_INDICATOR_SERIES",
|
|
209
|
-
"name": "vol",
|
|
210
|
-
"pane": "vol",
|
|
211
|
-
"params": {"ma_period": int(volume_ma)},
|
|
212
|
-
"data": {"vol_ma": _map_to_str_keys(vol_map)},
|
|
213
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
214
|
-
}
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
if "macd" in inds:
|
|
218
|
-
macd = series_macd(rows, *DEFAULT_MACD)
|
|
219
|
-
cmds.append(
|
|
220
|
-
{
|
|
221
|
-
"type": "SET_INDICATOR_SERIES",
|
|
222
|
-
"name": "macd",
|
|
223
|
-
"pane": "macd",
|
|
224
|
-
"params": {"fast": DEFAULT_MACD[0], "slow": DEFAULT_MACD[1], "signal": DEFAULT_MACD[2]},
|
|
225
|
-
"data": {
|
|
226
|
-
"dif": _map_to_str_keys(macd["dif"]),
|
|
227
|
-
"dea": _map_to_str_keys(macd["dea"]),
|
|
228
|
-
"hist": _map_to_str_keys(macd["hist"]),
|
|
229
|
-
},
|
|
230
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
231
|
-
}
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
if "kdj" in inds:
|
|
235
|
-
kdj = series_kdj(rows, *DEFAULT_KDJ)
|
|
236
|
-
cmds.append(
|
|
237
|
-
{
|
|
238
|
-
"type": "SET_INDICATOR_SERIES",
|
|
239
|
-
"name": "kdj",
|
|
240
|
-
"pane": "kdj",
|
|
241
|
-
"params": {"n": DEFAULT_KDJ[0], "m1": DEFAULT_KDJ[1], "m2": DEFAULT_KDJ[2]},
|
|
242
|
-
"data": {
|
|
243
|
-
"k": _map_to_str_keys(kdj["k"]),
|
|
244
|
-
"d": _map_to_str_keys(kdj["d"]),
|
|
245
|
-
"j": _map_to_str_keys(kdj["j"]),
|
|
246
|
-
},
|
|
247
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
248
|
-
}
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
if "boll" in inds:
|
|
252
|
-
boll = series_boll(rows, period=boll_period, std_mult=boll_std)
|
|
253
|
-
cmds.append(
|
|
254
|
-
{
|
|
255
|
-
"type": "SET_INDICATOR_SERIES",
|
|
256
|
-
"name": "boll",
|
|
257
|
-
"pane": "candle",
|
|
258
|
-
"params": {"period": int(boll_period), "std_mult": float(boll_std)},
|
|
259
|
-
"data": {
|
|
260
|
-
"mid": _map_to_str_keys(boll["mid"]),
|
|
261
|
-
"upper": _map_to_str_keys(boll["upper"]),
|
|
262
|
-
"lower": _map_to_str_keys(boll["lower"]),
|
|
263
|
-
},
|
|
264
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
265
|
-
}
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
if "rsi" in inds:
|
|
269
|
-
rsi = series_rsi(rows, period=rsi_period)
|
|
270
|
-
cmds.append(
|
|
271
|
-
{
|
|
272
|
-
"type": "SET_INDICATOR_SERIES",
|
|
273
|
-
"name": "rsi",
|
|
274
|
-
"pane": "rsi",
|
|
275
|
-
"params": {"period": int(rsi_period)},
|
|
276
|
-
"data": {"rsi": _map_to_str_keys(rsi)},
|
|
277
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
278
|
-
}
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
if "atr" in inds:
|
|
282
|
-
atr = series_atr(rows, period=atr_period)
|
|
283
|
-
cmds.append(
|
|
284
|
-
{
|
|
285
|
-
"type": "SET_INDICATOR_SERIES",
|
|
286
|
-
"name": "atr",
|
|
287
|
-
"pane": "atr",
|
|
288
|
-
"params": {"period": int(atr_period)},
|
|
289
|
-
"data": {"atr": _map_to_str_keys(atr)},
|
|
290
|
-
"note": "data keys are unix seconds; view multiplies by 1000 for klinecharts",
|
|
291
|
-
}
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
for ln in _normalize_lines(lines):
|
|
295
|
-
cmds.append(
|
|
296
|
-
{
|
|
297
|
-
"type": "DRAW_TREND_LINE",
|
|
298
|
-
"id": ln["id"],
|
|
299
|
-
"from": ln["from"],
|
|
300
|
-
"to": ln["to"],
|
|
301
|
-
"label": ln["label"],
|
|
302
|
-
"color": ln["color"],
|
|
303
|
-
}
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
for mk in _normalize_marks(marks):
|
|
307
|
-
# fallback price to nearest bar high if missing (labels sit above candle)
|
|
308
|
-
price = mk["price"]
|
|
309
|
-
if price is None:
|
|
310
|
-
nearest = min(rows, key=lambda r: abs(int(r["time"]) - mk["time"])) if rows else None
|
|
311
|
-
price = float(nearest["high"]) if nearest else 0.0
|
|
312
|
-
cmds.append(
|
|
313
|
-
{
|
|
314
|
-
"type": "TEXT_MARKER",
|
|
315
|
-
"id": mk["id"],
|
|
316
|
-
"time": mk["time"],
|
|
317
|
-
"price": float(price),
|
|
318
|
-
"text": mk["text"],
|
|
319
|
-
"color": mk["color"],
|
|
320
|
-
}
|
|
321
|
-
)
|
|
322
|
-
|
|
323
|
-
return cmds
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
def draw_kline(
|
|
327
|
-
rows: Any,
|
|
328
|
-
*,
|
|
329
|
-
indicators: list[str] | None = None,
|
|
330
|
-
indicators_explicit: bool | None = None,
|
|
331
|
-
ma_periods: list[int] | None = None,
|
|
332
|
-
marks: Any = None,
|
|
333
|
-
lines: Any = None,
|
|
334
|
-
comparisons: Any = None,
|
|
335
|
-
security_workspace: Any = None,
|
|
336
|
-
symbol: str | None = None,
|
|
337
|
-
name: str | None = None,
|
|
338
|
-
data_source: str | None = None,
|
|
339
|
-
data_source_url: str | None = None,
|
|
340
|
-
interval: str = "day",
|
|
341
|
-
boll_period: int = DEFAULT_BOLL_PERIOD,
|
|
342
|
-
boll_std: float = DEFAULT_BOLL_STD,
|
|
343
|
-
volume_ma: int = DEFAULT_VOLUME_MA,
|
|
344
|
-
rsi_period: int = DEFAULT_RSI_PERIOD,
|
|
345
|
-
atr_period: int = DEFAULT_ATR_PERIOD,
|
|
346
|
-
) -> dict[str, Any]:
|
|
347
|
-
"""Return a self-contained chart session payload."""
|
|
348
|
-
norm = validate_rows(rows, min_len=2)
|
|
349
|
-
requested_indicators = ["ma", "vol"] if indicators is None else indicators
|
|
350
|
-
inds = [str(x).lower() for x in requested_indicators if str(x).lower() in SUPPORTED_INDICATORS]
|
|
351
|
-
cmds = build_chart_commands(
|
|
352
|
-
norm,
|
|
353
|
-
indicators=inds,
|
|
354
|
-
ma_periods=ma_periods,
|
|
355
|
-
marks=marks,
|
|
356
|
-
lines=lines,
|
|
357
|
-
boll_period=boll_period,
|
|
358
|
-
boll_std=boll_std,
|
|
359
|
-
volume_ma=volume_ma,
|
|
360
|
-
rsi_period=rsi_period,
|
|
361
|
-
atr_period=atr_period,
|
|
362
|
-
)
|
|
363
|
-
comparison_series = _normalize_comparisons(comparisons)
|
|
364
|
-
if comparison_series:
|
|
365
|
-
cmds.append({"type": "SET_COMPARISON_SERIES", "series": comparison_series})
|
|
366
|
-
# Structured payload for the view (includes SET_CANDLES rows).
|
|
367
|
-
# Content text stays compact for host LLM context.
|
|
368
|
-
payload = {
|
|
369
|
-
"calculation_engine": {"name": "TA-Lib", "wrapper_version": ENGINE_VERSION,
|
|
370
|
-
"native_version": NATIVE_VERSION},
|
|
371
|
-
"symbol": symbol or "",
|
|
372
|
-
"name": name or symbol or "",
|
|
373
|
-
"interval": (interval or "day").lower(),
|
|
374
|
-
"count": len(norm),
|
|
375
|
-
"start_time": int(norm[0]["time"]),
|
|
376
|
-
"end_time": int(norm[-1]["time"]),
|
|
377
|
-
"indicators": inds,
|
|
378
|
-
"indicators_explicit": bool(indicators_explicit),
|
|
379
|
-
"chartCommands": cmds,
|
|
380
|
-
# Convenience cards for view header
|
|
381
|
-
"last_close": float(norm[-1]["close"]),
|
|
382
|
-
"last_time": int(norm[-1]["time"]),
|
|
383
|
-
}
|
|
384
|
-
if isinstance(security_workspace, dict):
|
|
385
|
-
# The app only consumes this provider-neutral schema. Supplying it with
|
|
386
|
-
# the draw payload keeps news/company data visible even when the host
|
|
387
|
-
# cannot issue a second in-app tools/call request.
|
|
388
|
-
payload["security_workspace"] = security_workspace
|
|
389
|
-
if data_source and str(data_source).strip():
|
|
390
|
-
payload["data_meta"] = {"source": str(data_source).strip()[:120]}
|
|
391
|
-
source_url = _safe_https_url(data_source_url)
|
|
392
|
-
if source_url:
|
|
393
|
-
payload["data_meta"]["source_url"] = source_url
|
|
394
|
-
return payload
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"""Whitelisted browser object observations; never upgrade them to pixel verification."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
KINDS = {"horizontal_line", "trend_line", "channel", "rectangle", "fibonacci_retracement", "labeled_polyline", "text_annotation", "number_annotation", "icon_annotation", "series_line", "price_band", "price_sticks"}
|
|
5
|
-
REASONS = {
|
|
6
|
-
"created": {"overlay_registered", "outside_time_viewport", "indicator_registered"},
|
|
7
|
-
"hidden": {"period_mismatch", "anchors_not_loaded"},
|
|
8
|
-
"removed": {"overlay_removed", "indicator_removed"},
|
|
9
|
-
"failed": {"invalid_geometry", "overlay_missing", "overlay_mismatch", "overlay_still_present", "creation_failed", "indicator_missing", "indicator_still_present"},
|
|
10
|
-
"unknown": {"overlay_api_unavailable", "overlay_lookup_failed", "overlay_mismatch", "context_not_ready", "application_rolled_back", "rollback_unknown", "indicator_api_unavailable"},
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _empty(status):
|
|
15
|
-
return {"schema_version": 1, "report_status": status, "evidence_scope": "chart_object_api",
|
|
16
|
-
"render_verified": False, "pixel_verified": False, "items": []}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def sanitize_drawing_feedback(raw, allowed):
|
|
20
|
-
if raw is None: return _empty("not_reported")
|
|
21
|
-
if isinstance(raw, dict) and isinstance(raw.get("report_status"), str) and raw["report_status"] in {"not_reported", "invalid"}:
|
|
22
|
-
return _empty(raw["report_status"])
|
|
23
|
-
try:
|
|
24
|
-
if (not isinstance(raw, dict) or type(raw.get("schema_version")) is not int or raw["schema_version"] != 1
|
|
25
|
-
or raw.get("phase") not in {"current", "applied", "rolled_back", "rollback_unknown"}
|
|
26
|
-
or not isinstance(raw.get("items"), list) or len(raw["items"]) > 360): raise ValueError("report")
|
|
27
|
-
objects = {d["id"]: d["kind"] for d in allowed}; seen = set(); items = []
|
|
28
|
-
for item in raw["items"]:
|
|
29
|
-
identity, kind, status, reason, visibility = (item[k] for k in ("id", "kind", "status", "reason", "visibility"))
|
|
30
|
-
if (not isinstance(identity, str) or not 1 <= len(identity) <= 256 or identity in seen or objects.get(identity) != kind
|
|
31
|
-
or kind not in KINDS or status not in REASONS or reason not in REASONS[status]
|
|
32
|
-
or visibility not in {"unknown", "outside_time_viewport", "not_applicable"}
|
|
33
|
-
or (reason == "outside_time_viewport") != (visibility == "outside_time_viewport")): raise ValueError("item")
|
|
34
|
-
seen.add(identity)
|
|
35
|
-
overlap = item.get("time_range_overlap")
|
|
36
|
-
if overlap is not None and type(overlap) is not bool: raise ValueError("time_range_overlap")
|
|
37
|
-
items.append({"id": identity, "kind": kind, "status": status, "reason": reason, "visibility": visibility,
|
|
38
|
-
"outside_loaded_price_envelope": item.get("outside_loaded_price_envelope") is True,
|
|
39
|
-
"time_range_overlap": overlap})
|
|
40
|
-
if len(seen) != len(objects): raise ValueError("coverage")
|
|
41
|
-
scope = raw.get("evidence_scope")
|
|
42
|
-
if scope not in {"chart_object_api", "indicator_registry", "mixed_chart_api_and_indicator_registry"}:
|
|
43
|
-
scope = "chart_object_api"
|
|
44
|
-
return {**_empty("reported"), "phase": raw["phase"], "evidence_scope": scope, "items": items}
|
|
45
|
-
except (ValueError, TypeError, KeyError, AttributeError): return _empty("invalid")
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"""Small, read-only presentation helpers. Never interpret intent or authorize edits."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
from copy import deepcopy
|
|
5
|
-
import re
|
|
6
|
-
from typing import get_args
|
|
7
|
-
|
|
8
|
-
from tools.lines import ColorInput
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def drawing_capabilities() -> dict:
|
|
12
|
-
return {"color_inputs": list(get_args(ColorInput)), "editable_origins": ["ai"],
|
|
13
|
-
"drawing_selection_supported": False, "ambiguous_target": "ask_user",
|
|
14
|
-
"unspecified_price_amount": "ask_user"}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def edit_interaction(data: dict, change: dict | None = None) -> dict:
|
|
18
|
-
status = data.get("apply_status")
|
|
19
|
-
states = {
|
|
20
|
-
"not_requested": ("prepared", "修改方案已准备,尚未执行。", "read_current_context_before_apply"),
|
|
21
|
-
"queued": ("pending", "修改已排队,尚未确认完成。", "check_original_candidate_status"),
|
|
22
|
-
"delivered": ("pending", "修改已送达网页,尚未确认完成。", "check_original_candidate_status"),
|
|
23
|
-
"rejected": ("not_confirmed", "本次修改被拒绝,未获成功确认。", "read_current_context_before_new_edit"),
|
|
24
|
-
"failed": ("not_confirmed", "本次修改失败,请先检查失败原因。", "inspect_failure_do_not_resend"),
|
|
25
|
-
"outcome_unknown": ("unknown", "本次修改结果尚不确定,不要重复执行。", "check_original_candidate_status_do_not_resend"),
|
|
26
|
-
}
|
|
27
|
-
value = states.get(status, ("unknown", "本次修改状态无法确认。", "stop_and_inspect"))
|
|
28
|
-
token = data.get("candidate_chart_session")
|
|
29
|
-
confirmed = (status == "applied" and isinstance(token, str) and re.fullmatch(r"[A-Za-z0-9_-]{32}", token) is not None
|
|
30
|
-
and data.get("confirmed_chart_session") == data["candidate_chart_session"]
|
|
31
|
-
and data.get("confirmation_scope") == "view_state_only")
|
|
32
|
-
if confirmed:
|
|
33
|
-
value = ("confirmed", "本次修改已获网页状态确认;目标图形和画面像素仍需核验。", "read_current_context_before_next_edit")
|
|
34
|
-
if data.get("needs_attention"):
|
|
35
|
-
value = ("needs_review", "网页已确认应用,但图形反馈仍需检查;画面像素未核验。", "inspect_drawing_feedback")
|
|
36
|
-
target = (change.get("after") or change.get("before") or {}).get("id") if isinstance(change, dict) else None
|
|
37
|
-
feedback = data.get("drawing_feedback")
|
|
38
|
-
item = next((entry for entry in feedback.get("items", []) if entry.get("id") == target), None) if (
|
|
39
|
-
target and isinstance(feedback, dict) and feedback.get("report_status") == "reported"
|
|
40
|
-
and feedback.get("phase") == "applied") else None
|
|
41
|
-
object_status = item.get("status", "unknown") if item else "unknown"
|
|
42
|
-
time_overlap = item.get("time_range_overlap") if item else None
|
|
43
|
-
if confirmed and value[0] == "confirmed" and item:
|
|
44
|
-
if object_status == "created":
|
|
45
|
-
message = ("网页已确认应用,目标序列已在图表登记;画面像素未核验。" if item.get("reason") == "indicator_registered"
|
|
46
|
-
else "网页已确认应用,目标图形对象与锚点已核对;画面像素未核验。")
|
|
47
|
-
if item.get("reason") != "indicator_registered":
|
|
48
|
-
if time_overlap is False: message = "网页已确认应用,目标图形对象已核对,但在应用当时的时间视口之外;画面像素未核验。"
|
|
49
|
-
elif time_overlap is True: message = "网页已确认应用,目标图形对象与锚点已核对,时间范围覆盖应用当时的视口;画面像素未核验。"
|
|
50
|
-
value = (value[0], message, value[2])
|
|
51
|
-
elif object_status == "removed":
|
|
52
|
-
value = (value[0], "网页已确认删除,目标图形对象已从图表对象表移除;画面像素未核验。", value[2])
|
|
53
|
-
elif object_status == "hidden":
|
|
54
|
-
value = (value[0], "网页已确认应用,但目标图形在当前周期或数据范围内隐藏;画面像素未核验。", value[2])
|
|
55
|
-
return {"status": value[0], "message": value[1], "next_action": value[2],
|
|
56
|
-
"completion_confirmed": value[0] == "confirmed", "render_verified": False,
|
|
57
|
-
"object_status": object_status, "time_range_overlap": time_overlap, "pixel_verified": False,
|
|
58
|
-
"record_is_historical": data.get("record_is_historical") is True}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def edit_change(candidate: dict, parent: dict) -> dict | None:
|
|
62
|
-
# Derive an object-level diff from the exact named snapshots, not prose or
|
|
63
|
-
# a global latest chart. These are candidate effects, not a live receipt.
|
|
64
|
-
from tools.chart_edits import snapshot_inventory
|
|
65
|
-
try:
|
|
66
|
-
guard = candidate["drawing_guard"]
|
|
67
|
-
kind, action = guard["kind"], guard["action"]
|
|
68
|
-
before = {obj["id"]: obj for obj in snapshot_inventory(parent)}
|
|
69
|
-
after = {obj["id"]: obj for obj in snapshot_inventory(candidate)}
|
|
70
|
-
if action == "create":
|
|
71
|
-
added = set(after) - set(before)
|
|
72
|
-
if len(added) != 1:
|
|
73
|
-
return None
|
|
74
|
-
target = added.pop()
|
|
75
|
-
elif action in {"update", "delete"}:
|
|
76
|
-
target = guard["object_id"]
|
|
77
|
-
else:
|
|
78
|
-
return None
|
|
79
|
-
old, new = before.get(target), after.get(target)
|
|
80
|
-
if (action == "create" and old is not None or action == "delete" and new is not None
|
|
81
|
-
or action != "create" and old is None or action != "delete" and new is None
|
|
82
|
-
or any(obj["kind"] != kind for obj in (old, new) if obj is not None)):
|
|
83
|
-
return None
|
|
84
|
-
fields = sorted(k for k in set(old or {}) | set(new or {})
|
|
85
|
-
if k not in {"id", "origin", "kind"} and (old or {}).get(k) != (new or {}).get(k))
|
|
86
|
-
detail = {}
|
|
87
|
-
if kind == "labeled_polyline" and old is not None and new is not None:
|
|
88
|
-
previous_points = {p["label"]: p for p in old["points"]}
|
|
89
|
-
next_points = {p["label"]: p for p in new["points"]}
|
|
90
|
-
detail["point_changes"] = [{"label": label, "before": deepcopy(previous_points.get(label)),
|
|
91
|
-
"after": deepcopy(next_points.get(label))}
|
|
92
|
-
for label in sorted(previous_points.keys() | next_points.keys())
|
|
93
|
-
if previous_points.get(label) != next_points.get(label)]
|
|
94
|
-
return {"kind": kind, "action": action, "before": deepcopy(old), "after": deepcopy(new), **detail,
|
|
95
|
-
"changed_fields": fields, "basis": "prepared_candidate_not_live_state",
|
|
96
|
-
"other_ai_drawings_unchanged": {k: v for k, v in before.items() if k != target}
|
|
97
|
-
== {k: v for k, v in after.items() if k != target}}
|
|
98
|
-
except (KeyError, TypeError, AttributeError):
|
|
99
|
-
return None
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def error_interaction(code: str) -> dict:
|
|
103
|
-
if code in {"invalid_color", "invalid_price", "invalid_object_identity", "ambiguous_drawing_id", "drawing_not_editable",
|
|
104
|
-
"invalid_annotation_text", "invalid_annotation_value", "invalid_annotation_anchor", "annotation_anchor_required", "annotation_not_found",
|
|
105
|
-
"invalid_polyline_points", "invalid_point_label", "duplicate_point_label", "point_not_found", "point_label_required", "empty_point_update"}:
|
|
106
|
-
next_action = "ask_user"
|
|
107
|
-
elif code in {"chart_context_stale", "chart_view_inactive", "chart_context_revision_conflict",
|
|
108
|
-
"chart_snapshot_not_aligned", "chart_context_unavailable", "ambiguous_chart_views"}:
|
|
109
|
-
next_action = "read_current_context"
|
|
110
|
-
elif code in {"chart_application_unavailable", "chart_edit_outcome_unknown"}:
|
|
111
|
-
next_action = "check_original_candidate_status_do_not_resend"
|
|
112
|
-
else:
|
|
113
|
-
next_action = "stop_and_inspect"
|
|
114
|
-
result = {"status": "not_confirmed", "completion_confirmed": False, "next_action": next_action}
|
|
115
|
-
if code == "invalid_color":
|
|
116
|
-
result["color_inputs"] = list(get_args(ColorInput))
|
|
117
|
-
return result
|