@v587d/capital-generation 2.16.1 → 2.18.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 +75 -0
- package/README.md +11 -5
- package/automation/board.js +461 -0
- package/automation/brief.js +779 -0
- 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/agents/role-tool-policy.d.ts +5 -4
- package/lib/agents/role-tool-policy.js +9 -4
- package/lib/chart/delivery.d.ts +8 -7
- package/lib/chart/present-tool.d.ts +5 -4
- package/lib/present-entry.d.ts +5 -3
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +10 -10
- package/preset/capital-generation/README.md +8 -6
- package/preset/capital-generation/agent.patch.yml +7 -6
- 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.18.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
|
@@ -6,15 +6,16 @@
|
|
|
6
6
|
import type { AgentLike, GuardedExecution, PolicyContext } from './root-tool-policy.js';
|
|
7
7
|
import { type RolePresetId } from '../preset-ids.js';
|
|
8
8
|
export { ROLE_PRESET_IDS, ROLE_PRESET_ID_LIST, type RolePresetId } from '../preset-ids.js';
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/** Registered together with `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny these by name.
|
|
10
|
+
* 0.2.2 moved `list_agents` into the same main entry, so the welded set grew from one to two names. */
|
|
11
|
+
export declare const SIBLING_DENIED_TOOLS: readonly ["interrupt_agent", "list_agents"];
|
|
11
12
|
/** Residual surface; no allow list: family rows define the tool surface. */
|
|
12
13
|
export interface RoleSurface {
|
|
13
14
|
/** Sibling names welded into a needed row that this persona must not have. */
|
|
14
15
|
readonly denySiblings?: readonly string[];
|
|
15
16
|
}
|
|
16
|
-
/** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent`;
|
|
17
|
-
* mounts no control row. Tolerant per-name deny records misses without failing open. */
|
|
17
|
+
/** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents`;
|
|
18
|
+
* specialist mounts no control row. Tolerant per-name deny records misses without failing open. */
|
|
18
19
|
export declare const ROLE_TOOL_SURFACES: Record<RolePresetId, RoleSurface>;
|
|
19
20
|
/** Role preset id only, undefined for root and other presets; failure means "do not converge". */
|
|
20
21
|
export declare function rolePresetIdOf(ctx: PolicyContext, agent: AgentLike | undefined): RolePresetId | undefined;
|
|
@@ -7,10 +7,11 @@ import { isRootAgent, recordGuardDecision } from './root-tool-policy.js';
|
|
|
7
7
|
import { readPresetClaim } from '../preset-claim.js';
|
|
8
8
|
import { ROLE_PRESET_ID_LIST, ROLE_PRESET_IDS } from '../preset-ids.js';
|
|
9
9
|
export { ROLE_PRESET_IDS, ROLE_PRESET_ID_LIST } from '../preset-ids.js';
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** Registered together with `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny these by name.
|
|
11
|
+
* 0.2.2 moved `list_agents` into the same main entry, so the welded set grew from one to two names. */
|
|
12
|
+
export const SIBLING_DENIED_TOOLS = ['interrupt_agent', 'list_agents'];
|
|
13
|
+
/** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents`;
|
|
14
|
+
* specialist mounts no control row. Tolerant per-name deny records misses without failing open. */
|
|
14
15
|
export const ROLE_TOOL_SURFACES = {
|
|
15
16
|
[ROLE_PRESET_IDS.collector]: { denySiblings: SIBLING_DENIED_TOOLS },
|
|
16
17
|
[ROLE_PRESET_IDS.junior]: { denySiblings: SIBLING_DENIED_TOOLS },
|
|
@@ -76,6 +77,10 @@ export function roleSiblingGuardReasonFor(ctx) {
|
|
|
76
77
|
return undefined;
|
|
77
78
|
if (!ROLE_PRESET_ID_LIST.includes(claim.claim))
|
|
78
79
|
return undefined;
|
|
80
|
+
if (name === 'list_agents') {
|
|
81
|
+
return `${name} 不对人设 ${claim.claim} 开放:叶子角色只回传自己的结果,子 Agent 名单与调度归主 Agent。`
|
|
82
|
+
+ '需要别的 Agent 配合,用 send_message 回告主 Agent;不要自己换工具硬做。';
|
|
83
|
+
}
|
|
79
84
|
return `${name} 不对人设 ${claim.claim} 开放:叶子角色只回传自己的结果,打断别的会话归主 Agent 决定。`
|
|
80
85
|
+ '需要别的 Agent 停下来,用 send_message 回告主 Agent;不要自己换工具硬做。';
|
|
81
86
|
};
|
package/lib/chart/delivery.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chart delivery at the closing answer.
|
|
3
3
|
*
|
|
4
|
-
* DSH's deliverable card
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* appends the message after the stream ends.
|
|
8
|
-
* root session being idle (no actionable inbox
|
|
9
|
-
* the shape of a closing turn.
|
|
4
|
+
* DSH's deliverable card replays `deliverables/presented` from the closing turn (0.2.2 dropped the
|
|
5
|
+
* `file.seq < owner.seq` filter, so late declarations are no longer lost). A turn is still final
|
|
6
|
+
* only after the fact, and the one place where that is knowable before the turn closes is the
|
|
7
|
+
* assistant stream's terminal `finish` chunk: the loop appends the message after the stream ends.
|
|
8
|
+
* So delivery is deferred to that chunk, gated on the root session being idle (no actionable inbox
|
|
9
|
+
* input, no running direct children), which is exactly the shape of a closing turn.
|
|
10
|
+
* Waiting/aborted/tool-call responses never flush.
|
|
10
11
|
*
|
|
11
12
|
* `subagent-settled` notices are not actionable input: they can arrive while the closing answer is
|
|
12
13
|
* already streaming. Counting them as pending would strand a card that the model has just selected,
|
|
@@ -46,7 +47,7 @@ interface InboxStateLike {
|
|
|
46
47
|
}
|
|
47
48
|
export interface ChartDeliveryOptions {
|
|
48
49
|
artifacts: ChartArtifactRegistry;
|
|
49
|
-
/** Writes one first-party deliverables/presented batch; must be synchronous (
|
|
50
|
+
/** Writes one first-party deliverables/presented batch; must be synchronous (listener runs before the message commits). */
|
|
50
51
|
publish: (sessionId: string, inputs: ChartTurnEventInput[]) => boolean;
|
|
51
52
|
/** Durable pending input; synchronous projection read. Absent means "cannot tell" → proceed. */
|
|
52
53
|
inboxOf?: (session: SessionLike) => InboxStateLike | undefined;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* present_charts: the root Agent's final-turn delivery step.
|
|
3
3
|
*
|
|
4
4
|
* render_chart only mints a chart_ref (the specialist row no longer auto-delivers). DSH's
|
|
5
|
-
* deliverable card replays
|
|
6
|
-
* the card has to be
|
|
7
|
-
*
|
|
8
|
-
* event type — the session-event
|
|
5
|
+
* deliverable card replays declarations from the whole closing turn (0.2.2 dropped the
|
|
6
|
+
* `file.seq < owner.seq` filter), but the card still has to be attributed to the turn that
|
|
7
|
+
* carries the final answer: the root Agent presents its collected refs/deliverables here
|
|
8
|
+
* immediately before writing that answer. Never a custom event type — the session-event
|
|
9
|
+
* vocabulary is closed (see events.ts).
|
|
9
10
|
*/
|
|
10
11
|
import type { Context } from '@deepseek-ai/cordis';
|
|
11
12
|
import type { ChartArtifactRegistry } from './artifact-ref.js';
|
package/lib/present-entry.d.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The model only records which charts belong to the answer. The actual first-party
|
|
5
5
|
* `deliverables/presented` append happens in the terminal assistant-stream chunk, before the closing
|
|
6
|
-
* message commits, gated on an idle root (no actionable inbox input, no running direct children).
|
|
7
|
-
* point where "the final answer" is knowable, so early/no `present_charts` calls
|
|
8
|
-
* card in a folded process turn (rationale: docs/dev/chart-delivery-events.md §6.3).
|
|
6
|
+
* message commits, gated on an idle root (no actionable inbox input, no running direct children).
|
|
7
|
+
* That is the first point where "the final answer" is knowable, so early/no `present_charts` calls
|
|
8
|
+
* cannot strand the card in a folded process turn (rationale: docs/dev/chart-delivery-events.md §6.3).
|
|
9
|
+
* 0.2.2 made the client replay the whole turn, so this write point is about turn attribution and
|
|
10
|
+
* ordering, not about dodging a seq cutoff.
|
|
9
11
|
*/
|
|
10
12
|
import type { Context } from '@deepseek-ai/cordis';
|
|
11
13
|
import type { SessionLike } from './data-collector/store.js';
|
|
@@ -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.18.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.18.0';
|
|
8
8
|
export const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
|
|
9
9
|
export class LocalFetchError extends Error {
|
|
10
10
|
code;
|
|
@@ -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.18.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.18.0';
|
|
23
23
|
function errorText(error) {
|
|
24
24
|
return error instanceof Error ? error.message : String(error);
|
|
25
25
|
}
|