@v587d/capital-generation 2.16.0 → 2.17.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 +60 -0
- package/README.md +9 -3
- package/automation/board.js +461 -0
- package/automation/brief.js +779 -0
- package/automation/builtins.js +3 -3
- package/automation/client.js +127 -7
- package/automation/client.src.cjs +1051 -7
- package/automation/index.js +24 -2
- package/automation/package.json +3 -1
- package/automation/route.js +9 -2
- package/automation/runner.js +14 -2
- package/automation/schema.js +60 -0
- package/automation/service.js +30 -1
- package/automation/store.js +142 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +1 -0
- package/lib/web-retriever/sources.js +7 -3
- package/lib/web-retriever/tools.js +6 -4
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +1 -1
- package/preset/capital-generation/agent.patch.yml +3 -3
- package/preset/capital-generation/skills/capital-web-evidence/SKILL.md +10 -4
- package/preset/capital-generation/skills/capital-web-protocol/SKILL.md +22 -14
- package/watchlist/package.json +1 -1
package/automation/index.js
CHANGED
|
@@ -8,6 +8,8 @@ import { homedir } from 'node:os'
|
|
|
8
8
|
import { join } from 'node:path'
|
|
9
9
|
|
|
10
10
|
import { createRunRunner, buildRunPrompt, sessionTitleOf } from './runner.js'
|
|
11
|
+
import { createBriefService } from './brief.js'
|
|
12
|
+
import { createBoardService } from './board.js'
|
|
11
13
|
import { createScheduler } from './scheduler.js'
|
|
12
14
|
import { createAutomationService, AutomationError } from './service.js'
|
|
13
15
|
import { createAutomationStore, domainSpec, ROUTE_PATH } from './store.js'
|
|
@@ -62,12 +64,14 @@ export function createAutomationRuntime(options) {
|
|
|
62
64
|
calendar,
|
|
63
65
|
settings: getSettings,
|
|
64
66
|
})
|
|
67
|
+
let briefs
|
|
65
68
|
const runner = createRunRunner({
|
|
66
69
|
ctx,
|
|
67
70
|
store,
|
|
68
71
|
settings: getSettings,
|
|
69
72
|
profile: { displayName, runDir },
|
|
70
73
|
workspaces,
|
|
74
|
+
onRunSucceeded: (payload) => briefs?.onRunSucceeded(payload),
|
|
71
75
|
now,
|
|
72
76
|
logger,
|
|
73
77
|
})
|
|
@@ -80,6 +84,18 @@ export function createAutomationRuntime(options) {
|
|
|
80
84
|
now,
|
|
81
85
|
logger,
|
|
82
86
|
})
|
|
87
|
+
briefs = createBriefService({
|
|
88
|
+
ctx,
|
|
89
|
+
store,
|
|
90
|
+
scheduler,
|
|
91
|
+
now,
|
|
92
|
+
logger,
|
|
93
|
+
})
|
|
94
|
+
const boardService = createBoardService({
|
|
95
|
+
store,
|
|
96
|
+
scheduler,
|
|
97
|
+
now,
|
|
98
|
+
})
|
|
83
99
|
const service = createAutomationService({
|
|
84
100
|
store,
|
|
85
101
|
scheduler,
|
|
@@ -89,6 +105,8 @@ export function createAutomationRuntime(options) {
|
|
|
89
105
|
workspaces,
|
|
90
106
|
version,
|
|
91
107
|
settings: getSettings,
|
|
108
|
+
briefs,
|
|
109
|
+
boardService,
|
|
92
110
|
now,
|
|
93
111
|
})
|
|
94
112
|
runner.installListeners()
|
|
@@ -97,7 +115,7 @@ export function createAutomationRuntime(options) {
|
|
|
97
115
|
installAutomationPolicy({ ctx: toolsCtx, runner, logger })
|
|
98
116
|
})
|
|
99
117
|
}
|
|
100
|
-
return { store, runner, scheduler, service, calendar, workspaces, profile: { displayName, runDir, ownerDir } }
|
|
118
|
+
return { store, runner, scheduler, briefs, service, calendar, workspaces, profile: { displayName, runDir, ownerDir } }
|
|
101
119
|
}
|
|
102
120
|
|
|
103
121
|
function authorizeFactory(ctx) {
|
|
@@ -158,12 +176,16 @@ export function apply(ctx) {
|
|
|
158
176
|
})
|
|
159
177
|
activeService = created.service
|
|
160
178
|
created.scheduler.start()
|
|
161
|
-
.then(() =>
|
|
179
|
+
.then(() => {
|
|
180
|
+
created.briefs?.start()
|
|
181
|
+
logger?.info?.(`capital-automation: scheduler ${created.scheduler.status().state}`)
|
|
182
|
+
})
|
|
162
183
|
.catch((error) => logger?.error?.(`capital-automation: scheduler 启动失败:${String(error)}`))
|
|
163
184
|
appCtx.effect(() => async () => {
|
|
164
185
|
if (activeService === created.service) {
|
|
165
186
|
activeService = undefined
|
|
166
187
|
}
|
|
188
|
+
await created.briefs?.stop?.()
|
|
167
189
|
await created.scheduler.stop().catch(() => {})
|
|
168
190
|
created.calendar.dispose?.()
|
|
169
191
|
await created.runner.dispose?.()
|
package/automation/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v587d/capital-automation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "CapGen 投研自动化:独立 host bundle(固定 capital_automation 域、单 scheduler owner、/capital-automation 路由与浏览器页面)。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"store.js",
|
|
40
40
|
"service.js",
|
|
41
41
|
"runner.js",
|
|
42
|
+
"brief.js",
|
|
43
|
+
"board.js",
|
|
42
44
|
"scheduler.js",
|
|
43
45
|
"workspaces.js",
|
|
44
46
|
"contract.js",
|
package/automation/route.js
CHANGED
|
@@ -121,12 +121,12 @@ function decodeId(raw) {
|
|
|
121
121
|
return id
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function queryOf(url, allowedKeys) {
|
|
124
|
+
function queryOf(url, allowedKeys, maxKeys = MAX_QUERY_KEYS) {
|
|
125
125
|
const result = {}
|
|
126
126
|
let count = 0
|
|
127
127
|
for (const [key, value] of url.searchParams.entries()) {
|
|
128
128
|
count += 1
|
|
129
|
-
if (count >
|
|
129
|
+
if (count > maxKeys || !allowedKeys.has(key) || Object.prototype.hasOwnProperty.call(result, key)) {
|
|
130
130
|
throw new AutomationError('invalid_query', '查询参数无效。', 400)
|
|
131
131
|
}
|
|
132
132
|
if (value.length > MAX_QUERY_VALUE_CHARS) {
|
|
@@ -230,6 +230,13 @@ async function dispatch({ req, method, suffix, url, service, requestId }) {
|
|
|
230
230
|
if (suffix === WORKSPACES_SUFFIX && method === 'GET') {
|
|
231
231
|
return { body: await service.workspaceCatalog() }
|
|
232
232
|
}
|
|
233
|
+
if (suffix === '/board' && method === 'GET') {
|
|
234
|
+
return { body: await service.board(queryOf(url, new Set(['days', 'tz', 'limit', 'before', 'category']), 5)) }
|
|
235
|
+
}
|
|
236
|
+
const briefRetry = /^\/board\/briefs\/([^/]+)\/retry$/.exec(suffix)
|
|
237
|
+
if (briefRetry !== null && method === 'POST') {
|
|
238
|
+
return { body: await service.retryBrief(decodeId(briefRetry[1])), status: 202 }
|
|
239
|
+
}
|
|
233
240
|
if (suffix === '/runs' && method === 'GET') {
|
|
234
241
|
return { body: await service.listRuns(queryOf(url, new Set(['limit', 'before']))) }
|
|
235
242
|
}
|
package/automation/runner.js
CHANGED
|
@@ -116,7 +116,7 @@ ${task.instruction}
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
export function createRunRunner(options) {
|
|
119
|
-
const { ctx, store, settings, profile, workspaces, now = () => Date.now(), logger, random } = options
|
|
119
|
+
const { ctx, store, settings, profile, workspaces, onRunSucceeded, now = () => Date.now(), logger, random } = options
|
|
120
120
|
const entries = new Map()
|
|
121
121
|
const pendingDispatches = new Set()
|
|
122
122
|
const bySession = new Map()
|
|
@@ -317,7 +317,19 @@ export function createRunRunner(options) {
|
|
|
317
317
|
})
|
|
318
318
|
entries.delete(entry.id)
|
|
319
319
|
if (entry.sessionId !== undefined) bySession.delete(entry.sessionId)
|
|
320
|
-
|
|
320
|
+
const finalRun = updated ?? { ...entry.run, status }
|
|
321
|
+
try {
|
|
322
|
+
await notify(entry, finalRun)
|
|
323
|
+
} catch (error) {
|
|
324
|
+
logger?.warn?.(`capital-automation: run notification failed: ${String(error)}`)
|
|
325
|
+
}
|
|
326
|
+
if (finalRun.status === 'succeeded' && typeof onRunSucceeded === 'function') {
|
|
327
|
+
try {
|
|
328
|
+
await onRunSucceeded({ run: finalRun, task: entry.task })
|
|
329
|
+
} catch (error) {
|
|
330
|
+
logger?.warn?.(`capital-automation: brief enqueue failed: ${String(error)}`)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
321
333
|
}
|
|
322
334
|
|
|
323
335
|
async function notify(entry, run) {
|
package/automation/schema.js
CHANGED
|
@@ -278,6 +278,66 @@ export const NotificationSchema = z.strictObject({
|
|
|
278
278
|
readAt: isoInstant.optional(),
|
|
279
279
|
})
|
|
280
280
|
|
|
281
|
+
/** Derived task brief. One per successful run; storage validates it on every open. */
|
|
282
|
+
export const BriefItemSchema = z.strictObject({
|
|
283
|
+
kind: z.enum(['confirm', 'verify', 'track']),
|
|
284
|
+
title: z.string().min(1).max(40),
|
|
285
|
+
detail: z.string().max(120).optional(),
|
|
286
|
+
symbol: z.string().max(20).optional(),
|
|
287
|
+
trigger: z.string().max(80).optional(),
|
|
288
|
+
dueAt: z.string().refine(isCalendarDate, { message: 'must be a valid YYYY-MM-DD date' }).optional(),
|
|
289
|
+
dueLabel: z.string().max(20).optional(),
|
|
290
|
+
sourceQuote: z.string().min(1).max(160),
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
export const BriefStockSchema = z.strictObject({
|
|
294
|
+
symbol: z.string().min(1).max(20),
|
|
295
|
+
name: z.string().min(1).max(40),
|
|
296
|
+
roles: z.array(z.enum(['holding', 'watch', 'event', 'risk'])).min(1).max(3),
|
|
297
|
+
note: z.string().max(80).optional(),
|
|
298
|
+
nextAt: z.string().refine(isCalendarDate, { message: 'must be a valid YYYY-MM-DD date' }).optional(),
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
export const BriefGapSchema = z.strictObject({
|
|
302
|
+
kind: z.enum(['capability', 'transient', 'conflict', 'quality']),
|
|
303
|
+
topic: z.string().min(2).max(24),
|
|
304
|
+
detail: z.string().min(1).max(100),
|
|
305
|
+
sourceQuote: z.string().min(1).max(160),
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
export const TaskBriefSchema = z.strictObject({
|
|
309
|
+
schemaVersion: z.literal(1),
|
|
310
|
+
profileKey: z.string().min(1).max(80),
|
|
311
|
+
runId: z.string().min(1).max(80),
|
|
312
|
+
taskId: z.string().min(1).max(80),
|
|
313
|
+
sessionId: z.string().min(1).max(120).optional(),
|
|
314
|
+
status: z.enum(['pending', 'ready', 'failed', 'skipped']),
|
|
315
|
+
headline: z.string().min(4).max(24).optional(),
|
|
316
|
+
plain: z.string().min(40).max(200).optional(),
|
|
317
|
+
items: z.array(BriefItemSchema).max(6),
|
|
318
|
+
stocks: z.array(BriefStockSchema).max(8),
|
|
319
|
+
gaps: z.array(BriefGapSchema).max(6),
|
|
320
|
+
coverage: z.enum(['full', 'partial']).optional(),
|
|
321
|
+
model: z.string().max(120).optional(),
|
|
322
|
+
promptVersion: z.number().int().min(1).max(99),
|
|
323
|
+
sourceHash: z.string().regex(/^[a-f0-9]{16}$/).optional(),
|
|
324
|
+
error: z.string().max(300).optional(),
|
|
325
|
+
lastError: z.string().max(300).optional(),
|
|
326
|
+
lastErrorAt: isoInstant.optional(),
|
|
327
|
+
attempts: z.number().int().min(0).max(5),
|
|
328
|
+
generatedAt: isoInstant.optional(),
|
|
329
|
+
updatedAt: isoInstant,
|
|
330
|
+
}).superRefine((brief, ctx) => {
|
|
331
|
+
if (brief.status === 'ready') {
|
|
332
|
+
if (brief.headline === undefined) ctx.addIssue({ code: 'custom', path: ['headline'], message: 'ready brief requires headline' })
|
|
333
|
+
if (brief.plain === undefined) ctx.addIssue({ code: 'custom', path: ['plain'], message: 'ready brief requires plain' })
|
|
334
|
+
} else if (brief.status === 'failed') {
|
|
335
|
+
if (brief.error === undefined) ctx.addIssue({ code: 'custom', path: ['error'], message: 'failed brief requires error' })
|
|
336
|
+
} else if (brief.headline !== undefined || brief.plain !== undefined) {
|
|
337
|
+
ctx.addIssue({ code: 'custom', message: `${brief.status} brief must not carry headline/plain` })
|
|
338
|
+
}
|
|
339
|
+
})
|
|
340
|
+
|
|
281
341
|
export const OwnerRecordSchema = z.strictObject({
|
|
282
342
|
schemaVersion: z.literal(1),
|
|
283
343
|
profileKey: z.string().min(1).max(80),
|
package/automation/service.js
CHANGED
|
@@ -104,7 +104,7 @@ export class AutomationError extends Error {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
export function createAutomationService(options) {
|
|
107
|
-
const { store, scheduler, runner, calendar, profile, workspaces, version, settings, now = () => Date.now() } = options
|
|
107
|
+
const { store, scheduler, runner, calendar, profile, workspaces, version, settings, briefs, boardService, now = () => Date.now() } = options
|
|
108
108
|
let chain = Promise.resolve()
|
|
109
109
|
|
|
110
110
|
function serialize(operation) {
|
|
@@ -372,6 +372,33 @@ export function createAutomationService(options) {
|
|
|
372
372
|
return { days: buckets, total, success, failure }
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
async function board(query = {}) {
|
|
376
|
+
if (boardService === undefined || typeof boardService.board !== 'function') {
|
|
377
|
+
throw new AutomationError('board_unavailable', '看板服务暂时不可用。', 503)
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
return await boardService.board(query)
|
|
381
|
+
} catch (error) {
|
|
382
|
+
if (error?.boardError === true) throw new AutomationError(error.code, error.message, error.status ?? 400)
|
|
383
|
+
throw error
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
async function retryBrief(runId) {
|
|
388
|
+
if (briefs === undefined || typeof briefs.retry !== 'function') {
|
|
389
|
+
throw new AutomationError('brief_not_found', '任务简报服务暂时不可用。', 503)
|
|
390
|
+
}
|
|
391
|
+
const result = await briefs.retry(runId)
|
|
392
|
+
if (result?.ok !== true) {
|
|
393
|
+
throw new AutomationError(
|
|
394
|
+
result?.code ?? 'brief_not_retryable',
|
|
395
|
+
result?.message ?? '这条任务简报暂时不能重试。',
|
|
396
|
+
result?.status ?? 409,
|
|
397
|
+
)
|
|
398
|
+
}
|
|
399
|
+
return { queued: true }
|
|
400
|
+
}
|
|
401
|
+
|
|
375
402
|
async function listNotifications(query = {}) {
|
|
376
403
|
let unreadOnly = false
|
|
377
404
|
if (query.unread !== undefined) {
|
|
@@ -416,6 +443,8 @@ export function createAutomationService(options) {
|
|
|
416
443
|
getRun,
|
|
417
444
|
listRuns,
|
|
418
445
|
runHistory,
|
|
446
|
+
board,
|
|
447
|
+
retryBrief,
|
|
419
448
|
listNotifications,
|
|
420
449
|
markNotificationsRead,
|
|
421
450
|
storageState: async () => {
|
package/automation/store.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
OwnerRecordSchema,
|
|
13
13
|
RunRecordSchema,
|
|
14
14
|
TaskConfigSchema,
|
|
15
|
+
TaskBriefSchema,
|
|
15
16
|
TaskOverridesSchema,
|
|
16
17
|
TaskRecordSchema,
|
|
17
18
|
isActiveRun,
|
|
@@ -46,6 +47,7 @@ export const domainSpec = {
|
|
|
46
47
|
attempts: { valueSchema: AttemptRecordSchema },
|
|
47
48
|
notifications: { valueSchema: NotificationSchema },
|
|
48
49
|
meta: { valueSchema: OwnerRecordSchema },
|
|
50
|
+
briefs: { valueSchema: TaskBriefSchema },
|
|
49
51
|
},
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -181,6 +183,7 @@ export function createAutomationStore(options) {
|
|
|
181
183
|
attempts: domain.table('attempts'),
|
|
182
184
|
notifications: domain.table('notifications'),
|
|
183
185
|
meta: domain.table('meta'),
|
|
186
|
+
briefs: domain.table('briefs'),
|
|
184
187
|
}
|
|
185
188
|
})()
|
|
186
189
|
}
|
|
@@ -201,6 +204,10 @@ export function createAutomationStore(options) {
|
|
|
201
204
|
return record !== undefined && record.profileKey === profileKey
|
|
202
205
|
}
|
|
203
206
|
|
|
207
|
+
function ownBrief(record) {
|
|
208
|
+
return record !== undefined && record.profileKey === profileKey
|
|
209
|
+
}
|
|
210
|
+
|
|
204
211
|
async function seedBuiltins(tables) {
|
|
205
212
|
const at = iso(now())
|
|
206
213
|
for (const definition of builtins) {
|
|
@@ -397,6 +404,11 @@ export function createAutomationStore(options) {
|
|
|
397
404
|
await tables.notifications.delete(notificationId)
|
|
398
405
|
}
|
|
399
406
|
}
|
|
407
|
+
for (const [briefId, brief] of [...tables.briefs.entries()]) {
|
|
408
|
+
if (ownBrief(brief) && (brief.taskId === id || runIds.has(brief.runId))) {
|
|
409
|
+
await tables.briefs.delete(briefId)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
400
412
|
return tables.tasks.delete(id)
|
|
401
413
|
}
|
|
402
414
|
|
|
@@ -544,7 +556,11 @@ export function createAutomationStore(options) {
|
|
|
544
556
|
perTask.set(run.taskId, count)
|
|
545
557
|
if (index >= MAX_RUNS_PER_PROFILE || count > MAX_RUNS_PER_TASK) doomed.add(run.id)
|
|
546
558
|
})
|
|
547
|
-
for (const id of doomed)
|
|
559
|
+
for (const id of doomed) {
|
|
560
|
+
await tables.runs.delete(id)
|
|
561
|
+
const brief = tables.briefs.get(id)
|
|
562
|
+
if (ownBrief(brief)) await tables.briefs.delete(id)
|
|
563
|
+
}
|
|
548
564
|
}
|
|
549
565
|
|
|
550
566
|
async function claimOccurrence(input) {
|
|
@@ -671,6 +687,122 @@ export function createAutomationStore(options) {
|
|
|
671
687
|
return changed
|
|
672
688
|
}
|
|
673
689
|
|
|
690
|
+
async function createBrief(input) {
|
|
691
|
+
const tables = await ensure()
|
|
692
|
+
const existing = tables.briefs.get(input.runId)
|
|
693
|
+
if (existing !== undefined) return ownBrief(existing) ? existing : undefined
|
|
694
|
+
const at = iso(now())
|
|
695
|
+
const record = parseStrict(TaskBriefSchema, {
|
|
696
|
+
schemaVersion: 1,
|
|
697
|
+
profileKey,
|
|
698
|
+
runId: input.runId,
|
|
699
|
+
taskId: input.taskId,
|
|
700
|
+
...(input.sessionId === undefined ? {} : { sessionId: input.sessionId }),
|
|
701
|
+
status: 'pending',
|
|
702
|
+
items: [],
|
|
703
|
+
stocks: [],
|
|
704
|
+
gaps: [],
|
|
705
|
+
promptVersion: input.promptVersion ?? 1,
|
|
706
|
+
attempts: 0,
|
|
707
|
+
updatedAt: at,
|
|
708
|
+
}, 'brief')
|
|
709
|
+
await tables.briefs.put(record.runId, record)
|
|
710
|
+
return record
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
async function putBrief(record) {
|
|
714
|
+
const tables = await ensure()
|
|
715
|
+
const clean = parseStrict(TaskBriefSchema, { ...record, profileKey }, 'brief')
|
|
716
|
+
await tables.briefs.put(clean.runId, clean)
|
|
717
|
+
return clean
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
async function getBrief(runId) {
|
|
721
|
+
const tables = await ensure()
|
|
722
|
+
const record = tables.briefs.get(runId)
|
|
723
|
+
return ownBrief(record) ? record : undefined
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
async function listBriefsForRuns(runIds) {
|
|
727
|
+
const tables = await ensure()
|
|
728
|
+
const result = new Map()
|
|
729
|
+
for (const runId of runIds) {
|
|
730
|
+
const record = tables.briefs.get(runId)
|
|
731
|
+
if (ownBrief(record)) result.set(runId, record)
|
|
732
|
+
}
|
|
733
|
+
return result
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
async function listBriefsForProfile() {
|
|
737
|
+
const tables = await ensure()
|
|
738
|
+
const records = []
|
|
739
|
+
for (const [, record] of tables.briefs.entries()) if (ownBrief(record)) records.push(record)
|
|
740
|
+
records.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt) || left.runId.localeCompare(right.runId))
|
|
741
|
+
return records
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
async function countBriefs() {
|
|
745
|
+
const tables = await ensure()
|
|
746
|
+
let count = 0
|
|
747
|
+
for (const [, record] of tables.briefs.entries()) if (ownBrief(record)) count += 1
|
|
748
|
+
return count
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
async function updateBrief(runId, patch) {
|
|
752
|
+
const tables = await ensure()
|
|
753
|
+
const current = tables.briefs.get(runId)
|
|
754
|
+
if (!ownBrief(current)) return undefined
|
|
755
|
+
const next = {
|
|
756
|
+
...current,
|
|
757
|
+
...patch,
|
|
758
|
+
profileKey,
|
|
759
|
+
updatedAt: iso(now()),
|
|
760
|
+
}
|
|
761
|
+
if (next.status === 'pending') {
|
|
762
|
+
if (typeof current.error === 'string' && current.error.length > 0) {
|
|
763
|
+
next.lastError = current.error
|
|
764
|
+
next.lastErrorAt = iso(now())
|
|
765
|
+
}
|
|
766
|
+
delete next.headline
|
|
767
|
+
delete next.plain
|
|
768
|
+
delete next.error
|
|
769
|
+
delete next.generatedAt
|
|
770
|
+
next.items = []
|
|
771
|
+
next.stocks = []
|
|
772
|
+
next.gaps = []
|
|
773
|
+
}
|
|
774
|
+
const clean = parseStrict(TaskBriefSchema, next, 'brief')
|
|
775
|
+
await tables.briefs.put(runId, clean)
|
|
776
|
+
return clean
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
async function deleteBrief(runId) {
|
|
780
|
+
const tables = await ensure()
|
|
781
|
+
const current = tables.briefs.get(runId)
|
|
782
|
+
if (!ownBrief(current)) return false
|
|
783
|
+
return tables.briefs.delete(runId)
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
function publicBrief(brief) {
|
|
787
|
+
return {
|
|
788
|
+
runId: brief.runId,
|
|
789
|
+
taskId: brief.taskId,
|
|
790
|
+
sessionId: brief.sessionId ?? null,
|
|
791
|
+
status: brief.status,
|
|
792
|
+
headline: brief.headline ?? null,
|
|
793
|
+
plain: brief.plain ?? null,
|
|
794
|
+
coverage: brief.coverage ?? null,
|
|
795
|
+
error: brief.error ?? null,
|
|
796
|
+
attempts: brief.attempts,
|
|
797
|
+
generatedAt: brief.generatedAt ?? null,
|
|
798
|
+
counts: {
|
|
799
|
+
items: brief.items.length,
|
|
800
|
+
stocks: brief.stocks.length,
|
|
801
|
+
gaps: brief.gaps.length,
|
|
802
|
+
},
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
674
806
|
async function setOwnerMeta(record) {
|
|
675
807
|
const tables = await ensure()
|
|
676
808
|
const clean = parseStrict(OwnerRecordSchema, record, 'owner meta')
|
|
@@ -811,6 +943,15 @@ export function createAutomationStore(options) {
|
|
|
811
943
|
hasAttempt,
|
|
812
944
|
setAttemptState,
|
|
813
945
|
listAttemptsForRun,
|
|
946
|
+
createBrief,
|
|
947
|
+
putBrief,
|
|
948
|
+
getBrief,
|
|
949
|
+
listBriefsForRuns,
|
|
950
|
+
listBriefsForProfile,
|
|
951
|
+
countBriefs,
|
|
952
|
+
updateBrief,
|
|
953
|
+
deleteBrief,
|
|
954
|
+
publicBrief,
|
|
814
955
|
addNotification,
|
|
815
956
|
listNotifications,
|
|
816
957
|
unreadNotificationCount,
|
package/chart-ui/package.json
CHANGED
package/config/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Known limit: DNS resolves per request but the IP is not pinned to the connection,
|
|
4
4
|
* so a rebinding window remains (same trade-off as dsh-search-first).
|
|
5
5
|
*/
|
|
6
|
-
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.
|
|
6
|
+
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.17.0";
|
|
7
7
|
export declare const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
|
|
8
8
|
export type LocalFetchErrorCode = 'ABORTED' | 'TIMEOUT' | 'INVALID_URL' | 'BLOCKED_URL' | 'DNS' | 'REDIRECT' | 'HTTP' | 'TOO_LARGE' | 'UNSUPPORTED_CONTENT_TYPE';
|
|
9
9
|
export declare class LocalFetchError extends Error {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* so a rebinding window remains (same trade-off as dsh-search-first).
|
|
5
5
|
*/
|
|
6
6
|
import { htmlToMarkdown, stripInvisibleText } from './html-markdown.js';
|
|
7
|
-
export const LOCAL_FETCH_CLIENT_VERSION = '2.
|
|
7
|
+
export const LOCAL_FETCH_CLIENT_VERSION = '2.17.0';
|
|
8
8
|
export const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
|
|
9
9
|
export class LocalFetchError extends Error {
|
|
10
10
|
code;
|
|
@@ -967,7 +967,7 @@ export async function eastmoneyAnnouncements(client, input) {
|
|
|
967
967
|
const offset = Number.isSafeInteger(input.cursor) && input.cursor >= 0 ? input.cursor : 0;
|
|
968
968
|
const items = sorted.slice(offset, offset + input.pageSize);
|
|
969
969
|
const windowOutOfRange = !reachedOlder && oldestScanned !== undefined && oldestScanned > end;
|
|
970
|
-
const notes = ['
|
|
970
|
+
const notes = ['东财公告是官方披露的转载;正文/PDF 可作公告事实的权威引用(authoritative_reprint),verified_official 仍只给官方域名;正文用 eastmoney_announcement_body;窗口按 display_time(北京时间)过滤'];
|
|
971
971
|
if (sorted.length === 0 && !windowOutOfRange)
|
|
972
972
|
notes.push('窗口内没有公告(合法空结果;东财列表只覆盖最近若干页)');
|
|
973
973
|
if (windowOutOfRange) {
|
|
@@ -1018,6 +1018,7 @@ export async function eastmoneyAnnouncementBody(client, input) {
|
|
|
1018
1018
|
const pdfUrl = itemUrl(data.attach_url_web ?? data.attach_url);
|
|
1019
1019
|
const title = clip(data.notice_title);
|
|
1020
1020
|
const noticeDate = clip(data.notice_date);
|
|
1021
|
+
const aiSummary = Number(data.is_ai_summary) === 1;
|
|
1021
1022
|
const base = {
|
|
1022
1023
|
source: 'eastmoney',
|
|
1023
1024
|
operation: 'announcement_body',
|
|
@@ -1026,6 +1027,7 @@ export async function eastmoneyAnnouncementBody(client, input) {
|
|
|
1026
1027
|
offset: input.offset,
|
|
1027
1028
|
page_chars: content.length,
|
|
1028
1029
|
total_pages: totalPages,
|
|
1030
|
+
is_ai_summary: aiSummary,
|
|
1029
1031
|
...(pdfUrl.length > 0 ? { pdf_url: pdfUrl } : {}),
|
|
1030
1032
|
...(title.length > 0 ? { title } : {}),
|
|
1031
1033
|
...(noticeDate.length > 0 ? { notice_date: noticeDate } : {}),
|
|
@@ -1035,7 +1037,7 @@ export async function eastmoneyAnnouncementBody(client, input) {
|
|
|
1035
1037
|
...base,
|
|
1036
1038
|
content: '',
|
|
1037
1039
|
done: true,
|
|
1038
|
-
note:
|
|
1040
|
+
note: `该公告正文接口没有返回文本(美股公告常见;若为 A/H 公告,可能是上游结构变更);正文在附件:PDF 交 ocr,.html 用 web_retriever_fetch,别把标题当正文${aiSummary ? ';东财标记为 AI 摘要(is_ai_summary=1),不是全文' : ''}`,
|
|
1039
1041
|
};
|
|
1040
1042
|
}
|
|
1041
1043
|
if (page > totalPages) {
|
|
@@ -1059,8 +1061,10 @@ export async function eastmoneyAnnouncementBody(client, input) {
|
|
|
1059
1061
|
const notes = [];
|
|
1060
1062
|
if (totalPages > 1)
|
|
1061
1063
|
notes.push(`全文共 ${totalPages} 页(每页约 5,000 字符);用 next_offset / next_page 继续读`);
|
|
1064
|
+
if (aiSummary)
|
|
1065
|
+
notes.push('东财标记为 AI 摘要(is_ai_summary=1),不是公告全文;全文用 pdf_url + ocr');
|
|
1062
1066
|
if (pdfUrl.length > 0)
|
|
1063
|
-
notes.push('PDF
|
|
1067
|
+
notes.push('附件直链在 pdf_url(可能是 .html;PDF 交 ocr,HTML 用 web_retriever_fetch);verified_official 仍只给官方域名');
|
|
1064
1068
|
return {
|
|
1065
1069
|
...base,
|
|
1066
1070
|
content: slice,
|
|
@@ -169,7 +169,7 @@ export function registerSearchTools(ctx, retriever, windClient, echo = createRet
|
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
name: WIND_ANNOUNCEMENTS_TOOL,
|
|
172
|
-
description: 'Wind 官方文档库的公告语义检索(public_document,**按次计费**),只作深研备用。⛔ 公告清单不要用它:先 eastmoney_announcements(零 key、发行人限定、按披露时间窗完整列出);实测 Wind 的自然语言检索会漏最新公告、把关联方/别家公司文件排进来。本工具只适合“按语义找一段话”或东财覆盖不到的材料。query 必须一次带齐三要素:公司实体(代码或全称)、文件类型、时间范围;禁止无主体泛查询。返回内容标注“来源:万得 Wind
|
|
172
|
+
description: 'Wind 官方文档库的公告语义检索(public_document,**按次计费**),只作深研备用。⛔ 公告清单不要用它:先 eastmoney_announcements(零 key、发行人限定、按披露时间窗完整列出);实测 Wind 的自然语言检索会漏最新公告、把关联方/别家公司文件排进来。本工具只适合“按语义找一段话”或东财覆盖不到的材料。query 必须一次带齐三要素:公司实体(代码或全称)、文件类型、时间范围;禁止无主体泛查询。返回内容标注“来源:万得 Wind 金融数据服务”与时间口径;公告清单/正文优先东财,公告引用标 authoritative_reprint,官方域名核验才走巨潮/发行人。消耗积分,按需少量调用;AUTH/RATE_LIMIT 等错误不得重试。',
|
|
173
173
|
parameters: jsonObject({
|
|
174
174
|
query: { type: 'string', description: '自然语言检索要求;必须包含公司实体(股票代码或公司全称)、文件类型与时间范围三要素,最多 500 字符' },
|
|
175
175
|
top_k: { type: 'integer', description: '可选,返回相关文档最大数量 1~10,默认 5' },
|
|
@@ -913,7 +913,7 @@ export function registerSourceTools(ctx, localFetchOptions) {
|
|
|
913
913
|
const definitions = [
|
|
914
914
|
{
|
|
915
915
|
name: 'cls_telegraph',
|
|
916
|
-
description: '取财联社 7×24 全市场快讯(直连 cls.cn v1 接口,签名由本工具本地计算,零 key)。这是**确定性来源查询**而非检索:返回最近 limit 条快讯,含时间、标题、正文与原文链接。财联社是媒体来源,内容只能作为「媒体转述旁证」,不得标 verified_official;官方公告请用
|
|
916
|
+
description: '取财联社 7×24 全市场快讯(直连 cls.cn v1 接口,签名由本工具本地计算,零 key)。这是**确定性来源查询**而非检索:返回最近 limit 条快讯,含时间、标题、正文与原文链接。财联社是媒体来源,内容只能作为「媒体转述旁证」,不得标 verified_official;官方公告请用 eastmoney_announcements(正文/PDF 标 authoritative_reprint)。与 wscn_lives / eastmoney_724 互为独立备份。',
|
|
917
917
|
parameters: jsonObject({
|
|
918
918
|
limit: { type: 'integer', description: '可选,返回快讯条数 1~50,默认 20' },
|
|
919
919
|
}, []),
|
|
@@ -1021,7 +1021,7 @@ export function registerSourceTools(ctx, localFetchOptions) {
|
|
|
1021
1021
|
},
|
|
1022
1022
|
{
|
|
1023
1023
|
name: 'eastmoney_announcements',
|
|
1024
|
-
description: '取东方财富公告列表(确定性来源查询,零 key;一次只查一个市场)。codes 传 1~50 只批量代码;start_date/end_date 是披露时间窗口(按 display_time 的北京时间日期,含首尾,最长 31 天)。返回 code/name/date/title/category/art_code/url
|
|
1024
|
+
description: '取东方财富公告列表(确定性来源查询,零 key;一次只查一个市场)。codes 传 1~50 只批量代码;start_date/end_date 是披露时间窗口(按 display_time 的北京时间日期,含首尾,最长 31 天)。返回 code/name/market/date/published_at/title/category/art_code/url,按发布时间倒序;published_at 是完整时分,盘前窗口按它过滤;翻页把回执的 next_cursor 原样传回 cursor。⛔ 公告清单默认走本工具,不要用 wind_docs 的语义检索代替:实测 Wind 会漏最新公告、混入关联方/其他公司。⛔ 东财公告是官方披露的转载;正文/PDF 可作公告事实的权威引用(authoritative_reprint),但 verified_official 仍只给官方域名核验;正文用 eastmoney_announcement_body。⛔ 盘前公告的 start_date 要取上一交易日(display_time 在收盘后仍算当日),end_date 取运行日;只查运行日会漏掉昨晚盘后披露。窗口内没有公告是合法空结果,不是失败。',
|
|
1025
1025
|
parameters: jsonObject({
|
|
1026
1026
|
codes: { type: 'array', items: { type: 'string', description: 'A 股 6 位(600519 / 600519.SH)、港股 5 位(00700 / 0700.HK)、美股 ticker(AAPL / AAPL.O);一次只查一个市场,1~50 只;整张自选股一次批量传,不要逐只调用' } },
|
|
1027
1027
|
market: { type: 'string', enum: ['auto', 'A', 'H', 'U'], description: '可选,默认 auto 按代码形状推断;混合市场会报错,请分开调用' },
|
|
@@ -1064,7 +1064,7 @@ export function registerSourceTools(ctx, localFetchOptions) {
|
|
|
1064
1064
|
},
|
|
1065
1065
|
{
|
|
1066
1066
|
name: 'eastmoney_announcement_body',
|
|
1067
|
-
description: '读东方财富公告正文(按 art_code)。上游每页最多 5,000 字符,本工具用 page + offset 返回最多 4,000 字符/次;回执给 content/content_chars/next_offset/next_page/done/total_pages/pdf_url。art_code 从 eastmoney_announcements 回执复制,不要自己拼。⛔
|
|
1067
|
+
description: '读东方财富公告正文(按 art_code)。上游每页最多 5,000 字符,本工具用 page + offset 返回最多 4,000 字符/次;回执给 content/content_chars/next_offset/next_page/done/total_pages/pdf_url/is_ai_summary。art_code 从 eastmoney_announcements 回执复制,不要自己拼。⛔ 美股公告正文常为空(只有附件):此时 content 为空、done=true;pdf_url 可能是 .html,PDF 交 ocr、HTML 用 web_retriever_fetch,别把标题当正文。港股正文是繁体原文。⛔ 正文/PDF 可作公告事实的权威引用,标「公告原文(东财转载,authoritative_reprint)」;is_ai_summary=1 只是摘要,全文转 PDF/ocr;verified_official 仍只给官方域名。⛔ notice_date 只有日期,时分用列表的 published_at。',
|
|
1068
1068
|
parameters: jsonObject({
|
|
1069
1069
|
art_code: { type: 'string', description: '公告标识,形如 AN202611021831320924,来自 eastmoney_announcements 回执' },
|
|
1070
1070
|
page: { type: 'integer', description: '可选,上游正文页号(1 起),默认 1;先按 next_page 翻' },
|
|
@@ -1086,6 +1086,7 @@ export function registerSourceTools(ctx, localFetchOptions) {
|
|
|
1086
1086
|
offset: { type: 'integer' },
|
|
1087
1087
|
page_chars: { type: 'integer' },
|
|
1088
1088
|
total_pages: { type: 'integer' },
|
|
1089
|
+
is_ai_summary: { type: 'boolean' },
|
|
1089
1090
|
content: { type: 'string' },
|
|
1090
1091
|
content_chars: { type: 'integer' },
|
|
1091
1092
|
next_offset: { type: 'integer' },
|
|
@@ -1129,6 +1130,7 @@ export function registerSourceTools(ctx, localFetchOptions) {
|
|
|
1129
1130
|
offset: body.offset,
|
|
1130
1131
|
page_chars: body.page_chars,
|
|
1131
1132
|
total_pages: body.total_pages,
|
|
1133
|
+
is_ai_summary: body.is_ai_summary,
|
|
1132
1134
|
...(body.title === undefined ? {} : { title: body.title }),
|
|
1133
1135
|
...(body.notice_date === undefined ? {} : { notice_date: body.notice_date }),
|
|
1134
1136
|
...(body.pdf_url === undefined ? {} : { pdf_url: body.pdf_url }),
|
|
@@ -35,7 +35,7 @@ export interface WindCallResult {
|
|
|
35
35
|
code?: WindErrorCode;
|
|
36
36
|
}
|
|
37
37
|
/** Must match `package.json` version; a test pins the two together. */
|
|
38
|
-
export declare const WIND_CLIENT_VERSION = "2.
|
|
38
|
+
export declare const WIND_CLIENT_VERSION = "2.17.0";
|
|
39
39
|
export interface WindClient {
|
|
40
40
|
callTool(toolName: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<WindCallResult>;
|
|
41
41
|
}
|
|
@@ -19,7 +19,7 @@ export const WIND_SERVER_ENDPOINTS = {
|
|
|
19
19
|
analytics_data: 'https://mcp.wind.com.cn/vserver_analytics_data/mcp/',
|
|
20
20
|
};
|
|
21
21
|
/** Must match `package.json` version; a test pins the two together. */
|
|
22
|
-
export const WIND_CLIENT_VERSION = '2.
|
|
22
|
+
export const WIND_CLIENT_VERSION = '2.17.0';
|
|
23
23
|
function errorText(error) {
|
|
24
24
|
return error instanceof Error ? error.message : String(error);
|
|
25
25
|
}
|