@v587d/capital-generation 0.0.0-stage → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +794 -0
- package/LICENSE +21 -0
- package/README.md +116 -2
- package/assets/cg-icon.png +0 -0
- package/capital-config/client.js +28 -0
- package/capital-config/client.src.cjs +388 -0
- package/capital-config/index.js +113 -0
- package/capital-config/package.json +36 -0
- package/capital-watchlist/client.js +182 -0
- package/capital-watchlist/client.src.cjs +1229 -0
- package/capital-watchlist/index.js +772 -0
- package/capital-watchlist/package.json +37 -0
- package/chart-ui/README.md +112 -0
- package/chart-ui/client.js +16 -0
- package/chart-ui/client.src.cjs +126 -0
- package/chart-ui/index.js +205 -0
- package/chart-ui/package.json +30 -0
- package/cordis.patch.yml +72 -0
- package/lib/agents/bash-guard.d.ts +55 -0
- package/lib/agents/bash-guard.js +162 -0
- package/lib/agents/root-tool-policy.d.ts +164 -0
- package/lib/agents/root-tool-policy.js +309 -0
- package/lib/chart/artifact-ref.d.ts +65 -0
- package/lib/chart/artifact-ref.js +107 -0
- package/lib/chart/downsample.d.ts +8 -0
- package/lib/chart/downsample.js +53 -0
- package/lib/chart/errors.d.ts +16 -0
- package/lib/chart/errors.js +15 -0
- package/lib/chart/events.d.ts +120 -0
- package/lib/chart/events.js +471 -0
- package/lib/chart/html.d.ts +21 -0
- package/lib/chart/html.js +154 -0
- package/lib/chart/runtime.d.ts +20 -0
- package/lib/chart/runtime.js +270 -0
- package/lib/chart/series.d.ts +102 -0
- package/lib/chart/series.js +424 -0
- package/lib/chart/source-token.d.ts +64 -0
- package/lib/chart/source-token.js +217 -0
- package/lib/chart/spec.d.ts +58 -0
- package/lib/chart/spec.js +265 -0
- package/lib/chart/tool.d.ts +86 -0
- package/lib/chart/tool.js +288 -0
- package/lib/chart/vendor/LICENSE +201 -0
- package/lib/chart/vendor/VERSION.json +8 -0
- package/lib/chart/vendor/lightweight-charts.standalone.production.js +7 -0
- package/lib/data-collector/args.d.ts +38 -0
- package/lib/data-collector/args.js +114 -0
- package/lib/data-collector/dataset-tools.d.ts +3 -0
- package/lib/data-collector/dataset-tools.js +421 -0
- package/lib/data-collector/describe.d.ts +99 -0
- package/lib/data-collector/describe.js +256 -0
- package/lib/data-collector/hub.d.ts +187 -0
- package/lib/data-collector/hub.js +469 -0
- package/lib/data-collector/query-time.d.ts +58 -0
- package/lib/data-collector/query-time.js +101 -0
- package/lib/data-collector/query.d.ts +57 -0
- package/lib/data-collector/query.js +473 -0
- package/lib/data-collector/store.d.ts +499 -0
- package/lib/data-collector/store.js +1486 -0
- package/lib/data-collector/time-axis.d.ts +169 -0
- package/lib/data-collector/time-axis.js +419 -0
- package/lib/data-collector/tools.d.ts +32 -0
- package/lib/data-collector/tools.js +216 -0
- package/lib/index.d.ts +275 -0
- package/lib/index.js +458 -0
- package/lib/net/eastmoney-client.d.ts +104 -0
- package/lib/net/eastmoney-client.js +118 -0
- package/lib/net/throttle.d.ts +16 -0
- package/lib/net/throttle.js +34 -0
- package/lib/ocr/client.d.ts +82 -0
- package/lib/ocr/client.js +281 -0
- package/lib/ocr/markdown.d.ts +75 -0
- package/lib/ocr/markdown.js +209 -0
- package/lib/ocr/store.d.ts +119 -0
- package/lib/ocr/store.js +226 -0
- package/lib/sources/eastmoney-http.d.ts +2 -0
- package/lib/sources/eastmoney-http.js +1253 -0
- package/lib/sources/fuyao-core.d.ts +52 -0
- package/lib/sources/fuyao-core.js +96 -0
- package/lib/sources/fuyao-rest.d.ts +14 -0
- package/lib/sources/fuyao-rest.js +2057 -0
- package/lib/sources/security-code.d.ts +27 -0
- package/lib/sources/security-code.js +104 -0
- package/lib/sources/security-identity.d.ts +24 -0
- package/lib/sources/security-identity.js +89 -0
- package/lib/sources/tencent-http.d.ts +2 -0
- package/lib/sources/tencent-http.js +1053 -0
- package/lib/sources/wind-mcp.d.ts +8 -0
- package/lib/sources/wind-mcp.js +593 -0
- package/lib/time/tools.d.ts +74 -0
- package/lib/time/tools.js +464 -0
- package/lib/tool-exec.d.ts +29 -0
- package/lib/tool-exec.js +17 -0
- package/lib/web-retriever/engines.d.ts +61 -0
- package/lib/web-retriever/engines.js +202 -0
- package/lib/web-retriever/html-markdown.d.ts +50 -0
- package/lib/web-retriever/html-markdown.js +321 -0
- package/lib/web-retriever/local-fetch.d.ts +121 -0
- package/lib/web-retriever/local-fetch.js +562 -0
- package/lib/web-retriever/retriever.d.ts +58 -0
- package/lib/web-retriever/retriever.js +94 -0
- package/lib/web-retriever/sources.d.ts +235 -0
- package/lib/web-retriever/sources.js +961 -0
- package/lib/web-retriever/tools.d.ts +50 -0
- package/lib/web-retriever/tools.js +1029 -0
- package/lib/web-retriever/wind-client.d.ts +69 -0
- package/lib/web-retriever/wind-client.js +311 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +76 -4
- package/preset/capital-generation/README.md +161 -0
- package/preset/capital-generation/agent.patch.yml +509 -0
- package/preset/capital-generation/skills/capital-chart-protocol/SKILL.md +137 -0
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +416 -0
- package/preset/capital-generation/skills/capital-orchestration/SKILL.md +174 -0
- package/preset/capital-generation/skills/capital-visualization-protocol/SKILL.md +296 -0
- package/preset/capital-generation/skills/capital-web-protocol/SKILL.md +240 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { DatasetStoreError } from '../data-collector/store.js';
|
|
2
|
+
import { ChartError } from './errors.js';
|
|
3
|
+
import { buildStandaloneHtml, loadVendoredChartLibrary } from './html.js';
|
|
4
|
+
import { buildChartPayload, extractRows, MAX_CHART_POINTS } from './series.js';
|
|
5
|
+
import { normalizeChartSpec } from './spec.js';
|
|
6
|
+
import { chartSourceTokenForRender } from './source-token.js';
|
|
7
|
+
import { chartSessionScopeId } from './artifact-ref.js';
|
|
8
|
+
import { chartTraceEnabled } from './events.js';
|
|
9
|
+
const jsonObject = (properties = {}, required = []) => ({ type: 'object', properties, required, additionalProperties: false });
|
|
10
|
+
export const CHART_ARTIFACT_DIR = 'capital-analysis/charts';
|
|
11
|
+
function render(_args, value) {
|
|
12
|
+
return [{ type: 'text', text: JSON.stringify(value) }];
|
|
13
|
+
}
|
|
14
|
+
function newChartId() {
|
|
15
|
+
const cryptoLike = globalThis.crypto;
|
|
16
|
+
const suffix = cryptoLike?.randomUUID ? cryptoLike.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
|
|
17
|
+
return `ch_${suffix}`;
|
|
18
|
+
}
|
|
19
|
+
function sessionOf(exec) {
|
|
20
|
+
const session = exec.agent?.session;
|
|
21
|
+
if (!session || typeof session.id !== 'string' || session.id.length === 0) {
|
|
22
|
+
throw new ChartError('chart_source_invalid', 'the calling agent session was not provided');
|
|
23
|
+
}
|
|
24
|
+
return session;
|
|
25
|
+
}
|
|
26
|
+
function stripErrorCode(message) {
|
|
27
|
+
const separator = message.indexOf(':');
|
|
28
|
+
return separator >= 0 ? message.slice(separator + 1).trim() : message;
|
|
29
|
+
}
|
|
30
|
+
function normalizeStoreError(error) {
|
|
31
|
+
if (!(error instanceof DatasetStoreError))
|
|
32
|
+
return undefined;
|
|
33
|
+
const detail = stripErrorCode(error.message);
|
|
34
|
+
switch (error.code) {
|
|
35
|
+
case 'dataset_not_found':
|
|
36
|
+
case 'dataset_expired':
|
|
37
|
+
case 'dataset_session_mismatch':
|
|
38
|
+
return new ChartError('chart_source_not_found', detail, { cause: error.code });
|
|
39
|
+
case 'dataset_id_invalid':
|
|
40
|
+
case 'workspace_path_invalid':
|
|
41
|
+
return new ChartError('chart_source_invalid', detail, { cause: error.code });
|
|
42
|
+
case 'dataset_too_large':
|
|
43
|
+
return new ChartError('chart_too_large', detail, { cause: error.code });
|
|
44
|
+
case 'workspace_file_invalid':
|
|
45
|
+
case 'dataset_not_row_readable':
|
|
46
|
+
case 'dataset_format_unsupported':
|
|
47
|
+
return new ChartError('chart_source_invalid', detail, { cause: error.code });
|
|
48
|
+
case 'workspace_not_writable':
|
|
49
|
+
case 'dataset_write_failed':
|
|
50
|
+
return new ChartError('chart_write_failed', detail, { cause: error.code });
|
|
51
|
+
case 'filesystem_unavailable':
|
|
52
|
+
case 'sandbox_policy_unavailable':
|
|
53
|
+
case 'session_cwd_unavailable':
|
|
54
|
+
return new ChartError('chart_runtime_unavailable', detail, { cause: error.code });
|
|
55
|
+
default:
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 工具框架对 throw 的错误只保留 message;把 ChartError 的 details 在这里展开成
|
|
61
|
+
* JSON 信封,模型才能拿到 array_keys / available 等一次修正所需的信息。
|
|
62
|
+
*/
|
|
63
|
+
function toolVisibleError(error) {
|
|
64
|
+
const normalized = error instanceof ChartError ? error : normalizeStoreError(error);
|
|
65
|
+
if (!normalized)
|
|
66
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
67
|
+
const visible = new Error(JSON.stringify(normalized.toEnvelope()));
|
|
68
|
+
visible.name = normalized.name;
|
|
69
|
+
visible.code = normalized.code;
|
|
70
|
+
return visible;
|
|
71
|
+
}
|
|
72
|
+
const receiptSchema = jsonObject({
|
|
73
|
+
chart_ref: { type: 'string' },
|
|
74
|
+
chart_id: { type: 'string' },
|
|
75
|
+
kind: { type: 'string' },
|
|
76
|
+
axis: { type: 'string', enum: ['time', 'index'] },
|
|
77
|
+
title: { type: 'string' },
|
|
78
|
+
points: { type: 'integer' },
|
|
79
|
+
original_points: { type: 'integer' },
|
|
80
|
+
downsampled: { type: 'boolean' },
|
|
81
|
+
series_labels: { type: 'array', items: { type: 'string' } },
|
|
82
|
+
has_volume: { type: 'boolean' },
|
|
83
|
+
markers: { type: 'integer' },
|
|
84
|
+
dataset_id: { oneOf: [{ type: 'string' }, { type: 'null' }] },
|
|
85
|
+
source_label: { oneOf: [{ type: 'string' }, { type: 'null' }] },
|
|
86
|
+
captured_at: { oneOf: [{ type: 'integer' }, { type: 'null' }] },
|
|
87
|
+
chart_url: { oneOf: [{ type: 'string' }, { type: 'null' }] },
|
|
88
|
+
spec_path: { type: 'string' },
|
|
89
|
+
series_path: { type: 'string' },
|
|
90
|
+
html_path: { type: 'string' },
|
|
91
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
92
|
+
}, [
|
|
93
|
+
'chart_ref', 'chart_id', 'kind', 'axis', 'points', 'original_points', 'downsampled',
|
|
94
|
+
'series_labels', 'has_volume', 'markers', 'dataset_id', 'source_label',
|
|
95
|
+
'captured_at', 'chart_url', 'spec_path', 'series_path', 'html_path', 'warnings',
|
|
96
|
+
]);
|
|
97
|
+
const parameters = jsonObject({
|
|
98
|
+
dataset_id: { type: 'string', description: '数据来源之一:已授权的 DatasetRef 的 dataset_id(与 path / chart_source_ref 三选一)' },
|
|
99
|
+
path: { type: 'string', description: '数据来源之一:workspace 相对路径的 JSON 文件,如 capital-data/datasets/x/raw.json(与 dataset_id / chart_source_ref 三选一)' },
|
|
100
|
+
chart_source_ref: { type: 'string', description: '数据来源之一:宿主签发给 visualization_specialist 的短期 opaque chart source token(与 dataset_id / path 三选一)' },
|
|
101
|
+
task_id: { type: 'string', description: '使用 chart_source_ref 时必需;必须与 token 绑定的当前任务一致' },
|
|
102
|
+
spec: {
|
|
103
|
+
oneOf: [{ type: 'object', additionalProperties: true }, { type: 'string' }],
|
|
104
|
+
description: '图表描述对象或 JSON 对象字符串,至少 { kind, x?, series? | ohlc?, volume?, markers?, range?, title? };字段语义与错误码见 skill capital-chart-protocol',
|
|
105
|
+
},
|
|
106
|
+
title: { type: 'string', description: '可选:覆盖 spec.title 的图表标题' },
|
|
107
|
+
}, ['spec']);
|
|
108
|
+
export async function renderChart(input, args, exec) {
|
|
109
|
+
const now = input.now ?? (() => Date.now());
|
|
110
|
+
const session = sessionOf(exec);
|
|
111
|
+
const requestedDatasetId = typeof args.dataset_id === 'string' && args.dataset_id.trim().length > 0 ? args.dataset_id.trim() : undefined;
|
|
112
|
+
const path = typeof args.path === 'string' && args.path.trim().length > 0 ? args.path.trim() : undefined;
|
|
113
|
+
const chartSourceRef = typeof args.chart_source_ref === 'string' && args.chart_source_ref.trim().length > 0 ? args.chart_source_ref.trim() : undefined;
|
|
114
|
+
const sourceCount = [requestedDatasetId, path, chartSourceRef].filter((value) => value !== undefined).length;
|
|
115
|
+
if (sourceCount !== 1) {
|
|
116
|
+
throw new ChartError('chart_source_invalid', 'provide exactly one data source: dataset_id, path, or chart_source_ref');
|
|
117
|
+
}
|
|
118
|
+
if (session.header?.parentSession && chartSourceRef === undefined) {
|
|
119
|
+
throw new ChartError('chart_source_scope_mismatch', 'delegated visualization callers must use chart_source_ref');
|
|
120
|
+
}
|
|
121
|
+
const tokenSource = chartSourceRef === undefined ? undefined : chartSourceTokenForRender(input.sourceTokens, {
|
|
122
|
+
chart_source_ref: chartSourceRef,
|
|
123
|
+
task_id: args.task_id,
|
|
124
|
+
}, session);
|
|
125
|
+
const datasetId = tokenSource?.dataset_id ?? requestedDatasetId;
|
|
126
|
+
const spec = normalizeChartSpec(args.spec);
|
|
127
|
+
if (typeof args.title === 'string' && args.title.trim().length > 0)
|
|
128
|
+
spec.title = args.title.trim().slice(0, 200);
|
|
129
|
+
// ── 取数:两条来源都在宿主进程内完成,rows 不进入任何消息 ────────────────────
|
|
130
|
+
let rows;
|
|
131
|
+
let meta;
|
|
132
|
+
if (datasetId !== undefined) {
|
|
133
|
+
// A chart_source_ref carries the direct data-agent session that already has
|
|
134
|
+
// access to the parent Dataset scope. The nested visualization child is
|
|
135
|
+
// only the caller of render_chart; it never receives raw rows.
|
|
136
|
+
const readSession = tokenSource?.sourceSession ?? session;
|
|
137
|
+
const { ref, rows: datasetRows } = await input.store.readPresentationRows({ session: readSession, dataset_id: datasetId, signal: exec.signal });
|
|
138
|
+
rows = datasetRows;
|
|
139
|
+
meta = { source_kind: 'dataset', dataset_id: ref.dataset_id, source_label: ref.source_label, captured_at: ref.captured_at };
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const parsed = await input.store.readWorkspaceJson({ session, path: path, signal: exec.signal });
|
|
143
|
+
const extracted = extractRows(parsed);
|
|
144
|
+
rows = extracted.rows;
|
|
145
|
+
meta = { source_kind: 'path' };
|
|
146
|
+
}
|
|
147
|
+
// ── 有界化 ───────────────────────────────────────────────────────────────
|
|
148
|
+
const chartId = newChartId();
|
|
149
|
+
const payload = buildChartPayload({ chart_id: chartId, spec, rows, meta });
|
|
150
|
+
const library = loadVendoredChartLibrary();
|
|
151
|
+
const generatedAt = now();
|
|
152
|
+
const html = buildStandaloneHtml({ payload, library, generatedAt });
|
|
153
|
+
const dir = `${CHART_ARTIFACT_DIR}/${chartId}`;
|
|
154
|
+
const written = await input.store.writeWorkspaceFiles({
|
|
155
|
+
session,
|
|
156
|
+
dir,
|
|
157
|
+
files: [
|
|
158
|
+
{ name: 'spec.json', content: `${JSON.stringify({ chart_id: chartId, created_at: generatedAt, source: { dataset_id: meta.dataset_id ?? null, path: path ?? null }, spec }, null, 2)}\n` },
|
|
159
|
+
{ name: 'series.json', content: `${JSON.stringify(payload)}\n` },
|
|
160
|
+
{ name: 'chart.html', content: html },
|
|
161
|
+
],
|
|
162
|
+
signal: exec.signal,
|
|
163
|
+
});
|
|
164
|
+
const pathOf = (name) => written.find((file) => file.name === name)?.path ?? `${dir}/${name}`;
|
|
165
|
+
// 序列旁路:把 series.json 的**绝对路径**登记给 host 平面路由,客户端凭 chart_url 取数。
|
|
166
|
+
// 登记失败(服务缺失/实现异常)不阻断出图——图已经落盘了,降级成"只有文件路径"。
|
|
167
|
+
let chartUrl = null;
|
|
168
|
+
const seriesFile = written.find((file) => file.name === 'series.json');
|
|
169
|
+
if (input.charts && seriesFile !== undefined) {
|
|
170
|
+
try {
|
|
171
|
+
chartUrl = input.charts()?.publish({ chartId, filePath: seriesFile.absolutePath }) ?? null;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
payload.meta.warnings.push(`序列旁路登记失败(回执只给文件路径):${error instanceof Error ? error.message : String(error)}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const taskId = tokenSource?.task_id
|
|
178
|
+
?? (typeof args.task_id === 'string' && args.task_id.trim().length > 0 ? args.task_id.trim() : null);
|
|
179
|
+
const artifact = input.artifacts?.issue({
|
|
180
|
+
session: tokenSource?.sourceSession ?? session,
|
|
181
|
+
chart_id: chartId,
|
|
182
|
+
task_id: taskId,
|
|
183
|
+
dataset_id: meta.dataset_id ?? null,
|
|
184
|
+
source_label: meta.source_label ?? null,
|
|
185
|
+
captured_at: meta.captured_at ?? null,
|
|
186
|
+
kind: payload.kind,
|
|
187
|
+
axis: payload.axis,
|
|
188
|
+
chart_url: chartUrl,
|
|
189
|
+
spec_path: pathOf('spec.json'),
|
|
190
|
+
series_path: pathOf('series.json'),
|
|
191
|
+
html_path: pathOf('chart.html'),
|
|
192
|
+
created_at: generatedAt,
|
|
193
|
+
});
|
|
194
|
+
// Direct unit callers that do not install the production registry still get
|
|
195
|
+
// a stable receipt; production apply() always injects the registry.
|
|
196
|
+
const chartRef = artifact?.chart_ref ?? `chart_${chartId.slice(3)}`;
|
|
197
|
+
// 对话流呈现:把这张图登记为**用户正在看的那条会话**的本轮交付物
|
|
198
|
+
// (owner scope 与 chart_ref 同源,因此 specialist 出的图正好落在主会话)。
|
|
199
|
+
// 走官方 `deliverables/presented`——**不能**改回自定义事件类型:会话日志的事件词汇表
|
|
200
|
+
// 是闭集,非 first-party 类型会让整份会话在冷加载时打不开(事故记录见 src/chart/events.ts)。
|
|
201
|
+
// 事件不进模型消息历史。呈现通道可选:写不进去不影响图表产物与回执。
|
|
202
|
+
let deliverableTrace;
|
|
203
|
+
try {
|
|
204
|
+
const publisher = input.chartEvents?.();
|
|
205
|
+
if (publisher === undefined) {
|
|
206
|
+
deliverableTrace = '发布器不可用:chartEvents() 返回 undefined(sessions / sessionProjections 解析不到,或接线异常)';
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const ownerSessionId = chartSessionScopeId(tokenSource?.sourceSession ?? session);
|
|
210
|
+
const accepted = publisher.publish({
|
|
211
|
+
ownerSessionId,
|
|
212
|
+
chart_id: chartId,
|
|
213
|
+
title: payload.title,
|
|
214
|
+
html_path: pathOf('chart.html'),
|
|
215
|
+
});
|
|
216
|
+
deliverableTrace = `publish=${accepted ? '受理' : '拒绝'} ownerSessionId=${ownerSessionId} | ${publisher.lastTrace?.() ?? '(无轨迹)'}`;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
deliverableTrace = `交付登记抛错(已吞掉,不影响出图):${error instanceof Error ? error.message : String(error)}`;
|
|
221
|
+
}
|
|
222
|
+
// 诊断落盘**默认关闭**:交付行"静默不出现"是最难查的故障(2026-09-20 连查四轮),
|
|
223
|
+
// 而宿主终端不总能拿到(cordis logger 只进内存),所以留一条可从磁盘定位的出口;
|
|
224
|
+
// 但它属于调试产物,不该出现在对外版本的 workspace 里。
|
|
225
|
+
// 需要时用 `CAPITAL_CHART_TRACE=1` 启动宿主,图表产物目录会多出 deliverable-trace.txt。
|
|
226
|
+
if (chartTraceEnabled()) {
|
|
227
|
+
try {
|
|
228
|
+
await input.store.writeWorkspaceFiles({
|
|
229
|
+
session,
|
|
230
|
+
dir,
|
|
231
|
+
files: [{ name: 'deliverable-trace.txt', content: `${deliverableTrace}\n` }],
|
|
232
|
+
signal: exec.signal,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// 诊断落盘失败不影响出图。
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
chart_ref: chartRef,
|
|
241
|
+
chart_id: chartId,
|
|
242
|
+
kind: payload.kind,
|
|
243
|
+
axis: payload.axis,
|
|
244
|
+
title: payload.title,
|
|
245
|
+
points: payload.meta.points,
|
|
246
|
+
original_points: payload.meta.original_points,
|
|
247
|
+
downsampled: payload.meta.downsampled,
|
|
248
|
+
series_labels: payload.series.map((item) => item.label).concat(payload.ohlc ? [payload.ohlc.label] : []),
|
|
249
|
+
has_volume: payload.volume !== undefined,
|
|
250
|
+
markers: payload.markers.length,
|
|
251
|
+
dataset_id: meta.dataset_id ?? null,
|
|
252
|
+
source_label: meta.source_label ?? null,
|
|
253
|
+
captured_at: meta.captured_at ?? null,
|
|
254
|
+
chart_url: chartUrl,
|
|
255
|
+
spec_path: pathOf('spec.json'),
|
|
256
|
+
series_path: pathOf('series.json'),
|
|
257
|
+
html_path: pathOf('chart.html'),
|
|
258
|
+
warnings: payload.meta.warnings,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export function registerChartTool(ctx, options) {
|
|
262
|
+
const tools = ctx.get('tools');
|
|
263
|
+
if (!tools)
|
|
264
|
+
return;
|
|
265
|
+
const definition = {
|
|
266
|
+
name: 'render_chart',
|
|
267
|
+
description: `把已经取到的数据渲染成一张可交互图,产物落在 workspace 的 ${CHART_ARTIFACT_DIR}/<chart_id>/(chart.html 可离线打开)。` +
|
|
268
|
+
'**只回一条小回执,不回任何原始数据行**:序列走旁路,不进入上下文。' +
|
|
269
|
+
'来源三选一:dataset_id(已授权的 DatasetRef)、path(workspace 相对路径的 JSON,支持顶层数组或含行数组的 envelope),或 chart_source_ref(宿主签发给 visualization_specialist 的短期 token;使用它时还要提供 task_id)。' +
|
|
270
|
+
'spec 是自由对象,至少给出 kind(line / area / column / candlestick / bar;后两者要 ohlc 四字段与真实时间列)与字段选择(series 或 ohlc),' +
|
|
271
|
+
`最多保留 ${MAX_CHART_POINTS} 个点(超出由宿主下采样并如实标注)。` +
|
|
272
|
+
'字段语义、可用键与错误码见 skill capital-chart-protocol —— 首次画图前先加载它。' +
|
|
273
|
+
'是否出图由 data_junior 的可视化协议决定;本工具只负责安全生成图表产物和小型回执。' +
|
|
274
|
+
'出图成功后宿主会把这张图登记为当前对话的**本轮交付物**(官方 deliverables/presented),用户可从收尾的交付行点开自包含图表;调用方**不要**在回传或正文里罗列图表文件、路径或 HTML。' +
|
|
275
|
+
'图表是呈现不是分析:需要数值结论(首末值、涨跌幅、分位数等)仍走 data_junior 的 profile / query,不要用图去推断数字。',
|
|
276
|
+
parameters,
|
|
277
|
+
output: { schema: receiptSchema, render },
|
|
278
|
+
async execute(args, exec) {
|
|
279
|
+
try {
|
|
280
|
+
return await renderChart(options, args, exec);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
throw toolVisibleError(error);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
ctx.effect(() => tools.register(definition), 'capital-generation.tool(render_chart)');
|
|
288
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 TradingView, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lightweight-charts",
|
|
3
|
+
"version": "5.2.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"dist": "lightweight-charts.standalone.production.js",
|
|
6
|
+
"sha256": "e21cc5caa0226ef30bd8549c50b9ef926615f2a4ee6b4e486353477a55f598cf",
|
|
7
|
+
"attribution": "TradingView Lightweight Charts™ — attribution logo 保持开启"
|
|
8
|
+
}
|