Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
王蔡翾
rz-GB-web
Commits
969193af
Commit
969193af
authored
Nov 11, 2026
by
王蔡翾
Browse files
bug修复
parent
f402273d
Changes
12
Show whitespace changes
Inline
Side-by-side
scripts/verify-prototype.mjs
View file @
969193af
import
assert
from
'
node:assert/strict
'
import
assert
from
'
node:assert/strict
'
import
{
extractProfileFromText
}
from
'
../src/lib/profileImport.ts
'
import
{
extractProfileFromText
}
from
'
../src/lib/profileImport.ts
'
import
{
registrationDate
}
from
'
../src/lib/day2.ts
'
import
{
registrationDate
,
registrationReminder
}
from
'
../src/lib/day2.ts
'
// 验收型公司名称曾触发“业绩”误识别;导入应保留原文事实并去掉字段标签。
// 验收型公司名称曾触发“业绩”误识别;导入应保留原文事实并去掉字段标签。
const
draft
=
extractProfileFromText
(
'
杭州验收科技有限公司
\n
主营业务:智慧水务、监测设备
\n
服务地区:浙江、江苏
\n
资质:电子与智能化工程专业承包二级
'
)
const
draft
=
extractProfileFromText
(
'
杭州验收科技有限公司
\n
主营业务:智慧水务、监测设备
\n
服务地区:浙江、江苏
\n
资质:电子与智能化工程专业承包二级
'
)
...
@@ -16,4 +16,9 @@ assert.equal(registrationDate(['报名截止时间:2026年11月6日']), '2026-
...
@@ -16,4 +16,9 @@ assert.equal(registrationDate(['报名截止时间:2026年11月6日']), '2026-
assert
.
equal
(
registrationDate
([
'
投标截止2026-11-12
'
]),
null
)
assert
.
equal
(
registrationDate
([
'
投标截止2026-11-12
'
]),
null
)
assert
.
equal
(
registrationDate
([
'
报名截止2026-02-30
'
]),
null
)
assert
.
equal
(
registrationDate
([
'
报名截止2026-02-30
'
]),
null
)
assert
.
equal
(
registrationDate
(),
null
)
assert
.
equal
(
registrationDate
(),
null
)
console
.
log
(
'
原型交互数据检查通过(10 项断言)
'
)
assert
.
equal
(
registrationDate
([
'
获取采购文件时间:2026年11月6日9:00至2026年11月12日17:00
'
]),
'
2026-11-12
'
)
assert
.
equal
(
registrationDate
([
'
报名请查看公告,投标截止2026-11-12
'
]),
null
)
assert
.
equal
(
registrationReminder
([
'
报名截至2026-11-11
'
],
'
2026-11-11
'
)?.
label
,
'
报名今天截止
'
)
assert
.
equal
(
registrationReminder
([
'
报名结束日期2026-11-14
'
],
'
2026-11-11
'
)?.
label
,
'
报名仅剩 3 天
'
)
assert
.
equal
(
registrationReminder
([
'
报名截至2026-11-10
'
],
'
2026-11-11
'
)?.
label
,
'
报名已截止
'
)
console
.
log
(
'
原型交互数据检查通过(15 项断言)
'
)
src/components/AiPanel.tsx
View file @
969193af
...
@@ -8,7 +8,7 @@ import { ConversationView } from './ConversationView'
...
@@ -8,7 +8,7 @@ import { ConversationView } from './ConversationView'
import
{
Markdown
}
from
'
./Markdown
'
import
{
Markdown
}
from
'
./Markdown
'
import
{
defaultMatchDimNames
}
from
'
../types
'
import
{
defaultMatchDimNames
}
from
'
../types
'
export
type
AnalysisPanelState
=
{
kind
:
'
closed
'
}
|
{
kind
:
'
project
'
;
project
:
Candidate
;
item
?:
RankedItem
;
summary
?:
NonNullable
<
RankedItem
[
'
analysis
'
]
>
[
'
summary
'
];
batchId
?:
string
}
|
{
kind
:
'
search
'
;
batchId
:
string
}
export
type
AnalysisPanelState
=
{
kind
:
'
closed
'
}
|
{
kind
:
'
project
'
;
project
:
Candidate
;
item
?:
RankedItem
;
summary
?:
NonNullable
<
RankedItem
[
'
analysis
'
]
>
[
'
summary
'
];
batchId
?:
string
}
|
{
kind
:
'
search
'
;
batchId
:
string
;
resultCount
:
number
;
complete
:
boolean
}
/** 严格复用原型 600px 面板与快捷提问;展示真实数据,不插入额外按钮和说明区。 */
/** 严格复用原型 600px 面板与快捷提问;展示真实数据,不插入额外按钮和说明区。 */
export
function
AiPanel
({
state
,
onClose
}:
{
state
:
AnalysisPanelState
;
onClose
:
()
=>
void
})
{
export
function
AiPanel
({
state
,
onClose
}:
{
state
:
AnalysisPanelState
;
onClose
:
()
=>
void
})
{
...
@@ -36,7 +36,7 @@ export function AiPanel({ state, onClose }: { state: AnalysisPanelState; onClose
...
@@ -36,7 +36,7 @@ export function AiPanel({ state, onClose }: { state: AnalysisPanelState; onClose
`- 发布日期:
${
project
.
publishDate
||
'
未披露
'
}
`
,
`- 发布日期:
${
project
.
publishDate
||
'
未披露
'
}
`
,
'
\n
**项目内容**
'
,
summary
?.
construction
||
'
暂无已取得的公告正文
'
,
'
\n
**项目内容**
'
,
summary
?.
construction
||
'
暂无已取得的公告正文
'
,
'
\n
**公告参与条件**
'
,
summary
?.
qualifications
.
map
(
value
=>
`-
${
value
}
`
).
join
(
'
\n
'
)
||
'
公告参与条件待核验
'
,
'
\n
**公告参与条件**
'
,
summary
?.
qualifications
.
map
(
value
=>
`-
${
value
}
`
).
join
(
'
\n
'
)
||
'
公告参与条件待核验
'
,
]
:
[
'
### 基于本次搜索提问
'
,
'
你可以围绕这批结果比较、提问。我只基于本次结果
回答
,
不会修改结果列表的范围或顺序。
'
]
]
:
[
state
.
kind
===
'
search
'
?
`覆盖本批已检索到的全部
${
state
.
resultCount
}
条结果,包含其他分页。
${
state
.
complete
?
''
:
'
检索尚未读完平台命中范围。
'
}
`
:
''
,
'
回答不会修改结果列表的范围或顺序。
'
]
if
(
item
?.
analysis
?.
match
)
{
if
(
item
?.
analysis
?.
match
)
{
const
match
=
item
.
analysis
.
match
const
match
=
item
.
analysis
.
match
lines
.
push
(
`\n**结合公司档案对照**(档案版本 v
${
match
.
profileVersion
}
)`
,
`- 贴合度参考:**
${
match
.
score
??
'
—
'
}
分**`
,
'
\n
**贴合度打分报告**
'
,
'
| 维度 | 权重 | 得分 | 依据 |
'
,
'
| --- | --- | --- | --- |
'
)
lines
.
push
(
`\n**结合公司档案对照**(档案版本 v
${
match
.
profileVersion
}
)`
,
`- 贴合度参考:**
${
match
.
score
??
'
—
'
}
分**`
,
'
\n
**贴合度打分报告**
'
,
'
| 维度 | 权重 | 得分 | 依据 |
'
,
'
| --- | --- | --- | --- |
'
)
...
...
src/components/ConversationView.tsx
View file @
969193af
...
@@ -6,7 +6,6 @@ import { useNavigate } from 'react-router'
...
@@ -6,7 +6,6 @@ import { useNavigate } from 'react-router'
import
{
api
}
from
'
../lib/api
'
import
{
api
}
from
'
../lib/api
'
import
{
conversationsChanged
}
from
'
../lib/conversations
'
import
{
conversationsChanged
}
from
'
../lib/conversations
'
import
type
{
Conversation
,
ConversationMessage
,
QaScope
}
from
'
../lib/conversations
'
import
type
{
Conversation
,
ConversationMessage
,
QaScope
}
from
'
../lib/conversations
'
import
type
{
AgentTask
}
from
'
../hooks/useTaskEvents
'
import
{
beijingDate
,
message
}
from
'
../lib/day2
'
import
{
beijingDate
,
message
}
from
'
../lib/day2
'
import
{
ResearchTask
}
from
'
./ResearchTask
'
import
{
ResearchTask
}
from
'
./ResearchTask
'
import
{
PrimaryButton
}
from
'
./ui-ext/AiButton
'
import
{
PrimaryButton
}
from
'
./ui-ext/AiButton
'
...
@@ -17,7 +16,7 @@ export function ConversationView({ id: initialId, scope: initialScope, embedded
...
@@ -17,7 +16,7 @@ export function ConversationView({ id: initialId, scope: initialScope, embedded
const
[
id
,
setId
]
=
useState
(
initialId
)
const
[
id
,
setId
]
=
useState
(
initialId
)
const
navigate
=
useNavigate
()
const
navigate
=
useNavigate
()
const
[
messages
,
setMessages
]
=
useState
<
ConversationMessage
[]
>
([])
const
[
messages
,
setMessages
]
=
useState
<
ConversationMessage
[]
>
([])
const
[
scope
,
setScope
]
=
useState
<
QaScope
|
undefined
>
(
initialScope
)
const
scope
=
initialScope
const
[
input
,
setInput
]
=
useState
(
''
),
[
error
,
setError
]
=
useState
(
''
),
[
busy
,
setBusy
]
=
useState
(
false
)
const
[
input
,
setInput
]
=
useState
(
''
),
[
error
,
setError
]
=
useState
(
''
),
[
busy
,
setBusy
]
=
useState
(
false
)
const
[
ready
,
setReady
]
=
useState
(
!
id
)
const
[
ready
,
setReady
]
=
useState
(
!
id
)
const
scrollRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
scrollRef
=
useRef
<
HTMLDivElement
>
(
null
)
...
@@ -28,32 +27,29 @@ export function ConversationView({ id: initialId, scope: initialScope, embedded
...
@@ -28,32 +27,29 @@ export function ConversationView({ id: initialId, scope: initialScope, embedded
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
id
)
return
if
(
!
id
)
return
let
active
=
true
let
active
=
true
void
Promise
.
all
([
api
<
Conversation
>
(
`/conversations/
${
id
}
`
),
api
<
ConversationMessage
[]
>
(
`/conversations/
${
id
}
/messages`
)
])
.
then
(
async
([,
rows
])
=>
{
void
api
<
ConversationMessage
[]
>
(
`/conversations/
${
id
}
/messages`
).
then
(
rows
=>
{
if
(
!
active
)
return
if
(
!
active
)
return
setMessages
(
rows
)
setMessages
(
rows
)
const
taskId
=
rows
.
at
(
-
1
)?.
task_id
setReady
(
true
)
if
(
taskId
)
{
const
task
=
await
api
<
AgentTask
>
(
`/agent/tasks/
${
taskId
}
`
)
if
(
active
)
setScope
(
task
.
request
.
qa
??
undefined
)
}
if
(
active
)
setReady
(
true
)
}).
catch
(
e
=>
{
if
(
active
)
setError
(
message
(
e
))
})
}).
catch
(
e
=>
{
if
(
active
)
setError
(
message
(
e
))
})
return
()
=>
{
active
=
false
}
return
()
=>
{
active
=
false
}
},
[
id
])
},
[
id
])
const
ask
=
async
(
raw
=
input
)
=>
{
const
ask
=
async
(
raw
=
input
)
=>
{
if
(
inFlight
.
current
||
!
raw
.
trim
()
||
!
scope
)
return
if
(
!
ready
||
inFlight
.
current
||
!
raw
.
trim
()
||
(
!
id
&&
!
scope
)
)
return
inFlight
.
current
=
true
;
setBusy
(
true
);
setError
(
''
)
inFlight
.
current
=
true
;
setBusy
(
true
);
setError
(
''
)
try
{
try
{
// 生成提交键也属于提交流程;即使本地准备失败,finally 仍须解除发送锁以便重试。
// 生成提交键也属于提交流程;即使本地准备失败,finally 仍须解除发送锁以便重试。
const
body
=
{
question
:
raw
.
trim
(),
scope
}
// 内嵌项目面板仍使用明确的快照范围;普通历史会话由后端从同一会话的最近报告取得上下文。
const
signature
=
JSON
.
stringify
(
body
)
const
path
=
scope
?
'
messages
'
:
'
research
'
const
body
=
scope
?
{
question
:
raw
.
trim
(),
scope
}
:
{
question
:
raw
.
trim
()
}
const
signature
=
`
${
path
}
:
${
JSON
.
stringify
(
body
)}
`
if
(
pending
.
current
?.
signature
!==
signature
)
pending
.
current
=
{
signature
,
key
:
createUuid
(),
conversationId
:
id
}
if
(
pending
.
current
?.
signature
!==
signature
)
pending
.
current
=
{
signature
,
key
:
createUuid
(),
conversationId
:
id
}
if
(
!
pending
.
current
.
conversationId
)
{
if
(
!
pending
.
current
.
conversationId
)
{
const
c
=
await
api
<
Conversation
>
(
'
/conversations
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
title
:
''
})
})
const
c
=
await
api
<
Conversation
>
(
'
/conversations
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
title
:
''
})
})
pending
.
current
.
conversationId
=
c
.
id
pending
.
current
.
conversationId
=
c
.
id
}
}
const
conv
=
pending
.
current
.
conversationId
const
conv
=
pending
.
current
.
conversationId
await
api
(
`/conversations/
${
conv
}
/
messages
`
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
pending
.
current
.
key
},
body
:
JSON
.
stringify
(
body
)
})
await
api
(
`/conversations/
${
conv
}
/
${
path
}
`
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
pending
.
current
.
key
},
body
:
JSON
.
stringify
(
body
)
})
pending
.
current
=
null
;
setInput
(
''
);
conversationsChanged
()
pending
.
current
=
null
;
setInput
(
''
);
conversationsChanged
()
if
(
id
)
{
if
(
id
)
{
setMessages
(
await
api
<
ConversationMessage
[]
>
(
`/conversations/
${
id
}
/messages`
))
setMessages
(
await
api
<
ConversationMessage
[]
>
(
`/conversations/
${
id
}
/messages`
))
...
@@ -68,15 +64,18 @@ export function ConversationView({ id: initialId, scope: initialScope, embedded
...
@@ -68,15 +64,18 @@ export function ConversationView({ id: initialId, scope: initialScope, embedded
{
children
}
{
children
}
{
error
&&
<
p
role
=
"alert"
className
=
"rounded-ctrl bg-red-50 p-3 text-sm text-red-700"
>
{
error
}
<
button
className
=
"ml-3 underline"
onClick
=
{
()
=>
window
.
location
.
reload
()
}
>
重新读取历史
</
button
></
p
>
}
{
error
&&
<
p
role
=
"alert"
className
=
"rounded-ctrl bg-red-50 p-3 text-sm text-red-700"
>
{
error
}
<
button
className
=
"ml-3 underline"
onClick
=
{
()
=>
window
.
location
.
reload
()
}
>
重新读取历史
</
button
></
p
>
}
{
!
ready
&&
!
error
&&
<
p
role
=
"status"
className
=
"text-sm text-ink-400"
>
正在读取历史会话…
</
p
>
}
{
!
ready
&&
!
error
&&
<
p
role
=
"status"
className
=
"text-sm text-ink-400"
>
正在读取历史会话…
</
p
>
}
{
messages
.
map
(
row
=>
<
article
key
=
{
row
.
id
}
className
=
"space-y-3"
><
div
className
=
"flex justify-end"
><
p
className
=
"max-w-[85%] whitespace-pre-wrap rounded-2xl rounded-br-sm bg-brand-500 px-4 py-2 text-[14px] text-white shadow-[0_2px_8px_rgba(99,102,241,.25)]"
>
{
row
.
content
}
</
p
></
div
>
{
row
.
task_id
&&
<
ResearchTask
id
=
{
row
.
task_id
}
/>
}
</
article
>)
}
{
messages
.
map
(
row
=>
embedded
?
<
article
key
=
{
row
.
id
}
className
=
"space-y-3"
>
<
div
className
=
"flex justify-end"
><
p
className
=
"max-w-[85%] whitespace-pre-wrap rounded-2xl rounded-br-sm bg-brand-500 px-4 py-2 text-[14px] text-white shadow-[0_2px_8px_rgba(99,102,241,.25)]"
>
{
row
.
content
}
</
p
></
div
>
{
row
.
task_id
&&
<
ResearchTask
id
=
{
row
.
task_id
}
/>
}
</
article
>
:
row
.
task_id
?
<
ResearchTask
key
=
{
row
.
id
}
id
=
{
row
.
task_id
}
title
=
{
row
.
content
}
/>
:
<
article
key
=
{
row
.
id
}
className
=
"rounded-[16px] bg-white px-4 py-3 font-bold whitespace-pre-wrap"
>
{
row
.
content
}
</
article
>)
}
</
div
>
</
div
>
</
div
>
</
div
>
{
ready
&&
scope
&&
<
footer
className
=
"
shrink-0 border-t border-line-soft bg-white/75
px-4
py-3 backdrop-blur-md
"
><
div
className
=
{
embedded
?
''
:
'
mx-auto max-w-[820px]
'
}
>
<
footer
className
=
{
`
shrink-0 border-t border-line-soft bg-white/75 py-3 backdrop-blur-md
${
embedded
?
'
px-4
'
:
'
px-6
'
}
`
}
><
div
className
=
{
embedded
?
''
:
'
mx-auto max-w-[820px]
'
}
>
{
embedded
&&
<
div
className
=
"mb-2 flex flex-wrap gap-1.5"
>
{
quick
.
map
(
q
=>
<
button
key
=
{
q
}
disabled
=
{
busy
}
onClick
=
{
()
=>
{
setInput
(
q
);
void
ask
(
q
)
}
}
className
=
"rounded-full border border-line-soft px-2.5 py-1 text-xs text-ink-600 hover:border-brand-500/40 hover:text-brand-500 disabled:opacity-40"
>
{
q
}
</
button
>)
}
</
div
>
}
{
embedded
&&
<
div
className
=
"mb-2 flex flex-wrap gap-1.5"
>
{
quick
.
map
(
q
=>
<
button
key
=
{
q
}
disabled
=
{
busy
}
onClick
=
{
()
=>
{
setInput
(
q
);
void
ask
(
q
)
}
}
className
=
"rounded-full border border-line-soft px-2.5 py-1 text-xs text-ink-600 hover:border-brand-500/40 hover:text-brand-500 disabled:opacity-40"
>
{
q
}
</
button
>)
}
</
div
>
}
<
form
onSubmit
=
{
e
=>
{
e
.
preventDefault
();
void
ask
()
}
}
className
=
"flex items-end gap-2"
><
textarea
aria
-
label
=
"快照问题"
value
=
{
input
}
onChange
=
{
e
=>
setInput
(
e
.
target
.
value
)
}
onKeyDown
=
{
e
=>
{
if
(
e
.
key
===
'
Enter
'
&&
!
e
.
shiftKey
&&
!
e
.
nativeEvent
.
isComposing
)
{
e
.
preventDefault
();
void
ask
()
}
}
}
required
maxLength
=
{
2000
}
rows
=
{
1
}
className
=
"max-h-28 flex-1 resize-none rounded-ctrl border border-line-soft px-3 py-2 text-[14px] outline-none focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10"
placeholder
=
{
scope
.
projectId
?
'
围绕这个项目继续追问…
'
:
'
围绕本次检索结果提问…
'
}
/><
PrimaryButton
aria
-
label
=
"发送"
disabled
=
{
busy
||
!
input
.
trim
()
}
type
=
"submit"
className
=
"!rounded-full !p-2.5"
>
{
busy
?
<
Loader2
size
=
{
16
}
className
=
"animate-spin"
/>
:
<
Send
size
=
{
16
}
/>
}
</
PrimaryButton
></
form
>
<
form
onSubmit
=
{
e
=>
{
e
.
preventDefault
();
void
ask
()
}
}
className
=
"flex items-end gap-2"
><
textarea
aria
-
label
=
{
embedded
?
'
快照问题
'
:
'
研究问题
'
}
value
=
{
input
}
onChange
=
{
e
=>
setInput
(
e
.
target
.
value
)
}
onKeyDown
=
{
e
=>
{
if
(
e
.
key
===
'
Enter
'
&&
!
e
.
shiftKey
&&
!
e
.
nativeEvent
.
isComposing
)
{
e
.
preventDefault
();
void
ask
()
}
}
}
required
maxLength
=
{
2000
}
rows
=
{
1
}
className
=
"max-h-28 flex-1 resize-none rounded-ctrl border border-line-soft px-3 py-2 text-[14px] outline-none focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10"
placeholder
=
{
scope
?
.
projectId
?
'
围绕这个项目继续追问…
'
:
scope
?
'
围绕本次检索结果提问…
'
:
'
继续追问…
'
}
/><
PrimaryButton
aria
-
label
=
"发送"
disabled
=
{
!
ready
||
busy
||
!
input
.
trim
()
}
type
=
"submit"
className
=
"!rounded-full !p-2.5"
>
{
busy
?
<
Loader2
size
=
{
16
}
className
=
"animate-spin"
/>
:
<
Send
size
=
{
16
}
/>
}
</
PrimaryButton
></
form
>
{
embedded
&&
<
p
className
=
"mt-1.5 text-[11px] text-ink-400"
>
AI 分析供参考,是否跟进、报名或投标由你决定 · 上下文时间
<
span
className
=
"font-num"
>
{
beijingDate
()
}
</
span
></
p
>
}
{
embedded
&&
<
p
className
=
"mt-1.5 text-[11px] text-ink-400"
>
AI 分析供参考,是否跟进、报名或投标由你决定 · 上下文时间
<
span
className
=
"font-num"
>
{
beijingDate
()
}
</
span
></
p
>
}
</
div
></
footer
>
}
</
div
></
footer
>
</
section
>
</
section
>
}
}
src/components/MarketReport.tsx
0 → 100644
View file @
969193af
import
type
{
SearchReport
}
from
'
../lib/day2
'
/** 市场报告按已冻结的查询条件展示平台聚合。缺失月份保留为空,避免把未返回的数据当成零公告。 */
export
function
MarketReport
({
report
}:
{
report
:
SearchReport
})
{
const
{
conditions
,
market
}
=
report
const
{
beginDate
,
endDate
,
keywords
,
hardRegions
}
=
conditions
const
aggregates
=
market
?.
platformAggregations
??
[]
const
monthly
=
aggregates
.
find
(
group
=>
group
.
tool
===
'
aggregate_bids_advanced
'
)
const
endMonth
=
new
Date
(
`
${
endDate
.
slice
(
0
,
7
)}
-01T00:00:00Z`
)
const
months
=
Array
.
from
({
length
:
6
},
(
_
,
index
)
=>
{
const
month
=
new
Date
(
endMonth
)
month
.
setUTCMonth
(
month
.
getUTCMonth
()
-
(
5
-
index
))
const
key
=
month
.
toISOString
().
slice
(
0
,
7
)
month
.
setUTCMonth
(
month
.
getUTCMonth
()
+
1
,
0
)
return
{
key
,
complete
:
`
${
key
}
-01`
>=
beginDate
&&
month
.
toISOString
().
slice
(
0
,
10
)
<=
endDate
,
row
:
monthly
?.
rows
.
find
(
row
=>
row
.
name
===
key
)
}
}).
filter
(
month
=>
month
.
key
>=
beginDate
.
slice
(
0
,
7
))
const
[
prior
,
latest
]
=
months
.
filter
(
month
=>
month
.
complete
).
slice
(
-
2
)
const
priorCount
=
prior
?.
row
?.
count
,
latestCount
=
latest
?.
row
?.
count
// 查询首尾可能仅覆盖部分月份,趋势仅比较相邻的完整月,且两个月都必须有平台计数。
const
trend
=
priorCount
==
null
||
latestCount
==
null
?
'
当前统计范围内相邻完整月的数据不足,暂无法判断趋势。
'
:
`
${
latest
.
key
}
公告数为
${
latestCount
}
条,
${
prior
.
key
}
为
${
priorCount
}
条,
${
latestCount
===
priorCount
?
'
环比持平
'
:
`环比
${
latestCount
>
priorCount
?
'
增加
'
:
'
减少
'
}
${
Math
.
abs
(
latestCount
-
priorCount
)}
条`
}
。`
return
<
div
className
=
"space-y-4 text-sm leading-7 text-ink-600"
>
<
p
>
统计范围:
{
hardRegions
.
join
(
'
、
'
)
||
'
全国
'
}
·
{
beginDate
}
至
{
endDate
}
·
{
keywords
.
join
(
'
、
'
)
}
</
p
>
<
div
><
h3
className
=
"font-semibold text-ink-900"
>
采购热度与趋势
</
h3
><
p
>
{
trend
}
</
p
></
div
>
<
div
>
<
h3
className
=
"font-semibold text-ink-900"
>
{
months
.
length
===
6
?
'
近 6 个月公告数
'
:
'
所选时段公告数
'
}
</
h3
>
{
monthly
?
<
div
className
=
"overflow-x-auto"
><
table
className
=
"w-full text-left"
>
<
thead
><
tr
className
=
"border-b border-line-soft"
><
th
scope
=
"col"
>
月份
</
th
><
th
scope
=
"col"
>
公告数
</
th
><
th
scope
=
"col"
>
金额合计(万元)
</
th
></
tr
></
thead
>
<
tbody
>
{
months
.
map
(({
key
,
complete
,
row
})
=>
<
tr
key
=
{
key
}
className
=
"border-b border-line-soft"
><
th
scope
=
"row"
className
=
"py-1 font-normal"
>
{
key
}{
complete
?
''
:
'
(部分)
'
}
</
th
><
td
>
{
row
?.
count
??
'
—
'
}
</
td
><
td
>
{
row
?.
amountWan
?.
toLocaleString
(
'
zh-CN
'
)
??
'
—
'
}
</
td
></
tr
>)
}
</
tbody
>
</
table
></
div
>
:
<
p
>
平台月度聚合结果尚未取得。
</
p
>
}
</
div
>
{
aggregates
.
filter
(
group
=>
group
.
tool
!==
'
aggregate_bids_advanced
'
).
map
(
group
=>
<
div
key
=
{
group
.
tool
}
>
<
h3
className
=
"font-semibold text-ink-900"
>
{
group
.
tool
===
'
get_top_purchasers
'
?
'
主要采购方
'
:
'
主要中标企业
'
}
</
h3
>
{
group
.
rows
.
length
?
<
ol
className
=
"list-decimal pl-5"
>
{
group
.
rows
.
map
((
row
,
index
)
=>
<
li
key
=
{
`
${
row
.
name
}
:
${
index
}
`
}
>
{
row
.
url
?
<
a
href
=
{
row
.
url
}
target
=
"_blank"
rel
=
"noopener noreferrer"
className
=
"text-brand-500 underline"
>
{
row
.
name
}
</
a
>
:
row
.
name
}{
row
.
count
==
null
?
''
:
` ·
${
row
.
count
}
次`
}
</
li
>)
}
</
ol
>
:
<
p
>
本次未返回排名记录。
</
p
>
}
</
div
>)
}
{
monthly
&&
<
p
className
=
"text-xs text-ink-400"
>
平台聚合按实际查询条件统计。月表仅展示所选时段末尾最多六个自然月,横线表示平台未返回数据。
</
p
>
}
</
div
>
}
src/components/OpportunityTable.tsx
View file @
969193af
import
{
useState
}
from
'
react
'
import
{
useState
}
from
'
react
'
import
{
ChevronLeft
,
ChevronRight
,
ExternalLink
,
Sparkles
,
Star
}
from
'
lucide-react
'
import
{
ChevronLeft
,
ChevronRight
,
ExternalLink
,
Sparkles
,
Star
,
Tag
}
from
'
lucide-react
'
import
*
as
Popover
from
'
@radix-ui/react-popover
'
import
*
as
Popover
from
'
@radix-ui/react-popover
'
import
type
{
RankedItem
}
from
'
../lib/day2
'
import
type
{
RankedItem
}
from
'
../lib/day2
'
import
{
message
}
from
'
../lib/day2
'
import
{
message
,
registrationReminder
}
from
'
../lib/day2
'
import
{
useStore
}
from
'
../lib/store
'
import
{
useStore
}
from
'
../lib/store
'
import
{
defaultMatchDimNames
}
from
'
../types
'
import
{
defaultMatchDimNames
}
from
'
../types
'
import
type
{
AnalysisPanelState
}
from
'
./AiPanel
'
import
type
{
AnalysisPanelState
}
from
'
./AiPanel
'
...
@@ -15,7 +15,7 @@ const PAGE_SIZE = 8
...
@@ -15,7 +15,7 @@ const PAGE_SIZE = 8
export
function
OpportunityTable
({
items
,
batchId
,
onOpenPanel
}:
{
export
function
OpportunityTable
({
items
,
batchId
,
onOpenPanel
}:
{
items
:
RankedItem
[];
batchId
:
string
;
onOpenPanel
:
(
state
:
AnalysisPanelState
)
=>
void
items
:
RankedItem
[];
batchId
:
string
;
onOpenPanel
:
(
state
:
AnalysisPanelState
)
=>
void
})
{
})
{
const
{
addWatch
,
isWatched
}
=
useStore
()
const
{
addWatch
,
removeWatch
,
isWatched
}
=
useStore
()
const
[
scoreProject
,
setScoreProject
]
=
useState
<
string
|
null
>
(
null
)
const
[
scoreProject
,
setScoreProject
]
=
useState
<
string
|
null
>
(
null
)
const
[
page
,
setPage
]
=
useState
(
1
),
[
error
,
setError
]
=
useState
(
''
)
const
[
page
,
setPage
]
=
useState
(
1
),
[
error
,
setError
]
=
useState
(
''
)
const
[
tagProject
,
setTagProject
]
=
useState
<
string
|
null
>
(
null
),
[
saving
,
setSaving
]
=
useState
(
false
)
const
[
tagProject
,
setTagProject
]
=
useState
<
string
|
null
>
(
null
),
[
saving
,
setSaving
]
=
useState
(
false
)
...
@@ -25,25 +25,37 @@ export function OpportunityTable({ items, batchId, onOpenPanel }: {
...
@@ -25,25 +25,37 @@ export function OpportunityTable({ items, batchId, onOpenPanel }: {
const
follow
=
async
(
id
:
string
)
=>
{
const
follow
=
async
(
id
:
string
)
=>
{
if
(
saving
)
return
if
(
saving
)
return
setSaving
(
true
);
setError
(
''
)
setSaving
(
true
);
setError
(
''
)
try
{
if
(
!
isWatched
(
id
))
await
addWatch
(
id
);
setTagProject
(
id
)
}
try
{
// 星标切换关注状态;标签使用独立触发器,保存关注后仍可就地打标签。
if
(
isWatched
(
id
))
{
await
removeWatch
(
id
);
setTagProject
(
null
)
}
else
{
await
addWatch
(
id
);
setTagProject
(
id
)
}
}
catch
(
e
)
{
setError
(
message
(
e
))
}
finally
{
setSaving
(
false
)
}
catch
(
e
)
{
setError
(
message
(
e
))
}
finally
{
setSaving
(
false
)
}
}
}
return
<>
return
<>
{
error
&&
<
p
role
=
"alert"
className
=
"px-5 py-2 text-xs text-bad-500"
>
{
error
}
</
p
>
}
{
error
&&
<
p
role
=
"alert"
className
=
"px-5 py-2 text-xs text-bad-500"
>
{
error
}
</
p
>
}
<
div
className
=
"overflow-x-auto"
><
table
className
=
"w-full min-w-[940px] table-fixed text-left text-[13px]"
>
<
div
className
=
"overflow-x-auto"
><
table
className
=
"w-full min-w-[940px] table-fixed text-left text-[13px]"
>
<
colgroup
>
{
[
30
,
1
5
,
9
,
1
4
,
1
1
,
7
,
1
4
].
map
((
width
,
i
)
=>
<
col
key
=
{
i
}
style
=
{
{
width
:
`
${
width
}
%`
}
}
/>)
}
</
colgroup
>
<
colgroup
>
{
[
27
,
1
3
,
9
,
1
6
,
1
6
,
6
,
1
3
].
map
((
width
,
i
)
=>
<
col
key
=
{
i
}
style
=
{
{
width
:
`
${
width
}
%`
}
}
/>)
}
</
colgroup
>
<
thead
><
tr
className
=
"border-b border-line-soft bg-[#FAFBFD] text-ink-400"
>
{
[
'
项目
名称
'
,
'
招标方
'
,
'
预算
'
,
'
时间节奏
'
,
'
参与
门槛
'
,
'
匹配度
'
,
'
操作
'
].
map
((
name
,
i
)
=>
<
th
key
=
{
name
}
className
=
{
i
===
0
?
'
w-[30%]
px-5 py-2.5 font-medium
'
:
'
px-3 py-2.5 font-medium
'
}
>
{
name
}
</
th
>)
}
</
tr
></
thead
>
<
thead
><
tr
className
=
"border-b border-line-soft bg-[#FAFBFD] text-ink-400"
>
{
[
'
项目
与建设内容
'
,
'
招标方
与地域
'
,
'
预算
'
,
'
时间节奏
'
,
'
资质与业绩
门槛
'
,
'
匹配度
'
,
'
操作
'
].
map
((
name
,
i
)
=>
<
th
key
=
{
name
}
className
=
{
i
===
0
?
'
px-5 py-2.5 font-medium
'
:
'
px-3 py-2.5 font-medium
'
}
>
{
name
}
</
th
>)
}
</
tr
></
thead
>
<
tbody
>
{
rows
.
map
(
item
=>
{
<
tbody
>
{
rows
.
map
(
item
=>
{
const
p
=
item
.
facts
,
summary
=
item
.
analysis
?.
summary
,
match
=
item
.
analysis
?.
match
const
p
=
item
.
facts
,
summary
=
item
.
analysis
?.
summary
,
match
=
item
.
analysis
?.
match
return
<
tr
key
=
{
p
.
id
}
onClick
=
{
()
=>
open
(
item
)
}
className
=
"cursor-pointer border-b border-line-soft/70 transition-colors last:border-0 hover:bg-brand-50/40"
>
const
reminder
=
registrationReminder
(
summary
?.
schedule
)
<
td
className
=
"px-5 py-3"
><
a
href
=
{
p
.
url
??
undefined
}
target
=
"_blank"
rel
=
"noreferrer"
onClick
=
{
e
=>
{
e
.
stopPropagation
();
if
(
!
p
.
url
)
open
(
item
)
}
}
className
=
"inline-flex items-start gap-1 font-medium leading-snug text-ink-900 hover:text-brand-500 hover:underline"
><
span
>
{
p
.
title
||
'
标题待核验
'
}
</
span
>
{
p
.
url
&&
<
ExternalLink
size
=
{
12
}
className
=
"mt-1 shrink-0 text-ink-400"
/>
}
</
a
><
div
className
=
"mt-1 flex flex-wrap gap-1"
>
{
p
.
products
.
slice
(
0
,
2
).
map
(
kw
=>
<
span
key
=
{
kw
}
className
=
"rounded-full bg-[#F4F7FB] px-2 py-px text-[11px] text-ink-600"
>
{
kw
}
</
span
>)
}
</
div
></
td
>
const
construction
=
summary
?.
construction
.
startsWith
(
'
未取得正文
'
)
?
p
.
products
.
join
(
'
、
'
)
:
summary
?.
construction
||
p
.
products
.
join
(
'
、
'
)
<
td
className
=
"px-3 py-3"
><
div
className
=
"max-w-[150px] leading-snug"
>
{
p
.
purchaser
||
'
待核验
'
}
</
div
><
div
className
=
"mt-0.5 text-xs text-ink-400"
>
{
p
.
region
||
'
地区未知
'
}
</
div
></
td
>
const
qualifications
=
summary
?.
qualifications
??
[]
// 同一行尽量兼顾资质与业绩,不让多个同类条款把另一项挤出列表。
const
requirements
=
[...
new
Set
([
qualifications
.
find
(
line
=>
/资质|资格|许可证|认证|承包/
.
test
(
line
)),
qualifications
.
find
(
line
=>
line
.
includes
(
'
业绩
'
))].
filter
(
Boolean
))]
const
timing
=
summary
?.
schedule
.
find
(
line
=>
/工期|交付|服务期/
.
test
(
line
))
const
watched
=
isWatched
(
p
.
id
)
return
<
tr
key
=
{
p
.
id
}
onClick
=
{
()
=>
open
(
item
)
}
className
=
"cursor-pointer border-b border-line-soft/70 align-top transition-colors last:border-0 hover:bg-brand-50/40"
>
<
td
className
=
"px-5 py-3"
><
a
href
=
{
p
.
url
??
undefined
}
target
=
"_blank"
rel
=
"noreferrer"
onClick
=
{
e
=>
{
e
.
stopPropagation
();
if
(
!
p
.
url
)
open
(
item
)
}
}
className
=
"inline-flex items-start gap-1 font-medium leading-snug text-ink-900 hover:text-brand-500 hover:underline"
><
span
>
{
p
.
title
||
'
标题待核验
'
}
</
span
>
{
p
.
url
&&
<
ExternalLink
size
=
{
12
}
className
=
"mt-1 shrink-0 text-ink-400"
/>
}
</
a
><
p
className
=
"mt-1 line-clamp-3 text-xs leading-relaxed text-ink-600"
title
=
{
construction
||
undefined
}
><
span
className
=
"font-medium"
>
建设内容
</
span
>
·
{
construction
||
'
公告摘要未披露
'
}
</
p
></
td
>
<
td
className
=
"px-3 py-3"
><
div
className
=
"leading-snug"
>
{
p
.
purchaser
||
'
待核验
'
}
</
div
><
div
className
=
"mt-1 text-xs text-ink-600"
>
地域 ·
{
summary
?.
region
||
p
.
region
||
'
未披露
'
}
</
div
></
td
>
<
td
className
=
"whitespace-nowrap px-3 py-3"
>
{
p
.
budgetWan
==
null
?
<
span
className
=
"text-ink-400"
>
未披露
</
span
>
:
<
span
className
=
"font-num font-bold"
>
{
p
.
budgetWan
.
toLocaleString
()
}
<
span
className
=
"text-xs font-medium text-ink-400"
>
万元
</
span
></
span
>
}
</
td
>
<
td
className
=
"whitespace-nowrap px-3 py-3"
>
{
p
.
budgetWan
==
null
?
<
span
className
=
"text-ink-400"
>
未披露
</
span
>
:
<
span
className
=
"font-num font-bold"
>
{
p
.
budgetWan
.
toLocaleString
()
}
<
span
className
=
"text-xs font-medium text-ink-400"
>
万元
</
span
></
span
>
}
</
td
>
<
td
className
=
"
max-w-[150px] px-3 py-3"
><
div
className
=
"flex items-start gap-1.5 text-xs font-medium text-ink-600"
><
span
className
=
"mt-1 h-1.5 w-1.5 shrink-0 rounded-full bg
-ink-
4
00"
/><
span
className
=
"line-clamp-2
"
title
=
{
summary
?.
schedule
.
join
(
'
;
'
)
}
>
{
summary
?.
schedule
[
0
]
||
'
截止未披露
'
}
</
span
></
div
><
div
className
=
"mt-
0.5
font-num
text-xs
text-ink-400"
>
发布
{
p
.
publishDate
||
'
未知
'
}
</
div
></
td
>
<
td
className
=
"
px-3 py-3 text-xs"
><
p
className
=
{
`font-semibold
${
reminder
&&
reminder
.
days
>=
0
&&
reminder
.
days
<=
7
?
'
text-bad-500
'
:
'
text-ink-600
'
}
`
}
>
{
reminder
?.
label
??
'
报名截止未披露
'
}
</
p
>
{
reminder
&&
<
time
className
=
"mt-1 block font-num text
-ink-
6
00"
dateTime
=
{
reminder
.
date
}
>
{
reminder
.
date
}
</
time
>
}{
timing
&&
<
p
className
=
"
mt-1
line-clamp-2
text-ink-600"
title
=
{
timing
}
>
{
timing
}
</
p
>
}
<
p
className
=
"mt-
1
font-num text-ink-400"
>
发布
{
p
.
publishDate
||
'
未知
'
}
</
p
></
td
>
<
td
className
=
"
max-w-[135px] px-3 py-3"
><
span
className
=
"block truncate rounded-full bg-warn-500/10 px-2.5 py-0.5 text-xs text-warn-500"
title
=
{
summary
?.
qualifications
.
join
(
'
;
'
)
}
>
{
summary
?.
qualifications
[
0
]
||
'
条件待核验
'
}
</
span
>
</
td
>
<
td
className
=
"
px-3 py-3 text-xs leading-relaxed text-ink-600"
>
{
(
requirements
.
length
?
requirements
:
qualifications
.
slice
(
0
,
1
)).
map
((
line
,
i
)
=>
<
p
key
=
{
i
}
className
=
"mb-1 line-clamp-3"
title
=
{
line
}
>
{
line
}
</
p
>)
}{
!
qualifications
.
length
&&
'
公告摘要未披露
'
}
</
td
>
<
td
className
=
"px-3 py-3"
><
Popover
.
Root
open
=
{
scoreProject
===
p
.
id
}
onOpenChange
=
{
value
=>
setScoreProject
(
value
?
p
.
id
:
null
)
}
><
Popover
.
Trigger
asChild
><
button
onMouseEnter
=
{
()
=>
setScoreProject
(
p
.
id
)
}
onMouseLeave
=
{
()
=>
setScoreProject
(
null
)
}
onFocus
=
{
()
=>
setScoreProject
(
p
.
id
)
}
onBlur
=
{
()
=>
setScoreProject
(
null
)
}
onClick
=
{
e
=>
e
.
stopPropagation
()
}
className
=
"whitespace-nowrap font-num text-[15px] font-bold text-brand-500"
aria
-
label
=
{
`查看
${
p
.
title
}
匹配度构成`
}
>
{
match
?.
score
??
'
—
'
}{
match
?.
score
!=
null
&&
<
span
className
=
"text-xs font-medium text-ink-400"
>
分
</
span
>
}
</
button
></
Popover
.
Trigger
><
Popover
.
Portal
><
Popover
.
Content
onClick
=
{
e
=>
e
.
stopPropagation
()
}
sideOffset
=
{
8
}
className
=
"z-50 w-72 rounded-card border border-line-soft bg-white p-3 shadow-card-hover"
><
h4
className
=
"text-xs font-medium"
>
贴合度打分构成
</
h4
>
{
match
?
<><
ul
className
=
"mt-2 space-y-2"
>
{
Object
.
entries
(
match
.
dimensions
).
map
(([
key
,
dim
])
=>
<
li
key
=
{
key
}
className
=
"text-xs"
><
div
className
=
"flex justify-between"
><
span
>
{
defaultMatchDimNames
[
key
as
keyof
typeof
defaultMatchDimNames
]
??
key
}
· 权重
{
match
.
weights
[
key
]
}
%
</
span
><
b
>
{
dim
.
known
?
`
${
dim
.
score
}
分`
:
'
待核验
'
}
</
b
></
div
><
p
className
=
"mt-0.5 text-[11px] text-ink-400"
>
{
dim
.
basis
}
</
p
></
li
>)
}
</
ul
><
p
className
=
"mt-2 text-[11px] text-ink-400"
>
完整性
{
match
.
completeness
}
% · 档案 v
{
match
.
profileVersion
}
·
{
match
.
limitation
}
</
p
></>
:
<
p
className
=
"mt-2 text-xs text-ink-400"
>
尚无已保存评分,请完善公司档案后重新检索。
</
p
>
}
</
Popover
.
Content
></
Popover
.
Portal
></
Popover
.
Root
></
td
>
<
td
className
=
"px-3 py-3"
><
Popover
.
Root
open
=
{
scoreProject
===
p
.
id
}
onOpenChange
=
{
value
=>
setScoreProject
(
value
?
p
.
id
:
null
)
}
><
Popover
.
Trigger
asChild
><
button
onMouseEnter
=
{
()
=>
setScoreProject
(
p
.
id
)
}
onMouseLeave
=
{
()
=>
setScoreProject
(
null
)
}
onFocus
=
{
()
=>
setScoreProject
(
p
.
id
)
}
onBlur
=
{
()
=>
setScoreProject
(
null
)
}
onClick
=
{
e
=>
e
.
stopPropagation
()
}
className
=
"whitespace-nowrap font-num text-[15px] font-bold text-brand-500"
aria
-
label
=
{
`查看
${
p
.
title
}
匹配度构成`
}
>
{
match
?.
score
??
'
—
'
}{
match
?.
score
!=
null
&&
<
span
className
=
"text-xs font-medium text-ink-400"
>
分
</
span
>
}
</
button
></
Popover
.
Trigger
><
Popover
.
Portal
><
Popover
.
Content
onClick
=
{
e
=>
e
.
stopPropagation
()
}
sideOffset
=
{
8
}
className
=
"z-50 w-72 rounded-card border border-line-soft bg-white p-3 shadow-card-hover"
><
h4
className
=
"text-xs font-medium"
>
贴合度打分构成
</
h4
>
{
match
?
<><
ul
className
=
"mt-2 space-y-2"
>
{
Object
.
entries
(
match
.
dimensions
).
map
(([
key
,
dim
])
=>
<
li
key
=
{
key
}
className
=
"text-xs"
><
div
className
=
"flex justify-between"
><
span
>
{
defaultMatchDimNames
[
key
as
keyof
typeof
defaultMatchDimNames
]
??
key
}
· 权重
{
match
.
weights
[
key
]
}
%
</
span
><
b
>
{
dim
.
known
?
`
${
dim
.
score
}
分`
:
'
待核验
'
}
</
b
></
div
><
p
className
=
"mt-0.5 text-[11px] text-ink-400"
>
{
dim
.
basis
}
</
p
></
li
>)
}
</
ul
><
p
className
=
"mt-2 text-[11px] text-ink-400"
>
完整性
{
match
.
completeness
}
% · 档案 v
{
match
.
profileVersion
}
·
{
match
.
limitation
}
</
p
></>
:
<
p
className
=
"mt-2 text-xs text-ink-400"
>
尚无已保存评分,请完善公司档案后重新检索。
</
p
>
}
</
Popover
.
Content
></
Popover
.
Portal
></
Popover
.
Root
></
td
>
<
td
className
=
"whitespace-nowrap px-3 py-3"
><
div
className
=
"flex items-center gap-1.5"
><
button
onClick
=
{
e
=>
{
e
.
stopPropagation
();
open
(
item
)
}
}
className
=
"inline-flex items-center gap-1 rounded-full border-brand-gradient px-2.5 py-1 text-[12px] font-medium shadow-card hover:shadow-card-hover"
><
Sparkles
size
=
{
12
}
className
=
"text-brand-500"
/><
span
className
=
"text-brand-gradient"
>
AI 分析
</
span
></
button
>
<
td
className
=
"whitespace-nowrap px-3 py-3"
><
div
className
=
"flex flex-wrap items-center gap-1.5"
><
button
onClick
=
{
e
=>
{
e
.
stopPropagation
();
open
(
item
)
}
}
className
=
"inline-flex items-center gap-1 rounded-full border-brand-gradient px-2.5 py-1 text-[12px] font-medium shadow-card hover:shadow-card-hover"
><
Sparkles
size
=
{
12
}
className
=
"text-brand-500"
/><
span
className
=
"text-brand-gradient"
>
AI 分析
</
span
></
button
>
<
Popover
.
Root
open
=
{
tagProject
===
p
.
id
}
onOpenChange
=
{
value
=>
{
if
(
!
value
)
setTagProject
(
null
)
}
}
><
Popover
.
Trigger
asChild
><
button
disabled
=
{
saving
}
onClick
=
{
e
=>
{
e
.
stopPropagation
();
void
follow
(
p
.
id
)
}
}
aria
-
label
=
{
isWatched
(
p
.
id
)
?
'
管理关注标签
'
:
'
加入重点关注
'
}
className
=
"rounded-full p-1.5 text-brand-500 hover:bg-brand-50"
><
Star
size
=
{
15
}
fill
=
{
isWatched
(
p
.
id
)
?
'
currentColor
'
:
'
none
'
}
/></
button
></
Popover
.
Trigger
><
Popover
.
Portal
><
Popover
.
Content
align
=
"end"
sideOffset
=
{
6
}
className
=
"z-50"
onClick
=
{
e
=>
e
.
stopPropagation
()
}
><
ProjectTags
projectId
=
{
p
.
id
}
onClose
=
{
()
=>
setTagProject
(
null
)
}
/></
Popover
.
Content
></
Popover
.
Portal
></
Popover
.
Root
>
<
button
disabled
=
{
saving
}
onClick
=
{
e
=>
{
e
.
stopPropagation
();
void
follow
(
p
.
id
)
}
}
aria
-
pressed
=
{
watched
}
aria
-
label
=
{
watched
?
'
取消重点关注
'
:
'
加入重点关注
'
}
className
=
"rounded-full p-1 text-brand-500 hover:bg-brand-50"
><
Star
size
=
{
15
}
fill
=
{
watched
?
'
currentColor
'
:
'
none
'
}
/></
button
>
{
watched
&&
<
Popover
.
Root
open
=
{
tagProject
===
p
.
id
}
onOpenChange
=
{
value
=>
setTagProject
(
value
?
p
.
id
:
null
)
}
><
Popover
.
Trigger
asChild
><
button
onClick
=
{
e
=>
e
.
stopPropagation
()
}
aria
-
label
=
"管理关注标签"
className
=
"rounded-full p-1 text-ink-400 hover:bg-brand-50 hover:text-brand-500"
><
Tag
size
=
{
13
}
/></
button
></
Popover
.
Trigger
><
Popover
.
Portal
><
Popover
.
Content
align
=
"end"
sideOffset
=
{
6
}
className
=
"z-50"
onClick
=
{
e
=>
e
.
stopPropagation
()
}
><
ProjectTags
projectId
=
{
p
.
id
}
onClose
=
{
()
=>
setTagProject
(
null
)
}
/></
Popover
.
Content
></
Popover
.
Portal
></
Popover
.
Root
>
}
</
div
></
td
>
</
div
></
td
>
</
tr
>
</
tr
>
})
}
</
tbody
>
})
}
</
tbody
>
...
...
src/components/ResearchSections.tsx
0 → 100644
View file @
969193af
import
{
useState
,
type
ReactNode
}
from
'
react
'
import
type
{
ResearchReport
}
from
'
../lib/day3
'
type
RecordData
=
Record
<
string
,
unknown
>
type
Section
=
ResearchReport
[
'
sections
'
][
number
]
const
record
=
(
value
:
unknown
):
RecordData
=>
value
&&
typeof
value
===
'
object
'
&&
!
Array
.
isArray
(
value
)
?
value
as
RecordData
:
{}
const
records
=
(
value
:
unknown
)
=>
Array
.
isArray
(
value
)
?
value
.
map
(
record
)
:
[]
function
text
(
data
:
RecordData
,
...
keys
:
string
[])
{
for
(
const
key
of
keys
)
{
const
value
=
data
[
key
]
if
(
typeof
value
===
'
string
'
&&
value
.
trim
())
return
value
.
trim
()
if
(
typeof
value
===
'
number
'
&&
Number
.
isFinite
(
value
))
return
String
(
value
)
}
return
''
}
function
amount
(
data
:
RecordData
,
wan
=
'
money_wan
'
,
yuan
=
'
money
'
)
{
// 接口同时支持元和万元,金额缺失仍保留为空,显式披露的零元正常显示。
const
money
=
text
(
data
,
yuan
),
moneyWan
=
text
(
data
,
wan
)
const
value
=
money
?
Number
(
money
)
/
10000
:
moneyWan
?
Number
(
moneyWan
)
:
NaN
return
Number
.
isFinite
(
value
)
&&
value
>=
0
?
value
:
null
}
const
format
=
(
value
:
number
)
=>
value
.
toLocaleString
(
'
zh-CN
'
,
{
maximumFractionDigits
:
4
})
const
region
=
(
data
:
RecordData
)
=>
[...
new
Set
([
'
province
'
,
'
city
'
,
'
county
'
].
map
(
key
=>
text
(
data
,
key
)).
filter
(
Boolean
))].
join
(
'
·
'
)
const
company
=
(
data
:
RecordData
)
=>
text
(
data
,
'
fullname
'
,
'
company_name
'
,
'
name
'
)
function
linked
(
label
:
string
,
url
:
string
):
ReactNode
{
if
(
!
label
||
!
/^https
?
:
\/\/
/i
.
test
(
url
))
return
label
return
<
a
href
=
{
url
}
target
=
"_blank"
rel
=
"noopener noreferrer"
className
=
"text-brand-500 hover:underline"
>
{
label
}
</
a
>
}
/** 各工具只通过业务字段白名单进入表格。缺失一整列时隐藏该列,单个缺值以横线合并展示。 */
function
BusinessTable
({
title
,
headers
,
rows
,
empty
}:
{
title
:
string
;
headers
:
string
[];
rows
:
ReactNode
[][];
empty
?:
string
})
{
const
[
expanded
,
setExpanded
]
=
useState
(
false
)
const
visibleRows
=
rows
.
filter
(
row
=>
row
.
some
(
Boolean
))
const
columns
=
headers
.
flatMap
((
label
,
i
)
=>
visibleRows
.
some
(
row
=>
row
[
i
])
?
[{
label
,
i
}]
:
[])
// 报告内可能同时包含数份公告与伙伴列表,默认保留首屏要点并支持展开当前表的全部记录。
const
previewSize
=
8
const
displayRows
=
expanded
?
visibleRows
:
visibleRows
.
slice
(
0
,
previewSize
)
if
(
!
columns
.
length
&&
!
empty
)
return
null
return
<
section
>
<
h3
className
=
"mb-1 font-semibold text-ink-900"
>
{
title
}
</
h3
>
{
columns
.
length
?
<
div
className
=
"overflow-x-auto"
><
table
aria
-
label
=
{
title
}
className
=
"w-full text-left text-[13px] leading-relaxed"
>
<
thead
className
=
"bg-canvas"
><
tr
>
{
columns
.
map
(({
label
,
i
})
=>
<
th
scope
=
"col"
key
=
{
i
}
className
=
"px-3 py-1.5 font-medium"
>
{
label
}
</
th
>)
}
</
tr
></
thead
>
<
tbody
>
{
displayRows
.
map
((
row
,
index
)
=>
<
tr
key
=
{
index
}
className
=
"border-b border-line-soft align-top"
>
{
columns
.
map
(({
i
})
=>
<
td
key
=
{
i
}
className
=
"break-words px-3 py-1.5"
>
{
row
[
i
]
||
'
—
'
}
</
td
>)
}
</
tr
>)
}
</
tbody
>
</
table
></
div
>
:
<
p
className
=
"text-ink-400"
>
{
empty
}
</
p
>
}
{
visibleRows
.
length
>
previewSize
&&
<
button
type
=
"button"
aria
-
expanded
=
{
expanded
}
aria
-
label
=
{
`
${
title
}
·
${
expanded
?
'
收起
'
:
'
展开全部
'
}
`
}
onClick
=
{
()
=>
setExpanded
(
!
expanded
)
}
className
=
"mt-1 text-xs font-medium text-brand-500 hover:underline"
>
{
expanded
?
'
收起
'
:
`展开其余
${
visibleRows
.
length
-
previewSize
}
条`
}
</
button
>
}
</
section
>
}
function
NoticeTable
({
title
,
items
}:
{
title
:
string
;
items
:
RecordData
[]
})
{
return
<
BusinessTable
title
=
{
title
}
headers
=
{
[
'
时间
'
,
'
项目
'
,
'
金额(万元)
'
]
}
rows
=
{
items
.
map
(
item
=>
{
const
value
=
amount
(
item
)
return
[
text
(
item
,
'
pub_time
'
).
slice
(
0
,
10
),
linked
(
text
(
item
,
'
title
'
),
text
(
item
,
'
url
'
,
'
bid_url
'
)),
value
==
null
?
''
:
format
(
value
)]
})
}
empty
=
"本次未查到对应公告。"
/>
}
function
Purchases
({
data
}:
{
data
:
RecordData
})
{
const
items
=
records
(
data
.
items
)
const
disclosed
=
items
.
flatMap
(
item
=>
{
const
value
=
amount
(
item
);
return
value
==
null
?
[]
:
[
value
]
})
const
topics
=
[...
new
Set
(
items
.
flatMap
(
item
=>
Array
.
isArray
(
item
.
sm_names
)
?
item
.
sm_names
.
filter
((
value
):
value
is
string
=>
typeof
value
===
'
string
'
&&
!!
value
.
trim
())
:
[]))].
slice
(
0
,
5
)
const
total
=
text
(
data
,
'
total
'
)
const
min
=
Math
.
min
(...
disclosed
),
max
=
Math
.
max
(...
disclosed
)
return
<>
<
BusinessTable
title
=
"近一年采购画像"
headers
=
{
[
'
维度
'
,
'
观察
'
]
}
rows
=
{
[
[
'
招标公告
'
,
total
?
`平台命中
${
total
}
条,本次取得
${
items
.
length
}
条`
:
`本次取得
${
items
.
length
}
条`
],
...(
topics
.
length
?
[[
'
涉及标的
'
,
topics
.
join
(
'
、
'
)]]
:
[]),
...(
disclosed
.
length
?
[[
'
样本披露金额
'
,
`
${
format
(
min
)}${
min
===
max
?
''
:
`–
${
format
(
max
)}
`
}
万元(
${
disclosed
.
length
}
条)`
]]
:
[]),
]
}
/>
<
NoticeTable
title
=
"近期采购记录(节选)"
items
=
{
items
}
/>
</>
}
/** 以已核验记录组织报告。候选表只在待确认时展示,确认后转为所选主体和正式画像。 */
export
function
ResearchSections
({
sections
,
choices
}:
Pick
<
ResearchReport
,
'
sections
'
|
'
choices
'
>
)
{
return
sections
?.
map
(
section
=>
<
ResearchSection
key
=
{
section
.
key
}
section
=
{
section
}
choice
=
{
choices
?.
find
(
item
=>
item
.
key
===
section
.
key
)
}
/>)
}
function
ResearchSection
({
section
,
choice
}:
{
section
:
Section
;
choice
?:
ResearchReport
[
'
choices
'
][
number
]
})
{
const
data
=
record
(
section
.
data
),
items
=
records
(
data
.
items
),
{
key
,
tool
}
=
section
if
(
choice
?.
selected
)
{
const
selected
=
choice
.
options
.
find
(
option
=>
option
.
id
===
choice
.
selected
)
return
selected
?
<
p
><
span
className
=
"font-semibold text-ink-900"
>
已确认
{
key
===
'
notice:search
'
?
'
公告
'
:
'
主体
'
}
</
span
>
·
{
selected
.
name
}{
selected
.
region
?
` ·
${
selected
.
region
}
`
:
''
}
</
p
>
:
null
}
if
(
key
.
startsWith
(
'
entity:
'
)
||
key
===
'
buyer:entity
'
)
return
<
BusinessTable
title
=
"候选企业"
headers
=
{
[
'
企业全称
'
,
'
地域
'
]
}
rows
=
{
items
.
map
(
item
=>
[
linked
(
company
(
item
),
text
(
item
,
'
url
'
,
'
company_url
'
)),
region
(
item
)])
}
empty
=
"未找到匹配企业。"
/>
if
(
key
.
endsWith
(
'
:purchases
'
))
return
<
Purchases
data
=
{
data
}
/>
if
(
tool
===
'
search_bids
'
||
tool
===
'
query_bids_advanced
'
)
return
<
NoticeTable
title
=
{
key
.
endsWith
(
'
:wins
'
)
?
'
近期中标记录(节选)
'
:
key
===
'
buyer:history
'
?
'
采购方历史公告
'
:
'
候选项目公告
'
}
items
=
{
items
}
/>
if
(
tool
===
'
get_company_profile
'
||
tool
===
'
get_bid_detail
'
)
{
const
isCompany
=
tool
===
'
get_company_profile
'
const
value
=
amount
(
data
)
const
facts
=
isCompany
?
[
[
'
企业全称
'
,
linked
(
company
(
data
),
text
(
data
,
'
url
'
,
'
company_url
'
))],
[
'
地域
'
,
region
(
data
)],
[
'
行业
'
,
text
(
data
,
'
industry
'
,
'
industry_l1
'
)],
[
'
经营状态
'
,
text
(
data
,
'
business_status
'
)],
[
'
注册资本
'
,
text
(
data
,
'
capital
'
)],
[
'
成立日期
'
,
text
(
data
,
'
establishment_date
'
)],
[
'
招标记录
'
,
text
(
data
,
'
caller_count
'
)],
[
'
中标记录
'
,
text
(
data
,
'
winner_count
'
,
'
win_count
'
)],
[
'
经营范围
'
,
text
(
data
,
'
business_scope
'
)],
]
:
[
[
'
项目
'
,
linked
(
text
(
data
,
'
title
'
),
text
(
data
,
'
url
'
,
'
bid_url
'
))],
[
'
采购方
'
,
text
(
data
,
'
caller_name
'
,
'
purchaser
'
)],
[
'
地域
'
,
region
(
data
)],
[
'
发布日期
'
,
text
(
data
,
'
pub_time
'
)],
[
'
披露金额
'
,
value
==
null
?
''
:
`
${
format
(
value
)}
万元`
],
[
'
代理机构
'
,
text
(
data
,
'
agency_name
'
)],
]
return
<>
<
BusinessTable
title
=
{
isCompany
?
key
.
includes
(
'
:light:
'
)
?
'
竞对基础画像
'
:
'
企业基础画像
'
:
'
项目公告信息
'
}
headers
=
{
[
'
维度
'
,
'
观察
'
]
}
rows
=
{
facts
.
filter
(
row
=>
row
[
1
])
}
/>
{
!
isCompany
&&
<
Excerpt
title
=
"公告正文摘录"
value
=
{
text
(
data
,
'
fulltext
'
,
'
content
'
)
}
/>
}
</>
}
if
(
tool
===
'
get_company_partners
'
)
return
<
BusinessTable
title
=
{
key
.
endsWith
(
'
:customers
'
)
?
'
历史客户
'
:
'
历史供应商
'
}
headers
=
{
[
'
合作单位
'
,
'
合作次数
'
,
'
最近合作
'
]
}
rows
=
{
records
(
data
.
partners
).
map
(
item
=>
[
company
(
item
),
text
(
item
,
'
cooperation_count
'
),
text
(
item
,
'
last_cooperation_time
'
)])
}
/>
if
(
tool
===
'
get_company_business_keywords
'
)
return
<
BusinessTable
title
=
"主要业务品类"
headers
=
{
[
'
业务品类
'
,
'
出现次数
'
]
}
rows
=
{
records
(
data
.
keywords
).
map
(
item
=>
[
text
(
item
,
'
keyword
'
),
text
(
item
,
'
count
'
)])
}
/>
if
(
tool
===
'
aggregate_bids_advanced
'
)
return
<
BusinessTable
title
=
"历史公告统计"
headers
=
{
[
'
统计时段
'
,
'
公告数
'
,
'
金额合计(万元)
'
]
}
rows
=
{
records
(
data
.
buckets
).
map
(
item
=>
{
const
value
=
amount
(
item
,
'
sum_amount_wan
'
,
'
sum_amount
'
)
return
[
text
(
item
,
'
key
'
),
text
(
item
,
'
count
'
),
value
==
null
?
''
:
format
(
value
)]
})
}
/>
if
(
tool
===
'
find_competitors
'
||
tool
===
'
find_potential_bidders
'
)
return
<
BusinessTable
title
=
{
tool
===
'
find_competitors
'
?
'
共同投标的企业
'
:
'
潜在投标方
'
}
headers
=
{
[
'
企业
'
,
'
相关投标记录
'
]
}
rows
=
{
records
(
data
.
competitors
??
data
.
bidders
??
data
.
items
).
map
(
item
=>
[
company
(
item
),
text
(
item
,
'
co_bid_count
'
,
'
caller_history_count
'
,
'
region_win_count
'
)])
}
/>
if
(
tool
===
'
get_price_trends
'
)
{
const
stats
=
record
(
data
.
price_stats
)
return
<
BusinessTable
title
=
"历史单价参考(元)"
headers
=
{
[
'
统计项
'
,
'
金额
'
]
}
rows
=
{
[
[
'
最低
'
,
text
(
stats
,
'
min
'
)],
[
'
最高
'
,
text
(
stats
,
'
max
'
)],
[
'
均价
'
,
text
(
stats
,
'
avg
'
,
'
mean
'
)],
[
'
中位数
'
,
text
(
stats
,
'
median
'
)],
].
filter
(
row
=>
row
[
1
])
}
/>
}
if
(
tool
===
'
web_search
'
)
return
<
BusinessTable
title
=
"公开资料"
headers
=
{
[
'
来源
'
,
'
摘要
'
]
}
rows
=
{
records
(
data
.
results
).
map
(
item
=>
[
linked
(
text
(
item
,
'
title
'
),
text
(
item
,
'
url
'
)),
text
(
item
,
'
snippet
'
).
slice
(
0
,
240
)])
}
/>
if
(
tool
===
'
web_fetch
'
)
return
<
Excerpt
title
=
{
linked
(
text
(
data
,
'
title
'
)
||
'
公开资料摘录
'
,
text
(
data
,
'
url
'
))
}
value
=
{
text
(
data
,
'
content
'
,
'
fulltext
'
)
}
/>
if
(
tool
===
'
FILE_PARSE
'
)
return
<
BusinessTable
title
=
"文件要点摘录"
headers
=
{
[
'
位置
'
,
'
摘录
'
]
}
rows
=
{
records
(
data
.
segments
).
map
(
item
=>
[
text
(
item
,
'
locator
'
),
text
(
item
,
'
text
'
).
slice
(
0
,
240
)])
}
/>
if
(
tool
===
'
vision
'
)
return
<
Excerpt
title
=
"文件页面文字摘录"
value
=
{
text
(
data
,
'
content
'
,
'
text
'
)
}
/>
return
null
}
function
Excerpt
({
title
,
value
}:
{
title
:
ReactNode
;
value
:
string
})
{
if
(
!
value
)
return
null
return
<
details
className
=
"rounded-ctrl bg-canvas px-3 py-1.5"
><
summary
className
=
"cursor-pointer font-medium text-ink-900"
>
{
title
}
</
summary
><
p
className
=
"whitespace-pre-wrap break-words"
>
{
value
.
slice
(
0
,
1500
)
}{
value
.
length
>
1500
?
'
…
'
:
''
}
</
p
></
details
>
}
src/components/ResearchTask.tsx
View file @
969193af
...
@@ -3,38 +3,25 @@ import { Check, CircuitBoard, Loader2 } from 'lucide-react'
...
@@ -3,38 +3,25 @@ import { Check, CircuitBoard, Loader2 } from 'lucide-react'
import
{
useRef
,
useState
}
from
'
react
'
import
{
useRef
,
useState
}
from
'
react
'
import
{
api
}
from
'
../lib/api
'
import
{
api
}
from
'
../lib/api
'
import
{
useTaskEvents
}
from
'
../hooks/useTaskEvents
'
import
{
useTaskEvents
}
from
'
../hooks/useTaskEvents
'
import
type
{
AgentTask
}
from
'
../hooks/useTaskEvents
'
import
type
{
ResearchReport
}
from
'
../lib/day3
'
import
type
{
ResearchReport
}
from
'
../lib/day3
'
import
{
toolNames
}
from
'
../lib/day3
'
import
{
toolNames
}
from
'
../lib/day3
'
import
{
inputClass
,
message
}
from
'
../lib/day2
'
import
{
inputClass
,
message
}
from
'
../lib/day2
'
import
type
{
SearchReport
}
from
'
../lib/day2
'
import
{
MarketReport
}
from
'
./MarketReport
'
import
{
ResearchSections
}
from
'
./ResearchSections
'
import
{
GhostButton
,
PrimaryButton
}
from
'
./ui-ext/AiButton
'
import
{
GhostButton
,
PrimaryButton
}
from
'
./ui-ext/AiButton
'
const
labels
:
Record
<
string
,
string
>
=
{
fullname
:
'
企业全称
'
,
name
:
'
名称
'
,
title
:
'
标题
'
,
province
:
'
省份
'
,
city
:
'
城市
'
,
county
:
'
区县
'
,
industry
:
'
行业
'
,
capital
:
'
注册资本
'
,
size
:
'
企业规模
'
,
business_status
:
'
经营状态
'
,
establishment_date
:
'
成立日期
'
,
business_scope
:
'
经营范围
'
,
caller_count
:
'
招标次数
'
,
winner_count
:
'
中标次数
'
,
company_name
:
'
企业
'
,
company_id
:
'
主体编号
'
,
cooperation_count
:
'
合作次数
'
,
cooperation_amount
:
'
合作金额(元)
'
,
cooperation_amount_wan
:
'
合作金额(万元)
'
,
last_cooperation_time
:
'
最近合作时间
'
,
products
:
'
合作品类
'
,
keywords
:
'
业务词
'
,
partners
:
'
合作伙伴
'
,
items
:
'
公告记录
'
,
total
:
'
平台总数
'
,
bid_id
:
'
公告编号
'
,
pub_time
:
'
发布时间
'
,
money
:
'
金额(元)
'
,
money_wan
:
'
金额(万元)
'
,
caller_name
:
'
采购方
'
,
winner_names
:
'
中标方
'
,
sm_names
:
'
标的物
'
,
fulltext
:
'
正文
'
,
competitors
:
'
竞争者
'
,
co_bid_count
:
'
共同投标次数
'
,
top_co_bid_products
:
'
交锋品类
'
,
top_co_bid_callers
:
'
共同客户
'
,
top_co_bid_provinces
:
'
交锋区域
'
,
keyword
:
'
关键词
'
,
count
:
'
次数
'
,
amount
:
'
金额(元)
'
,
buckets
:
'
聚合结果
'
,
key
:
'
分组
'
,
sum_amount
:
'
金额合计(元)
'
,
total_count
:
'
记录总数
'
,
total_amount
:
'
金额合计(元)
'
,
content
:
'
正文
'
,
results
:
'
公开资料
'
,
snippet
:
'
摘录
'
,
url
:
'
原始来源
'
,
filename
:
'
文件名
'
,
segments
:
'
定位段落
'
,
locator
:
'
位置
'
,
text
:
'
正文
'
,
needsVision
:
'
需视觉识别
'
,
price_stats
:
'
价格统计
'
,
bidders
:
'
潜在投标者
'
,
service_end_date
:
'
服务截止时间
'
,
agency_name
:
'
代理机构
'
}
const
answerTime
=
new
Intl
.
DateTimeFormat
(
'
sv-SE
'
,
{
timeZone
:
'
Asia/Shanghai
'
,
year
:
'
numeric
'
,
month
:
'
2-digit
'
,
day
:
'
2-digit
'
,
hour
:
'
2-digit
'
,
minute
:
'
2-digit
'
}
)
function
sectionTitle
(
section
:
ResearchReport
[
'
sections
'
][
number
])
{
/** 一次提交对应一张卡片,使用同一份任务状态渲染进展、确认表单、正文及完成时间。 */
if
(
section
.
key
.
endsWith
(
'
:customers
'
))
return
'
历史客户
'
export
function
ResearchTask
({
id
,
title
}:
{
id
:
string
;
title
?:
string
})
{
if
(
section
.
key
.
endsWith
(
'
:suppliers
'
))
return
'
历史供应商
'
if
(
section
.
key
.
includes
(
'
:light:
'
))
return
`Top 竞对
${
Number
(
section
.
key
.
split
(
'
:
'
).
at
(
-
1
))
+
1
}
基础画像`
return
toolNames
[
section
.
tool
]
??
section
.
tool
}
/** React 仅渲染文字节点,不解析供应商 HTML;外链再次限制 HTTP(S),保留签名参数。 */
function
Facts
({
value
}:
{
value
:
unknown
})
{
if
(
value
==
null
||
value
===
''
)
return
<
span
className
=
"text-ink-400"
>
未提供
</
span
>
if
(
typeof
value
===
'
string
'
)
return
/^https
?
:
\/\/
/i
.
test
(
value
)
?
<
a
href
=
{
value
}
target
=
"_blank"
rel
=
"noopener noreferrer"
className
=
"break-all text-brand-500 underline"
>
查看原始来源
</
a
>
:
<
span
className
=
"whitespace-pre-wrap break-words"
>
{
value
}
</
span
>
if
(
typeof
value
===
'
boolean
'
)
return
<
span
>
{
value
?
'
是
'
:
'
否
'
}
</
span
>
if
(
typeof
value
===
'
number
'
)
return
<
span
>
{
String
(
value
)
}
</
span
>
if
(
Array
.
isArray
(
value
))
return
value
.
length
?
<
ul
className
=
"space-y-3"
>
{
value
.
map
((
item
,
i
)
=>
<
li
key
=
{
i
}
className
=
"border-l-2 border-line-soft pl-3"
><
Facts
value
=
{
item
}
/></
li
>)
}
</
ul
>
:
<
span
className
=
"text-ink-400"
>
本次未查到记录
</
span
>
return
<
dl
className
=
"space-y-2"
>
{
Object
.
entries
(
value
).
map
(([
key
,
item
])
=>
<
div
key
=
{
key
}
><
dt
className
=
"text-xs text-ink-400"
>
{
labels
[
key
]
??
key
}
</
dt
><
dd
className
=
"mt-1"
><
Facts
value
=
{
item
}
/></
dd
></
div
>)
}
</
dl
>
}
/** 四个调研入口共用真实 SSE、确认、取消、报告与费用组件,页面刷新只读取任务。 */
export
function
ResearchTask
({
id
,
onTask
}:
{
id
:
string
;
onTask
?:
(
task
:
AgentTask
)
=>
void
})
{
const
[
revision
,
setRevision
]
=
useState
(
0
)
const
[
revision
,
setRevision
]
=
useState
(
0
)
const
{
task
,
error
:
streamError
}
=
useTaskEvents
(
id
,
revision
)
const
{
task
,
error
:
streamError
}
=
useTaskEvents
(
id
,
revision
)
const
[
busy
,
setBusy
]
=
useState
(
false
),
[
error
,
setError
]
=
useState
(
''
)
const
[
busy
,
setBusy
]
=
useState
(
false
),
[
error
,
setError
]
=
useState
(
''
)
const
pending
=
useRef
<
{
signature
:
string
;
key
:
string
}
|
null
>
(
null
)
const
pending
=
useRef
<
{
signature
:
string
;
key
:
string
}
|
null
>
(
null
)
const
report
=
task
?.
result
as
ResearchReport
|
null
const
marketTask
=
task
?.
request
.
opportunity
?.
mode
===
'
MARKET
'
const
marketReport
=
marketTask
?
task
?.
result
as
SearchReport
|
null
:
null
const
report
=
!
marketTask
?
task
?.
result
as
ResearchReport
|
null
:
null
const
command
=
async
(
cancel
:
boolean
,
form
?:
HTMLFormElement
)
=>
{
const
command
=
async
(
cancel
:
boolean
,
form
?:
HTMLFormElement
)
=>
{
if
(
!
task
||
busy
)
return
if
(
!
task
||
busy
)
return
setBusy
(
true
);
setError
(
''
)
setBusy
(
true
);
setError
(
''
)
...
@@ -55,34 +42,40 @@ export function ResearchTask({ id, onTask }: { id: string; onTask?: (task: Agent
...
@@ -55,34 +42,40 @@ export function ResearchTask({ id, onTask }: { id: string; onTask?: (task: Agent
pending
.
current
=
null
pending
.
current
=
null
}
}
setRevision
(
x
=>
x
+
1
)
setRevision
(
x
=>
x
+
1
)
onTask
?.(
await
api
<
AgentTask
>
(
`/agent/tasks/
${
id
}
`
))
}
catch
(
e
)
{
setError
(
message
(
e
))
}
finally
{
setBusy
(
false
)
}
}
catch
(
e
)
{
setError
(
message
(
e
))
}
finally
{
setBusy
(
false
)
}
}
}
if
(
!
task
)
return
<
p
role
=
"status"
>
{
streamError
||
'
正在读取任务…
'
}
</
p
>
const
complete
=
!!
task
&&
!
[
'
RECEIVED
'
,
'
PLANNING
'
,
'
RUNNING
'
].
includes
(
task
.
status
)
const
complete
=
[
'
SUCCEEDED
'
,
'
FAILED
'
,
'
PARTIAL
'
,
'
CANCELLED
'
].
includes
(
task
.
status
)
const
hasChoices
=
report
?.
choices
?.
some
(
choice
=>
choice
.
options
.
length
>
0
&&
!
choice
.
selected
)
// 原型的回复由“Skill 调用进展 + 正文”组成,只把真实执行和报告映射到这两个区域。
const
canContinue
=
task
?.
status
!==
'
WAITING_ENTITY
'
||
hasChoices
// 调用账本、模型参数和刷新按钮不属于原型,不再额外插入消息内容。
return
<
article
className
=
"rounded-[16px] bg-white px-4 py-3 shadow-card"
>
return
<
section
className
=
"rounded-card border border-line-soft bg-white px-4 py-3 shadow-card"
>
{
title
&&
<
h2
className
=
"mb-3 whitespace-pre-wrap break-words text-base font-bold text-ink-900"
>
{
title
}
</
h2
>
}
<
div
className
=
"mb-2 rounded-ctrl border border-line-soft bg-canvas px-3 py-2"
>
{
!
task
?
<
p
role
=
"status"
>
{
streamError
||
'
正在读取任务…
'
}
</
p
>
:
<>
<
div
className
=
"mb-3 rounded-ctrl bg-canvas px-3 py-2"
>
<
div
className
=
"flex items-center gap-2 text-[12px] font-semibold text-brand-500"
>
{
complete
?
<
CircuitBoard
size
=
{
13
}
/>
:
<
Loader2
size
=
{
13
}
className
=
"animate-spin"
/>
}
Skill 调用进展
</
div
>
<
div
className
=
"flex items-center gap-2 text-[12px] font-semibold text-brand-500"
>
{
complete
?
<
CircuitBoard
size
=
{
13
}
/>
:
<
Loader2
size
=
{
13
}
className
=
"animate-spin"
/>
}
Skill 调用进展
</
div
>
<
ul
className
=
"mt-1 space-y-1"
>
{
task
.
calls
.
map
(
call
=>
<
li
key
=
{
String
(
call
.
id
)
}
className
=
"flex items-center gap-1.5 text-[12px] text-ink-600"
>
{
call
.
status
===
'
SUCCEEDED
'
?
<
Check
size
=
{
12
}
className
=
"text-ok-500"
/>
:
<
span
className
=
"h-3 w-3"
/>
}{
toolNames
[
String
(
call
.
tool_name
)]
??
String
(
call
.
tool_name
)
}
</
li
>)
}
</
ul
>
<
ul
className
=
"mt-1 space-y-1"
>
{
task
.
calls
.
map
(
call
=>
<
li
key
=
{
String
(
call
.
id
)
}
className
=
"flex items-center gap-1.5 text-[12px] text-ink-600"
>
{
call
.
status
===
'
SUCCEEDED
'
?
<
Check
size
=
{
12
}
className
=
"text-ok-500"
/>
:
<
span
className
=
"h-3 w-3"
/>
}{
toolNames
[
String
(
call
.
tool_name
)]
??
String
(
call
.
tool_name
)
}
</
li
>)
}
</
ul
>
</
div
>
</
div
>
{
(
error
||
streamError
)
&&
<
p
role
=
"alert"
className
=
"mb-2 text-xs text-bad-500"
>
{
error
||
streamError
}
</
p
>
}
{
(
error
||
streamError
)
&&
<
p
role
=
"alert"
className
=
"mb-2 text-xs text-bad-500"
>
{
error
||
streamError
}
</
p
>
}
{
(
task
.
status
.
startsWith
(
'
WAITING_
'
)
||
task
.
status
===
'
FAILED
'
)
&&
task
.
question
&&
<
p
className
=
"mb-3 text-[13px] text-ink-600"
>
{
task
.
question
}
</
p
>
}
{
(
task
.
status
.
startsWith
(
'
WAITING_
'
)
||
task
.
status
===
'
FAILED
'
)
&&
task
.
question
&&
<
p
className
=
"mb-3 text-[13px] text-ink-600"
>
{
task
.
question
}
</
p
>
}
{
task
.
status
.
startsWith
(
'
WAITING_
'
)
&&
<
form
key
=
{
`
${
id
}
:
${
revision
}
:
${
task
.
status
}
`
}
onSubmit
=
{
e
=>
{
e
.
preventDefault
();
void
command
(
false
,
e
.
currentTarget
)
}
}
className
=
"space-y-3 rounded-ctrl bg-canvas p-4"
>
{
task
.
status
.
startsWith
(
'
WAITING_
'
)
&&
<
form
key
=
{
`
${
id
}
:
${
revision
}
:
${
task
.
status
}
`
}
onSubmit
=
{
e
=>
{
e
.
preventDefault
();
void
command
(
false
,
e
.
currentTarget
)
}
}
className
=
"space-y-3 rounded-ctrl bg-canvas p-4"
>
{
task
.
status
===
'
WAITING_ENTITY
'
&&
report
?.
choices
?.
map
(
choice
=>
<
label
key
=
{
choice
.
key
}
className
=
"block text-sm"
>
{
choice
.
key
.
startsWith
(
'
entity:
'
)
?
`企业
${
Number
(
choice
.
key
.
split
(
'
:
'
)[
1
])
+
1
}
`
:
choice
.
key
===
'
buyer:entity
'
?
'
采购方主体
'
:
'
项目公告
'
}
{
task
.
status
===
'
WAITING_ENTITY
'
&&
report
?.
choices
?.
filter
(
choice
=>
choice
.
options
.
length
>
0
&&
!
choice
.
selected
).
map
(
choice
=>
<
label
key
=
{
choice
.
key
}
className
=
"block text-sm"
>
{
choice
.
key
.
startsWith
(
'
entity:
'
)
?
`企业
${
Number
(
choice
.
key
.
split
(
'
:
'
)[
1
])
+
1
}
`
:
choice
.
key
===
'
buyer:entity
'
?
'
采购方主体
'
:
'
项目公告
'
}
<
select
name
=
{
choice
.
key
}
required
defaultValue
=
{
choice
.
selected
}
className
=
{
`
${
inputClass
}
mt-1`
}
><
option
value
=
""
>
选择本次明确主体
</
option
>
{
choice
.
options
.
map
(
option
=>
<
option
key
=
{
option
.
id
}
value
=
{
option
.
id
}
>
{
option
.
name
}
·
{
option
.
region
||
'
地区未知
'
}
·
{
option
.
id
}
</
option
>)
}
</
select
>
<
select
name
=
{
choice
.
key
}
required
defaultValue
=
{
choice
.
selected
}
className
=
{
`
${
inputClass
}
mt-1`
}
><
option
value
=
""
>
选择本次明确主体
</
option
>
{
choice
.
options
.
map
(
option
=>
<
option
key
=
{
option
.
id
}
value
=
{
option
.
id
}
>
{
option
.
name
}
·
{
option
.
region
||
'
地区未知
'
}
·
{
option
.
id
}
</
option
>)
}
</
select
>
</
label
>)
}
</
label
>)
}
{
task
.
status
===
'
WAITING_INPUT
'
&&
task
.
operation
===
'
BID_RESEARCH
'
&&
<
label
className
=
"block text-sm"
>
完整公开项目标题
<
input
name
=
"input"
defaultValue
=
{
task
.
request
.
input
}
maxLength
=
{
2000
}
className
=
{
inputClass
}
/></
label
>
}
{
task
.
status
===
'
WAITING_INPUT
'
&&
task
.
operation
===
'
BID_RESEARCH
'
&&
<
label
className
=
"block text-sm"
>
完整公开项目标题
<
input
name
=
"input"
defaultValue
=
{
task
.
request
.
input
}
maxLength
=
{
2000
}
className
=
{
inputClass
}
/></
label
>
}
{
task
.
status
===
'
WAITING_BUDGET
'
&&
<><
p
className
=
"text-xs text-ink-600"
>
已发生费用保留。继续从下一步执行;未知积分需先核对账单,首个未知单价请求可能超出积分上限。
</
p
><
div
className
=
"grid grid-cols-2 gap-3"
><
label
className
=
"text-sm"
>
累计调用上限
<
input
name
=
"maxCalls"
type
=
"number"
min
=
{
1
}
max
=
{
task
.
request
.
research
?.
companies
.
length
===
1
&&
task
.
operation
===
'
COMPANY_RESEARCH
'
?
18
:
25
}
defaultValue
=
{
task
.
request
.
maxCalls
}
required
className
=
{
inputClass
}
/></
label
><
label
className
=
"text-sm"
>
累计积分上限
<
input
name
=
"maxCostUnits"
type
=
"number"
min
=
"0.01"
max
=
"1000"
step
=
"0.01"
defaultValue
=
{
task
.
request
.
maxCostUnits
}
required
className
=
{
inputClass
}
/></
label
></
div
><
label
className
=
"flex gap-2 text-sm"
><
input
type
=
"checkbox"
required
/>
我已核对现有调用与费用,确认继续后续请求
</
label
></>
}
{
task
.
status
===
'
WAITING_BUDGET
'
&&
<><
p
className
=
"text-xs text-ink-600"
>
已发生费用保留。继续从下一步执行;未知积分需先核对账单,首个未知单价请求可能超出积分上限。
</
p
><
div
className
=
"grid grid-cols-2 gap-3"
><
label
className
=
"text-sm"
>
累计调用上限
<
input
name
=
"maxCalls"
type
=
"number"
min
=
{
1
}
max
=
{
task
.
request
.
research
?.
companies
.
length
===
1
&&
task
.
operation
===
'
COMPANY_RESEARCH
'
?
18
:
25
}
defaultValue
=
{
task
.
request
.
maxCalls
}
required
className
=
{
inputClass
}
/></
label
><
label
className
=
"text-sm"
>
累计积分上限
<
input
name
=
"maxCostUnits"
type
=
"number"
min
=
"0.01"
max
=
"1000"
step
=
"0.01"
defaultValue
=
{
task
.
request
.
maxCostUnits
}
required
className
=
{
inputClass
}
/></
label
></
div
><
label
className
=
"flex gap-2 text-sm"
><
input
type
=
"checkbox"
required
/>
我已核对现有调用与费用,确认继续后续请求
</
label
></>
}
<
div
className
=
"flex gap-2"
><
GhostButton
disabled
=
{
busy
}
onClick
=
{
()
=>
void
command
(
true
)
}
>
取消
</
GhostButton
><
PrimaryButton
disabled
=
{
busy
}
type
=
"submit"
>
确认并继续
</
PrimaryButton
></
div
>
<
div
className
=
"flex gap-2"
><
GhostButton
disabled
=
{
busy
}
onClick
=
{
()
=>
void
command
(
true
)
}
>
取消
</
GhostButton
>
{
canContinue
&&
<
PrimaryButton
disabled
=
{
busy
}
type
=
"submit"
>
确认并继续
</
PrimaryButton
>
}
</
div
>
</
form
>
}
</
form
>
}
{
marketReport
&&
<
MarketReport
report
=
{
marketReport
}
/>
}
{
report
&&
<
div
className
=
"space-y-4 text-sm leading-7 text-ink-600"
>
{
report
&&
<
div
className
=
"space-y-4 text-sm leading-7 text-ink-600"
>
{
report
.
observations
?.
map
((
item
,
index
)
=>
<
p
key
=
{
index
}
>
{
item
.
text
}
</
p
>)
}
{
!!
report
.
observations
?.
length
&&
<
section
>
<
h3
className
=
"font-semibold text-ink-900"
>
{
report
.
kind
===
'
SNAPSHOT_QA
'
?
'
回答
'
:
'
调研结论
'
}
</
h3
>
{
report
.
observations
.
map
((
item
,
index
)
=>
<
p
key
=
{
index
}
className
=
"whitespace-pre-wrap"
>
{
item
.
text
}
</
p
>)
}
</
section
>
}
{
report
.
ownFit
&&
<
div
><
h3
className
=
"font-semibold text-ink-900"
>
结合公司档案对照
</
h3
><
p
>
贴合度参考:
{
report
.
ownFit
.
match
.
score
??
'
资料不足
'
}
分
</
p
>
{
Object
.
entries
(
report
.
ownFit
.
match
.
dimensions
).
map
(([
key
,
dimension
])
=>
<
p
key
=
{
key
}
className
=
"text-[13px]"
>
{
dimension
.
basis
}
</
p
>)
}
</
div
>
}
{
report
.
ownFit
&&
<
div
><
h3
className
=
"font-semibold text-ink-900"
>
结合公司档案对照
</
h3
><
p
>
贴合度参考:
{
report
.
ownFit
.
match
.
score
??
'
资料不足
'
}
分
</
p
>
{
Object
.
entries
(
report
.
ownFit
.
match
.
dimensions
).
map
(([
key
,
dimension
])
=>
<
p
key
=
{
key
}
className
=
"text-[13px]"
>
{
dimension
.
basis
}
</
p
>)
}
</
div
>
}
{
report
.
commonCustomers
&&
<
div
><
h3
className
=
"font-semibold text-ink-900"
>
共同客户
</
h3
><
p
>
{
report
.
commonCustomers
.
join
(
'
、
'
)
||
'
当前样本未检出共同客户
'
}
</
p
></
div
>
}
{
report
.
commonCustomers
&&
<
div
><
h3
className
=
"font-semibold text-ink-900"
>
共同客户
</
h3
><
p
>
{
report
.
commonCustomers
.
join
(
'
、
'
)
||
'
当前样本未检出共同客户
'
}
</
p
></
div
>
}
{
report
.
sections
?.
map
(
section
=>
<
div
key
=
{
section
.
key
}
><
h3
className
=
"mb-2 font-semibold text-ink-900"
>
{
sectionTitle
(
section
)
}
</
h3
><
Facts
value
=
{
section
.
data
}
/></
div
>)
}
<
ResearchSections
sections
=
{
report
.
sections
}
choices
=
{
report
.
choices
}
/>
{
report
.
gaps
?.
length
>
0
&&
<
ul
className
=
"list-disc space-y-1 pl-5 text-[13px]"
>
{
report
.
gaps
.
map
(
gap
=>
<
li
key
=
{
gap
}
>
{
gap
}
</
li
>)
}
</
ul
>
}
{
report
.
gaps
?.
length
>
0
&&
<
ul
className
=
"list-disc space-y-1 pl-5 text-[13px]"
>
{
report
.
gaps
.
map
(
gap
=>
<
li
key
=
{
gap
}
>
{
gap
}
</
li
>)
}
</
ul
>
}
</
div
>
}
</
div
>
}
</
section
>
{
task
.
answeredAt
&&
<
time
dateTime
=
{
task
.
answeredAt
}
className
=
"mt-3 block font-num text-[11px] text-ink-400"
>
{
answerTime
.
format
(
new
Date
(
task
.
answeredAt
))
}
</
time
>
}
</>
}
</
article
>
}
}
src/hooks/useTaskEvents.ts
View file @
969193af
...
@@ -14,6 +14,7 @@ export interface AgentTask {
...
@@ -14,6 +14,7 @@ export interface AgentTask {
status
:
string
status
:
string
operation
:
string
operation
:
string
question
:
string
|
null
question
:
string
|
null
answeredAt
?:
string
|
null
result
:
unknown
result
:
unknown
usage
?:
{
external_calls
:
number
;
zlbx_calls
:
number
;
known_cost_units
:
number
;
unknown_cost_calls
:
number
;
model_web_calls
:
number
;
input_tokens
:
number
;
output_tokens
:
number
;
unknown_token_calls
:
number
}
usage
?:
{
external_calls
:
number
;
zlbx_calls
:
number
;
known_cost_units
:
number
;
unknown_cost_calls
:
number
;
model_web_calls
:
number
;
input_tokens
:
number
;
output_tokens
:
number
;
unknown_token_calls
:
number
}
request
:
{
operation
:
string
;
workflow
:
string
;
input
:
string
;
entityConfirmed
:
boolean
;
maxCalls
:
number
;
maxCostUnits
:
number
;
opportunity
?:
SearchQuery
;
research
?:
ResearchRequest
;
qa
?:
QaScope
}
request
:
{
operation
:
string
;
workflow
:
string
;
input
:
string
;
entityConfirmed
:
boolean
;
maxCalls
:
number
;
maxCostUnits
:
number
;
opportunity
?:
SearchQuery
;
research
?:
ResearchRequest
;
qa
?:
QaScope
}
...
...
src/lib/day2.ts
View file @
969193af
...
@@ -32,7 +32,7 @@ export interface RankedItem {
...
@@ -32,7 +32,7 @@ export interface RankedItem {
}
}
export
interface
SearchReport
{
export
interface
SearchReport
{
conditions
:
SearchQuery
;
rankingVersion
:
string
conditions
:
SearchQuery
;
rankingVersion
:
string
scope
:
{
platformTotal
:
number
|
null
;
fetchedCount
:
number
;
uniqueCount
:
number
;
displayCount
:
number
;
pagesRead
:
number
;
stopReason
:
string
;
complete
:
boolean
}
scope
:
{
platformTotal
:
number
|
null
;
fetchedCount
:
number
;
uniqueCount
:
number
;
displayCount
:
number
;
pagesRead
:
number
;
stopReason
:
string
;
complete
:
boolean
;
budgetFilteredLocally
?:
boolean
}
stageChains
:
{
projectNumber
:
string
;
purchaser
:
string
;
notices
:
Candidate
[];
basis
:
string
}[]
stageChains
:
{
projectNumber
:
string
;
purchaser
:
string
;
notices
:
Candidate
[];
basis
:
string
}[]
items
:
RankedItem
[];
limitations
:
string
[];
referencesVerified
:
boolean
items
:
RankedItem
[];
limitations
:
string
[];
referencesVerified
:
boolean
summaryProgress
:
{
completed
:
number
;
total
:
number
;
method
:
string
}
summaryProgress
:
{
completed
:
number
;
total
:
number
;
method
:
string
}
...
@@ -82,11 +82,40 @@ export function words(value: string) { return value.split(/[、,,;;\n]+/).ma
...
@@ -82,11 +82,40 @@ export function words(value: string) { return value.split(/[、,,;;\n]+/).ma
export
function
message
(
error
:
unknown
)
{
return
error
instanceof
Error
?
error
.
message
:
'
请求失败,请重试
'
}
export
function
message
(
error
:
unknown
)
{
return
error
instanceof
Error
?
error
.
message
:
'
请求失败,请重试
'
}
export
function
time
(
value
:
string
)
{
return
new
Date
(
value
).
toLocaleString
(
'
zh-CN
'
,
{
timeZone
:
'
Asia/Shanghai
'
,
hour12
:
false
})
}
export
function
time
(
value
:
string
)
{
return
new
Date
(
value
).
toLocaleString
(
'
zh-CN
'
,
{
timeZone
:
'
Asia/Shanghai
'
,
hour12
:
false
})
}
/** 仅格式化原文明确写出的报名截止日期;不拿投标日期代替,也不把无效日期自动顺延。 */
const
registration
=
/报名
(?:
及获取文件
)?
|
(?:
获取|领取|下载|购买
)(?:
招标|采购|磋商|询价|比选
)
文件/g
const
calendarDate
=
/^
(\d{4})\s
*
[
-年
/
.
]\s
*
(\d{1,2})\s
*
[
-月
/
.
]\s
*
(\d{1,2})
/
/** 仅在报名或获取采购文件的条款内读取截止日。日期区间取尾端,投标、开标和服务结束日期不能补位。 */
export
function
registrationDate
(
schedule
:
string
[]
=
[]):
string
|
null
{
export
function
registrationDate
(
schedule
:
string
[]
=
[]):
string
|
null
{
const
match
=
schedule
.
join
(
'
;
'
).
match
(
/报名
(?:
时间
)?(?:
截止|截至
)(?:
时间
)?\s
*
[
::
]?\s
*
(\d{4})[
-年
/
.
](\d{1,2})[
-月
/
.
](\d{1,2})
/
)
for
(
const
clause
of
schedule
.
flatMap
(
line
=>
line
.
split
(
/
[
,,;;。
\n]
/
)))
{
if
(
!
match
)
return
null
for
(
const
marker
of
clause
.
matchAll
(
registration
))
{
const
related
=
clause
.
slice
(
marker
.
index
+
marker
[
0
].
length
).
split
(
/
(?:
递交|提交
)(?:
投标|响应
)
|投标截止|响应截止|开标|服务
(?:
截止|期
)
|工期/
)[
0
]
const
end
=
related
.
match
(
/
(?:
截止|截至|结束
)(?:
时间|日期
)?\s
*
[
::为至到于
]?\s
*
(
.+
)
/
)
??
related
.
match
(
/
(?:
至|到|
[
~~—–
])\s
*
(
.+
)
/
)
const
match
=
end
?.[
1
].
match
(
calendarDate
)
if
(
!
match
)
continue
const
value
=
`
${
match
[
1
]}
-
${
match
[
2
].
padStart
(
2
,
'
0
'
)}
-
${
match
[
3
].
padStart
(
2
,
'
0
'
)}
`
const
value
=
`
${
match
[
1
]}
-
${
match
[
2
].
padStart
(
2
,
'
0
'
)}
-
${
match
[
3
].
padStart
(
2
,
'
0
'
)}
`
const
date
=
new
Date
(
`
${
value
}
T00:00:00Z`
)
const
date
=
new
Date
(
`
${
value
}
T00:00:00Z`
)
return
Number
.
isFinite
(
date
.
getTime
())
&&
date
.
toISOString
().
slice
(
0
,
10
)
===
value
?
value
:
null
if
(
Number
.
isFinite
(
date
.
getTime
())
&&
date
.
toISOString
().
slice
(
0
,
10
)
===
value
)
return
value
}
}
return
null
}
/** 用北京时间的两个日历日计算剩余天数,避免临近午夜时用小时差造成前后一天的偏差。 */
export
function
registrationReminder
(
schedule
?:
string
[],
today
=
beijingDate
())
{
const
date
=
registrationDate
(
schedule
)
if
(
!
date
)
return
null
const
days
=
(
Date
.
parse
(
date
)
-
Date
.
parse
(
today
))
/
86400000
return
{
date
,
days
,
label
:
days
<
0
?
'
报名已截止
'
:
days
===
0
?
'
报名今天截止
'
:
`报名仅剩
${
days
}
天`
}
}
export
function
budgetLabel
(
conditions
:
SearchQuery
)
{
const
preference
=
conditions
.
mode
===
'
LEADS
'
const
min
=
preference
?
conditions
.
budgetMinWan
:
conditions
.
hardMinWan
const
max
=
preference
?
conditions
.
budgetMaxWan
:
conditions
.
hardMaxWan
if
(
min
==
null
&&
max
==
null
)
return
''
const
bounds
=
min
!=
null
&&
max
!=
null
?
`
${
min
.
toLocaleString
(
'
zh-CN
'
)}
–
${
max
.
toLocaleString
(
'
zh-CN
'
)}
`
:
min
!=
null
?
`≥
${
min
.
toLocaleString
(
'
zh-CN
'
)}
`
:
`≤
${
max
!
.
toLocaleString
(
'
zh-CN
'
)}
`
return
`
${
preference
?
'
预算偏好
'
:
'
预算
'
}
${
bounds
}
万元`
}
}
src/lib/day3.ts
View file @
969193af
...
@@ -26,4 +26,5 @@ export const toolNames: Record<string, string> = {
...
@@ -26,4 +26,5 @@ export const toolNames: Record<string, string> = {
get_company_partners
:
'
客户与供应商
'
,
query_bids_advanced
:
'
历史公告明细
'
,
aggregate_bids_advanced
:
'
历史聚合统计
'
,
get_company_partners
:
'
客户与供应商
'
,
query_bids_advanced
:
'
历史公告明细
'
,
aggregate_bids_advanced
:
'
历史聚合统计
'
,
find_competitors
:
'
真实投标竞对
'
,
search_bids
:
'
定位项目公告
'
,
get_bid_detail
:
'
项目正文
'
,
find_potential_bidders
:
'
潜在投标者
'
,
get_price_trends
:
'
品牌型号历史单价
'
,
find_competitors
:
'
真实投标竞对
'
,
search_bids
:
'
定位项目公告
'
,
get_bid_detail
:
'
项目正文
'
,
find_potential_bidders
:
'
潜在投标者
'
,
get_price_trends
:
'
品牌型号历史单价
'
,
web_search
:
'
检索公开资料
'
,
web_fetch
:
'
读取公开网页
'
,
model_json
:
'
生成有据建议
'
,
vision
:
'
识别文件页面
'
,
FILE_PARSE
:
'
本地文件提取
'
,
ENTITY_CACHE
:
'
读取已确认主体(缓存)
'
,
web_search
:
'
检索公开资料
'
,
web_fetch
:
'
读取公开网页
'
,
model_json
:
'
生成有据建议
'
,
vision
:
'
识别文件页面
'
,
FILE_PARSE
:
'
本地文件提取
'
,
ENTITY_CACHE
:
'
读取已确认主体(缓存)
'
,
get_top_purchasers
:
'
统计主要采购方
'
,
get_top_suppliers
:
'
统计主要中标企业
'
,
}
}
src/pages/DiscoverPage.tsx
View file @
969193af
...
@@ -7,7 +7,7 @@ import { useStore } from '../lib/store'
...
@@ -7,7 +7,7 @@ import { useStore } from '../lib/store'
import
{
useTaskEvents
}
from
'
../hooks/useTaskEvents
'
import
{
useTaskEvents
}
from
'
../hooks/useTaskEvents
'
import
type
{
AgentTask
}
from
'
../hooks/useTaskEvents
'
import
type
{
AgentTask
}
from
'
../hooks/useTaskEvents
'
import
type
{
SearchQuery
,
SearchReport
,
SearchHistory
,
SearchScheme
}
from
'
../lib/day2
'
import
type
{
SearchQuery
,
SearchReport
,
SearchHistory
,
SearchScheme
}
from
'
../lib/day2
'
import
{
initialQuery
,
asSearchQuery
,
publicationRange
,
beijingDate
,
registrationDate
,
inputClass
,
words
,
message
,
time
}
from
'
../lib/day2
'
import
{
initialQuery
,
asSearchQuery
,
publicationRange
,
beijingDate
,
registrationDate
,
budgetLabel
,
inputClass
,
words
,
message
,
time
}
from
'
../lib/day2
'
import
{
PrimaryButton
,
GhostButton
}
from
'
../components/ui-ext/AiButton
'
import
{
PrimaryButton
,
GhostButton
}
from
'
../components/ui-ext/AiButton
'
import
{
BEE_IMG
}
from
'
../lib/assets
'
import
{
BEE_IMG
}
from
'
../lib/assets
'
...
@@ -31,7 +31,7 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
...
@@ -31,7 +31,7 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
const
[
range
,
setRange
]
=
useState
(
'
30
'
)
const
[
range
,
setRange
]
=
useState
(
'
30
'
)
const
[
regionText
,
setRegionText
]
=
useState
(
''
)
const
[
regionText
,
setRegionText
]
=
useState
(
''
)
const
[
limits
,
setLimits
]
=
useState
({
maxCalls
:
5
,
maxCostUnits
:
10
})
const
[
limits
,
setLimits
]
=
useState
({
maxCalls
:
5
,
maxCostUnits
:
10
})
const
[
bud
ge
t
,
set
Bud
ge
t
]
=
useState
(
{
maxCalls
:
2
,
maxCostUnits
:
2
}
)
const
[
searchMaxPa
ge
s
,
set
SearchMaxPa
ge
s
]
=
useState
(
5
)
const
[
schemes
,
setSchemes
]
=
useState
<
SearchScheme
[]
>
([])
const
[
schemes
,
setSchemes
]
=
useState
<
SearchScheme
[]
>
([])
const
[
history
,
setHistory
]
=
useState
<
SearchHistory
[]
>
([])
const
[
history
,
setHistory
]
=
useState
<
SearchHistory
[]
>
([])
const
selected
=
params
.
get
(
'
batch
'
)
??
history
.
find
(
run
=>
run
.
schemeId
)?.
id
??
null
const
selected
=
params
.
get
(
'
batch
'
)
??
history
.
find
(
run
=>
run
.
schemeId
)?.
id
??
null
...
@@ -54,9 +54,10 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
...
@@ -54,9 +54,10 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
return
pending
.
current
.
key
return
pending
.
current
.
key
}
}
const
reload
=
useCallback
(
async
()
=>
{
const
reload
=
useCallback
(
async
()
=>
{
const
[
saved
,
runs
,
allowed
]
=
await
Promise
.
all
([
api
<
SearchScheme
[]
>
(
'
/search-schemes
'
),
api
<
SearchHistory
[]
>
(
'
/searches
'
),
api
<
{
maxCalls
:
number
;
maxCostUnits
:
number
}
>
(
'
/system/limits
'
)])
const
[
saved
,
runs
,
allowed
]
=
await
Promise
.
all
([
api
<
SearchScheme
[]
>
(
'
/search-schemes
'
),
api
<
SearchHistory
[]
>
(
'
/searches
'
),
api
<
{
maxCalls
:
number
;
maxCostUnits
:
number
;
searchMaxPages
:
number
}
>
(
'
/system/limits
'
)])
setSchemes
(
saved
);
setHistory
(
runs
);
setLimits
(
allowed
)
setSchemes
(
saved
);
setHistory
(
runs
)
setBudget
(
current
=>
({
maxCalls
:
Math
.
min
(
current
.
maxCalls
,
allowed
.
maxCalls
),
maxCostUnits
:
Math
.
min
(
current
.
maxCostUnits
,
allowed
.
maxCostUnits
)
}))
setLimits
({
maxCalls
:
allowed
.
maxCalls
,
maxCostUnits
:
allowed
.
maxCostUnits
})
setSearchMaxPages
(
allowed
.
searchMaxPages
)
},
[])
},
[])
useEffect
(()
=>
{
void
reload
().
catch
(
e
=>
setError
(
message
(
e
)))
},
[
reload
])
useEffect
(()
=>
{
void
reload
().
catch
(
e
=>
setError
(
message
(
e
)))
},
[
reload
])
const
update
=
<
K
extends
keyof
SearchQuery
>
(key: K, value: SearchQuery[K]) => setQuery(current => (
{
...
current
,
[
key
]:
value
}
))
const
update
=
<
K
extends
keyof
SearchQuery
>
(key: K, value: SearchQuery[K]) => setQuery(current => (
{
...
current
,
[
key
]:
value
}
))
...
@@ -76,7 +77,8 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
...
@@ -76,7 +77,8 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
const
conditions
=
{
...
query
,
keywords
:
keyword
.
split
(
/
[\s
、,,;;
]
+/
).
filter
(
Boolean
)
}
const
conditions
=
{
...
query
,
keywords
:
keyword
.
split
(
/
[\s
、,,;;
]
+/
).
filter
(
Boolean
)
}
if
(
conditions
.
keywords
.
length
===
0
&&
conditions
.
mode
!==
'
MARKET
'
)
throw
new
Error
(
'
请填写关键词,使用逗号分隔
'
)
if
(
conditions
.
keywords
.
length
===
0
&&
conditions
.
mode
!==
'
MARKET
'
)
throw
new
Error
(
'
请填写关键词,使用逗号分隔
'
)
if
(
conditions
.
beginDate
>
conditions
.
endDate
)
throw
new
Error
(
'
开始日期不能晚于结束日期
'
)
if
(
conditions
.
beginDate
>
conditions
.
endDate
)
throw
new
Error
(
'
开始日期不能晚于结束日期
'
)
const
payload
=
{
conditions
,
...
budget
}
// 普通检索尽量读满部署允许的页数,预算筛选即使首两页无命中也能继续检查后续页。
const
payload
=
{
conditions
,
maxCalls
:
Math
.
min
(
limits
.
maxCalls
,
searchMaxPages
),
maxCostUnits
:
Math
.
min
(
10
,
limits
.
maxCostUnits
)
}
const
next
=
await
api
<
AgentTask
>
(
'
/searches
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
keyFor
(
payload
)
},
body
:
JSON
.
stringify
(
payload
)
})
const
next
=
await
api
<
AgentTask
>
(
'
/searches
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
keyFor
(
payload
)
},
body
:
JSON
.
stringify
(
payload
)
})
pending
.
current
=
null
;
choose
(
next
.
id
);
setRevision
(
v
=>
v
+
1
);
await
reload
()
pending
.
current
=
null
;
choose
(
next
.
id
);
setRevision
(
v
=>
v
+
1
);
await
reload
()
}
)
}
)
...
@@ -91,7 +93,7 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
...
@@ -91,7 +93,7 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
// 原型只展示本次检索结果;服务端仍保留完整快照,不在页面另加审计与调试区域。
// 原型只展示本次检索结果;服务端仍保留完整快照,不在页面另加审计与调试区域。
const report = task?.result as SearchReport | null
const report = task?.result as SearchReport | null
const dirty = !!report
&&
JSON.stringify(
{
...
query
,
keywords
:
keyword
.
split
(
/
[\s
、,,;;
]
+/
).
filter
(
Boolean
)
}
) !== JSON.stringify(report.conditions)
const dirty = !!report
&&
JSON.stringify(
{
...
query
,
keywords
:
keyword
.
split
(
/
[\s
、,,;;
]
+/
).
filter
(
Boolean
)
}
) !== JSON.stringify(report.conditions)
const active = task
&&
!['SUCCEEDED', 'FAILED', 'PARTIAL', 'CANCELLED'].includes(task.status)
&&
!task.status.startsWith('WAITING_')
const active =
!!
task
&&
!['SUCCEEDED', 'FAILED', 'PARTIAL', 'CANCELLED'].includes(task.status)
&&
!task.status.startsWith('WAITING_')
// 问候条使用北京时间;仅展示服务端已有关注,不以原型示例公司或示例项目填充。
// 问候条使用北京时间;仅展示服务端已有关注,不以原型示例公司或示例项目填充。
const local = new Date(new Date().toLocaleString('en-US',
{
timeZone
:
'
Asia/Shanghai
'
}
))
const local = new Date(new Date().toLocaleString('en-US',
{
timeZone
:
'
Asia/Shanghai
'
}
))
...
@@ -112,7 +114,7 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
...
@@ -112,7 +114,7 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
const schemeRuns = history.filter((run, index) => run.schemeId
&&
history.findIndex(other => other.schemeId === run.schemeId) === index)
const schemeRuns = history.filter((run, index) => run.schemeId
&&
history.findIndex(other => other.schemeId === run.schemeId) === index)
const manualRun = history.find(run => !run.schemeId)
const manualRun = history.find(run => !run.schemeId)
const conditions = report?.conditions
const conditions = report?.conditions
const conditionLabel = conditions ? [conditions.keywords.length ? `关键词「$
{
conditions
.
keywords
.
join
(
'
'
)
}
」` : '', (conditions.mode === 'LEADS' ? conditions.preferredRegions : conditions.hardRegions).length ? `地区「$
{
(
conditions
.
mode
===
'
LEADS
'
?
conditions
.
preferredRegions
:
conditions
.
hardRegions
).
join
(
'
、
'
)
}
」` : '', `发布时间 $
{
conditions
.
beginDate
}
至 $
{
conditions
.
endDate
}
`].filter(Boolean).join(' · ') : ''
const conditionLabel = conditions ? [conditions.keywords.length ? `关键词「$
{
conditions
.
keywords
.
join
(
'
'
)
}
」` : '', (conditions.mode === 'LEADS' ? conditions.preferredRegions : conditions.hardRegions).length ? `地区「$
{
(
conditions
.
mode
===
'
LEADS
'
?
conditions
.
preferredRegions
:
conditions
.
hardRegions
).
join
(
'
、
'
)
}
」` : '', `发布时间 $
{
conditions
.
beginDate
}
至 $
{
conditions
.
endDate
}
`
, budgetLabel(conditions)
].filter(Boolean).join(' · ') : ''
return
<
div
className
=
"mx-auto max-w-[1120px] px-4 py-4 sm:px-5 sm:py-5 xl:px-6"
>
return
<
div
className
=
"mx-auto max-w-[1120px] px-4 py-4 sm:px-5 sm:py-5 xl:px-6"
>
{
profile
.
completed
?
<
div
className
=
"relative overflow-hidden rounded-card p-6 shadow-card fade-up"
style
=
{
{
background
:
'
linear-gradient(115deg, #1D19DC 0%, #2E54E8 52%, #3F8BF0 100%)
'
}
}
>
{
profile
.
completed
?
<
div
className
=
"relative overflow-hidden rounded-card p-6 shadow-card fade-up"
style
=
{
{
background
:
'
linear-gradient(115deg, #1D19DC 0%, #2E54E8 52%, #3F8BF0 100%)
'
}
}
>
<
div
className
=
"pointer-events-none absolute -top-24 right-40 h-52 w-52 rounded-full border border-white/15"
/><
div
className
=
"pointer-events-none absolute -top-12 right-52 h-28 w-28 rounded-full border border-white/10"
/><
div
className
=
"pointer-events-none absolute -bottom-16 right-72 h-32 w-32 rounded-full bg-white/5"
/>
<
div
className
=
"pointer-events-none absolute -top-24 right-40 h-52 w-52 rounded-full border border-white/15"
/><
div
className
=
"pointer-events-none absolute -top-12 right-52 h-28 w-28 rounded-full border border-white/10"
/><
div
className
=
"pointer-events-none absolute -bottom-16 right-72 h-32 w-32 rounded-full bg-white/5"
/>
...
@@ -159,12 +161,16 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
...
@@ -159,12 +161,16 @@ export function DiscoverPage({ onOpenPanel }: { onOpenPanel: (state: AnalysisPan
</
form
>
</
form
>
</
PrototypeDialog
>
</
PrototypeDialog
>
{
(
selected
||
history
.
some
(
run
=>
run
.
schemeId
))
?
<
section
className
=
"mt-4 overflow-hidden rounded-card border border-line-soft bg-white shadow-card"
>
{
(
selected
||
history
.
some
(
run
=>
run
.
schemeId
))
?
<
section
className
=
"mt-4 overflow-hidden rounded-card border border-line-soft bg-white shadow-card"
>
<
div
className
=
"flex flex-wrap items-center gap-2 border-b border-line-soft px-5 py-3"
>
{
schemeRuns
.
length
>
0
&&
<
Layers
size
=
{
15
}
className
=
"text-brand-500"
/>
}
<
h2
className
=
"text-[15px] font-bold"
>
{
schemeRuns
.
length
?
'
检索结果
'
:
'
全部结果
'
}
</
h2
>
{
schemeRuns
.
length
?
<
div
role
=
"tablist"
aria
-
label
=
"检索结果"
className
=
"ml-1 flex gap-0.5 rounded-full bg-[#F4F7FB] p-0.5"
><
button
role
=
"tab"
aria
-
selected
=
{
selected
===
manualRun
?.
id
}
disabled
=
{
!
manualRun
}
onClick
=
{
()
=>
{
if
(
manualRun
)
choose
(
manualRun
.
id
)
}
}
className
=
{
`rounded-full px-3 py-1 text-xs
${
selected
===
manualRun
?.
id
?
'
bg-white font-medium text-brand-500 shadow-card
'
:
'
text-ink-600 hover:text-brand-500
'
}
`
}
>
当前结果
</
button
>
{
schemeRuns
.
map
(
run
=>
<
button
key
=
{
run
.
id
}
role
=
"tab"
aria
-
selected
=
{
selected
===
run
.
id
}
onClick
=
{
()
=>
choose
(
run
.
id
)
}
className
=
{
`rounded-full px-3 py-1 text-xs
${
selected
===
run
.
id
?
'
bg-white font-medium text-brand-500 shadow-card
'
:
'
text-ink-600 hover:text-brand-500
'
}
`
}
>
{
run
.
schemeName
}
结果
</
button
>)
}
</
div
>
:
report
&&
<><
span
className
=
"rounded-full bg-brand-50 px-2.5 py-0.5 font-num text-xs font-bold text-brand-500"
>
共
{
report
.
items
.
length
}
条
</
span
><
span
className
=
"text-xs text-ink-400"
>
{
conditionLabel
}
</
span
></>
}
<
span
className
=
"flex-1"
/></
div
>
<
div
className
=
"flex flex-wrap items-center gap-2 border-b border-line-soft px-5 py-3"
>
{
schemeRuns
.
length
>
0
&&
<
Layers
size
=
{
15
}
className
=
"text-brand-500"
/>
}
<
h2
className
=
"text-[15px] font-bold"
>
{
schemeRuns
.
length
?
'
检索结果
'
:
'
全部结果
'
}
</
h2
>
{
schemeRuns
.
length
?
<
div
role
=
"tablist"
aria
-
label
=
"检索结果"
className
=
"ml-1 flex gap-0.5 rounded-full bg-[#F4F7FB] p-0.5"
><
button
role
=
"tab"
aria
-
selected
=
{
selected
===
manualRun
?.
id
}
disabled
=
{
!
manualRun
}
onClick
=
{
()
=>
{
if
(
manualRun
)
choose
(
manualRun
.
id
)
}
}
className
=
{
`rounded-full px-3 py-1 text-xs
${
selected
===
manualRun
?.
id
?
'
bg-white font-medium text-brand-500 shadow-card
'
:
'
text-ink-600 hover:text-brand-500
'
}
`
}
>
当前结果
</
button
>
{
schemeRuns
.
map
(
run
=>
<
button
key
=
{
run
.
id
}
role
=
"tab"
aria
-
selected
=
{
selected
===
run
.
id
}
onClick
=
{
()
=>
choose
(
run
.
id
)
}
className
=
{
`rounded-full px-3 py-1 text-xs
${
selected
===
run
.
id
?
'
bg-white font-medium text-brand-500 shadow-card
'
:
'
text-ink-600 hover:text-brand-500
'
}
`
}
>
{
run
.
schemeName
}
结果
</
button
>)
}
</
div
>
:
report
&&
<><
span
className
=
"rounded-full bg-brand-50 px-2.5 py-0.5 font-num text-xs font-bold text-brand-500"
>
共
{
report
.
items
.
length
}
条
</
span
><
span
className
=
"text-xs text-ink-400"
>
{
conditionLabel
}
</
span
></>
}
<
span
className
=
"flex-1"
/>
{
/* 只传批次 ID,问答侧栏独立读取服务端快照。页面分页、结果筛选和排序都留在列表组件内。 */
}
{
task
&&
!!
report
?.
items
.
length
&&
<
GhostButton
disabled
=
{
active
}
onClick
=
{
()
=>
onOpenPanel
({
kind
:
'
search
'
,
batchId
:
task
.
id
,
resultCount
:
report
.
items
.
length
,
complete
:
report
.
scope
.
complete
})
}
className
=
"!px-3 !py-1.5 text-xs"
><
Sparkles
size
=
{
14
}
/>
基于本次搜索提问
</
GhostButton
>
}
</
div
>
{
schemeRuns
.
length
>
0
&&
report
&&
<
div
className
=
"flex flex-wrap items-center gap-2 border-b border-line-soft px-5 py-2 text-xs text-ink-400"
><
span
>
{
conditionLabel
}
</
span
><
span
>
·
</
span
><
span
>
{
history
.
find
(
run
=>
run
.
id
===
selected
)?.
schemeId
?
`最近执行
${
time
(
history
.
find
(
run
=>
run
.
id
===
selected
)
!
.
createdAt
)}
`
:
'
手动检索
'
}
</
span
><
span
>
·
</
span
><
span
>
共
<
span
className
=
"font-num text-ink-900"
>
{
report
.
items
.
length
}
</
span
>
条
</
span
></
div
>
}
{
schemeRuns
.
length
>
0
&&
report
&&
<
div
className
=
"flex flex-wrap items-center gap-2 border-b border-line-soft px-5 py-2 text-xs text-ink-400"
><
span
>
{
conditionLabel
}
</
span
><
span
>
·
</
span
><
span
>
{
history
.
find
(
run
=>
run
.
id
===
selected
)?.
schemeId
?
`最近执行
${
time
(
history
.
find
(
run
=>
run
.
id
===
selected
)
!
.
createdAt
)}
`
:
'
手动检索
'
}
</
span
><
span
>
·
</
span
><
span
>
共
<
span
className
=
"font-num text-ink-900"
>
{
report
.
items
.
length
}
</
span
>
条
</
span
></
div
>
}
{
!
selected
&&
<
p
className
=
"py-16 text-center text-sm text-ink-400"
>
选择历史快照回查,或在上方设置条件开始检索。
</
p
>
}
{
!
selected
&&
<
p
className
=
"py-16 text-center text-sm text-ink-400"
>
选择历史快照回查,或在上方设置条件开始检索。
</
p
>
}
{
selected
&&
!
task
&&
<
p
className
=
"p-6 text-sm"
role
=
"status"
>
正在加载任务快照…
</
p
>
}
{
selected
&&
!
task
&&
<
p
className
=
"p-6 text-sm"
role
=
"status"
>
正在加载任务快照…
</
p
>
}
{
task
&&
<>
{
task
&&
<>
{
report
?.
scope
.
budgetFilteredLocally
&&
!
report
.
scope
.
complete
&&
<
p
className
=
"border-b border-line-soft px-5 py-2 text-xs text-ink-400"
>
预算已筛选
{
report
.
scope
.
fetchedCount
}
条已读取公告,未读取部分尚未纳入。
</
p
>
}
{
task
.
status
!==
'
SUCCEEDED
'
&&
<
div
className
=
"flex flex-wrap items-center gap-3 px-5 py-3 text-xs"
><
span
className
=
"rounded-full bg-brand-50 px-3 py-1 text-brand-500"
>
{
taskStates
[
task
.
status
]
??
task
.
status
}
</
span
><
span
>
{
task
.
question
}
</
span
>
{
active
&&
<
GhostButton
disabled
=
{
busy
}
onClick
=
{
()
=>
void
runAction
(
async
()
=>
{
await
api
(
`/agent/tasks/
${
task
.
id
}
/cancel`
,
{
method
:
'
POST
'
});
setRevision
(
v
=>
v
+
1
)
})
}
>
取消后续请求
</
GhostButton
>
}{
task
.
status
.
startsWith
(
'
WAITING_
'
)
&&
<
GhostButton
disabled
=
{
busy
}
onClick
=
{
()
=>
void
runAction
(
async
()
=>
{
const
conditions
=
task
.
request
.
opportunity
;
if
(
!
conditions
)
return
;
const
payload
=
{
conditions
,
...
limits
};
await
api
(
`/searches/
${
task
.
id
}
/continue`
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
keyFor
({
continue
:
task
.
id
,
...
payload
})
},
body
:
JSON
.
stringify
(
payload
)
});
pending
.
current
=
null
;
setRevision
(
v
=>
v
+
1
)
})
}
>
{
task
.
status
===
'
WAITING_BUDGET
'
?
`确认提高至
${
limits
.
maxCalls
}
次 /
${
limits
.
maxCostUnits
}
积分并继续`
:
'
已补配置,继续原任务
'
}
</
GhostButton
>
}
</
div
>
}
{
task
.
status
!==
'
SUCCEEDED
'
&&
<
div
className
=
"flex flex-wrap items-center gap-3 px-5 py-3 text-xs"
><
span
className
=
"rounded-full bg-brand-50 px-3 py-1 text-brand-500"
>
{
taskStates
[
task
.
status
]
??
task
.
status
}
</
span
><
span
>
{
task
.
question
}
</
span
>
{
active
&&
<
GhostButton
disabled
=
{
busy
}
onClick
=
{
()
=>
void
runAction
(
async
()
=>
{
await
api
(
`/agent/tasks/
${
task
.
id
}
/cancel`
,
{
method
:
'
POST
'
});
setRevision
(
v
=>
v
+
1
)
})
}
>
取消后续请求
</
GhostButton
>
}{
task
.
status
.
startsWith
(
'
WAITING_
'
)
&&
<
GhostButton
disabled
=
{
busy
}
onClick
=
{
()
=>
void
runAction
(
async
()
=>
{
const
conditions
=
task
.
request
.
opportunity
;
if
(
!
conditions
)
return
;
const
payload
=
{
conditions
,
...
limits
};
await
api
(
`/searches/
${
task
.
id
}
/continue`
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
keyFor
({
continue
:
task
.
id
,
...
payload
})
},
body
:
JSON
.
stringify
(
payload
)
});
pending
.
current
=
null
;
setRevision
(
v
=>
v
+
1
)
})
}
>
{
task
.
status
===
'
WAITING_BUDGET
'
?
`确认提高至
${
limits
.
maxCalls
}
次 /
${
limits
.
maxCostUnits
}
积分并继续`
:
'
已补配置,继续原任务
'
}
</
GhostButton
>
}
</
div
>
}
{
report
&&
<>
{
active
&&
!
report
.
items
.
length
?
<
p
role
=
"status"
className
=
"p-12 text-center text-sm text-ink-400"
>
正在检索并整理公告…
</
p
>
:
<
OpportunityTable
key
=
{
selected
}
items
=
{
report
.
items
}
batchId
=
{
task
.
id
}
onOpenPanel
=
{
onOpenPanel
}
/>
}
</>
}
{
report
&&
<>
{
active
&&
!
report
.
items
.
length
?
<
p
role
=
"status"
className
=
"p-12 text-center text-sm text-ink-400"
>
正在检索并整理公告…
</
p
>
:
<
OpportunityTable
key
=
{
selected
}
items
=
{
report
.
items
}
batchId
=
{
task
.
id
}
onOpenPanel
=
{
onOpenPanel
}
/>
}
</>
}
...
...
src/pages/ResearchPage.tsx
View file @
969193af
import
{
createUuid
}
from
'
../lib/uuid
'
import
{
createUuid
}
from
'
../lib/uuid
'
import
{
useEffect
,
useRef
,
useState
}
from
'
react
'
import
{
useEffect
,
useRef
,
useState
}
from
'
react
'
import
{
useNavigate
,
useSearchParams
}
from
'
react-router
'
import
{
useSearchParams
}
from
'
react-router
'
import
{
MessagesSquare
,
UserSearch
,
GitCompareArrows
,
Map
,
Send
,
X
,
Loader2
}
from
'
lucide-react
'
import
{
MessagesSquare
,
UserSearch
,
GitCompareArrows
,
Map
,
Send
,
X
,
Loader2
}
from
'
lucide-react
'
import
{
api
}
from
'
../lib/api
'
import
{
api
}
from
'
../lib/api
'
import
{
conversationsChanged
}
from
'
../lib/conversations
'
import
{
conversationsChanged
}
from
'
../lib/conversations
'
import
type
{
Conversation
}
from
'
../lib/conversations
'
import
type
{
Conversation
}
from
'
../lib/conversations
'
import
type
{
AgentTask
}
from
'
../hooks/useTaskEvents
'
import
type
{
AgentTask
}
from
'
../hooks/useTaskEvents
'
import
type
{
ResearchRequest
}
from
'
../lib/day3
'
import
type
{
ResearchRequest
}
from
'
../lib/day3
'
import
{
initialQuery
,
message
,
words
}
from
'
../lib/day2
'
import
{
message
}
from
'
../lib/day2
'
import
{
ConversationView
}
from
'
../components/ConversationView
'
import
{
ConversationView
}
from
'
../components/ConversationView
'
import
{
ResearchTask
}
from
'
../components/ResearchTask
'
import
{
ResearchTask
}
from
'
../components/ResearchTask
'
import
{
PrimaryButton
}
from
'
../components/ui-ext/AiButton
'
import
{
PrimaryButton
}
from
'
../components/ui-ext/AiButton
'
...
@@ -21,7 +21,6 @@ const ENTRIES = [
...
@@ -21,7 +21,6 @@ const ENTRIES = [
/** 界面只使用原型的三个入口及输入框;真实任务仍在服务端创建、确认和保存。 */
/** 界面只使用原型的三个入口及输入框;真实任务仍在服务端创建、确认和保存。 */
export
function
ResearchPage
()
{
export
function
ResearchPage
()
{
const
[
params
,
setParams
]
=
useSearchParams
()
const
[
params
,
setParams
]
=
useSearchParams
()
const
navigate
=
useNavigate
()
const
entry
=
params
.
get
(
'
entry
'
)
||
''
const
entry
=
params
.
get
(
'
entry
'
)
||
''
const
selected
=
params
.
get
(
'
task
'
)
const
selected
=
params
.
get
(
'
task
'
)
const
conversationId
=
params
.
get
(
'
conv
'
)
const
conversationId
=
params
.
get
(
'
conv
'
)
...
@@ -30,16 +29,18 @@ export function ResearchPage() {
...
@@ -30,16 +29,18 @@ export function ResearchPage() {
const
[
busy
,
setBusy
]
=
useState
(
false
),
[
error
,
setError
]
=
useState
(
''
)
const
[
busy
,
setBusy
]
=
useState
(
false
),
[
error
,
setError
]
=
useState
(
''
)
const
[
budget
,
setBudget
]
=
useState
({
maxCalls
:
18
,
maxCostUnits
:
10
})
const
[
budget
,
setBudget
]
=
useState
({
maxCalls
:
18
,
maxCostUnits
:
10
})
const
[
fileId
,
setFileId
]
=
useState
<
string
|
null
>
(
null
)
const
[
fileId
,
setFileId
]
=
useState
<
string
|
null
>
(
null
)
const
inFlight
=
useRef
(
false
)
const
pending
=
useRef
<
{
signature
:
string
;
key
:
string
;
conversationId
?:
string
}
|
null
>
(
null
)
const
pending
=
useRef
<
{
signature
:
string
;
key
:
string
;
conversationId
?:
string
}
|
null
>
(
null
)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
entry
!==
'
project
'
&&
!
params
.
get
(
'
parent
'
))
return
let
active
=
true
let
active
=
true
//
请求保护沿用服务端上限,不为了展示技术参数增加原型没有的设置入口
。
//
项目和关联采购方仍按结构化任务提交;普通对话的预算由服务端统一选择
。
void
api
<
{
maxCalls
:
number
;
maxCostUnits
:
number
}
>
(
'
/system/limits
'
).
then
(
value
=>
{
void
api
<
{
maxCalls
:
number
;
maxCostUnits
:
number
}
>
(
'
/system/limits
'
).
then
(
value
=>
{
if
(
active
)
setBudget
({
maxCalls
:
Math
.
min
(
18
,
value
.
maxCalls
),
maxCostUnits
:
Math
.
min
(
10
,
value
.
maxCostUnits
)
})
if
(
active
)
setBudget
({
maxCalls
:
Math
.
min
(
18
,
value
.
maxCalls
),
maxCostUnits
:
Math
.
min
(
10
,
value
.
maxCostUnits
)
})
}).
catch
(
e
=>
{
if
(
active
)
setError
(
message
(
e
))
})
}).
catch
(
e
=>
{
if
(
active
)
setError
(
message
(
e
))
})
return
()
=>
{
active
=
false
}
return
()
=>
{
active
=
false
}
},
[])
},
[
entry
,
params
])
useEffect
(()
=>
{
useEffect
(()
=>
{
const
id
=
params
.
get
(
'
file
'
)
const
id
=
params
.
get
(
'
file
'
)
if
(
!
id
)
return
if
(
!
id
)
return
...
@@ -53,36 +54,34 @@ export function ResearchPage() {
...
@@ -53,36 +54,34 @@ export function ResearchPage() {
return
()
=>
{
active
=
false
}
return
()
=>
{
active
=
false
}
},
[
params
])
},
[
params
])
const
create
=
async
(
request
:
unknown
,
path
=
'
/agent/tasks
'
)
=>
{
const
create
=
async
(
request
:
unknown
,
structured
=
false
)
=>
{
const
signature
=
`
${
path
}
:
${
JSON
.
stringify
(
request
)}
`
const
signature
=
`
${
structured
}
:
${
JSON
.
stringify
(
request
)}
`
if
(
pending
.
current
?.
signature
!==
signature
)
pending
.
current
=
{
signature
,
key
:
createUuid
()
}
if
(
pending
.
current
?.
signature
!==
signature
)
pending
.
current
=
{
signature
,
key
:
createUuid
()
}
if
(
!
pending
.
current
.
conversationId
)
{
if
(
!
pending
.
current
.
conversationId
)
{
const
conversation
=
await
api
<
Conversation
>
(
'
/conversations
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
title
:
''
})
})
const
conversation
=
await
api
<
Conversation
>
(
'
/conversations
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
title
:
''
})
})
pending
.
current
.
conversationId
=
conversation
.
id
pending
.
current
.
conversationId
=
conversation
.
id
}
}
// 响应未知时保留原键和会话;重试只回读同一次提交,不重复创建收费任务。
// 响应未知时保留原键和会话;重试只回读同一次提交,不重复创建收费任务。
const
task
=
await
api
<
AgentTask
>
(
path
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
pending
.
current
.
key
},
body
:
JSON
.
stringify
(
request
)
})
const
conv
=
pending
.
current
.
conversationId
const
conv
=
pending
.
current
.
conversationId
await
api
(
`/conversations/
${
conv
}
/
tasks
`
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
{
taskId
:
task
.
id
}
)
})
const
task
=
await
api
<
AgentTask
>
(
structured
?
'
/agent/tasks
'
:
`/conversations/
${
conv
}
/
research
`
,
{
method
:
'
POST
'
,
headers
:
{
'
Idempotency-Key
'
:
pending
.
current
.
key
},
body
:
JSON
.
stringify
(
request
)
})
pending
.
current
=
null
;
conversationsChanged
(
)
if
(
structured
)
await
api
(
`/conversations/
${
conv
}
/tasks`
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
taskId
:
task
.
id
})
}
)
if
(
path
===
'
/searches
'
)
navigate
(
`/?batch=
${
task
.
id
}
`
)
pending
.
current
=
null
;
setInput
(
''
);
conversationsChanged
(
)
else
setParams
({
conv
})
setParams
({
conv
})
}
}
const
start
=
async
()
=>
{
const
start
=
async
()
=>
{
if
(
busy
||
(
!
input
.
trim
()
&&
!
fileId
))
return
if
(
inFlight
.
current
||
(
!
input
.
trim
()
&&
!
fileId
))
return
inFlight
.
current
=
true
setBusy
(
true
);
setError
(
''
)
setBusy
(
true
);
setError
(
''
)
try
{
try
{
if
(
entry
===
'
market
'
)
{
if
(
entry
===
'
project
'
||
(
entry
!==
'
market
'
&&
params
.
has
(
'
parent
'
)))
{
await
create
({
conditions
:
{
...
initialQuery
(),
keywords
:
words
(
input
),
mode
:
'
MARKET
'
},
...
budget
},
'
/searches
'
)
}
else
{
const
project
=
entry
===
'
project
'
const
project
=
entry
===
'
project
'
const
research
:
ResearchRequest
=
{
const
research
:
ResearchRequest
=
{
companies
:
project
?
[]
:
[
input
.
trim
()],
selections
:
{},
mode
:
'
QUICK
'
,
fileId
:
project
?
fileId
:
null
,
companies
:
project
?
[]
:
[
input
.
trim
()],
selections
:
{},
mode
:
'
QUICK
'
,
fileId
:
project
?
fileId
:
null
,
parentId
:
params
.
get
(
'
parent
'
),
targetProjectId
:
params
.
get
(
'
project
'
),
focus
:
null
,
acknowledgedCalls
:
0
,
parentId
:
params
.
get
(
'
parent
'
),
targetProjectId
:
params
.
get
(
'
project
'
),
focus
:
null
,
acknowledgedCalls
:
0
,
}
}
await
create
({
operation
:
project
?
'
BID_RESEARCH
'
:
'
COMPANY_RESEARCH
'
,
workflow
:
project
?
'
BID_DECISION
'
:
'
COMPANY_INTEL
'
,
input
:
project
?
input
.
trim
()
:
''
,
entityConfirmed
:
false
,
...
budget
,
research
})
await
create
({
operation
:
project
?
'
BID_RESEARCH
'
:
'
COMPANY_RESEARCH
'
,
workflow
:
project
?
'
BID_DECISION
'
:
'
COMPANY_INTEL
'
,
input
:
project
?
input
.
trim
()
:
''
,
entityConfirmed
:
false
,
...
budget
,
research
}
,
true
)
}
}
else
await
create
({
question
:
input
.
trim
(),
entry
:
ENTRIES
.
find
(
item
=>
item
.
key
===
entry
)?.
key
})
}
catch
(
e
)
{
setError
(
message
(
e
))
}
finally
{
setBusy
(
false
)
}
}
catch
(
e
)
{
setError
(
message
(
e
))
}
finally
{
inFlight
.
current
=
false
;
setBusy
(
false
)
}
}
}
if
(
conversationId
||
qaBatch
||
qaProject
)
return
<
ConversationView
key
=
{
conversationId
??
`
${
qaBatch
}
:
${
qaProject
}
`
}
id
=
{
conversationId
??
undefined
}
scope
=
{
qaBatch
||
qaProject
?
{
batchId
:
qaBatch
,
projectId
:
qaProject
}
:
undefined
}
/>
if
(
conversationId
||
qaBatch
||
qaProject
)
return
<
ConversationView
key
=
{
conversationId
??
`
${
qaBatch
}
:
${
qaProject
}
`
}
id
=
{
conversationId
??
undefined
}
scope
=
{
qaBatch
||
qaProject
?
{
batchId
:
qaBatch
,
projectId
:
qaProject
}
:
undefined
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment