Spaces:
Running
Running
feat: add agent submission to Supabase storage
Browse files- agent_submissions_setup.sql +20 -0
- src/views/AddAssetView.vue +46 -9
agent_submissions_setup.sql
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- 1. 添加 agent_submissions_data JSON 列
|
| 2 |
+
ALTER TABLE trading_decisions
|
| 3 |
+
ADD COLUMN IF NOT EXISTS agent_submissions_data JSONB;
|
| 4 |
+
|
| 5 |
+
-- 2. 初始化数据(在 InvestorAgent, 2025-08-01, BTC, gpt_4.1 这一行)
|
| 6 |
+
UPDATE trading_decisions
|
| 7 |
+
SET agent_submissions_data = '[]'::jsonb
|
| 8 |
+
WHERE agent_name = 'InvestorAgent'
|
| 9 |
+
AND date = '2025-08-01'
|
| 10 |
+
AND asset = 'BTC'
|
| 11 |
+
AND model = 'gpt_4.1';
|
| 12 |
+
|
| 13 |
+
-- 3. 验证(可选)
|
| 14 |
+
SELECT agent_name, date, asset, model, agent_submissions_data
|
| 15 |
+
FROM trading_decisions
|
| 16 |
+
WHERE agent_name = 'InvestorAgent'
|
| 17 |
+
AND date = '2025-08-01'
|
| 18 |
+
AND asset = 'BTC'
|
| 19 |
+
AND model = 'gpt_4.1';
|
| 20 |
+
|
src/views/AddAssetView.vue
CHANGED
|
@@ -214,17 +214,53 @@ export default {
|
|
| 214 |
this.agentForm.message = ''
|
| 215 |
|
| 216 |
try {
|
| 217 |
-
//
|
| 218 |
-
const
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
name: this.agentForm.name,
|
| 221 |
endpoint: this.agentForm.endpoint,
|
| 222 |
description: this.agentForm.description,
|
| 223 |
-
timestamp: new Date().toISOString()
|
| 224 |
-
|
| 225 |
-
|
| 226 |
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
this.agentForm.messageType = 'success'
|
| 229 |
|
| 230 |
// 滚动到消息位置
|
|
@@ -235,7 +271,7 @@ export default {
|
|
| 235 |
}
|
| 236 |
})
|
| 237 |
|
| 238 |
-
//
|
| 239 |
setTimeout(() => {
|
| 240 |
this.agentForm.name = ''
|
| 241 |
this.agentForm.endpoint = ''
|
|
@@ -245,7 +281,8 @@ export default {
|
|
| 245 |
|
| 246 |
} catch (error) {
|
| 247 |
console.error('Error submitting agent:', error)
|
| 248 |
-
|
|
|
|
| 249 |
this.agentForm.messageType = 'error'
|
| 250 |
|
| 251 |
// 滚动到消息位置
|
|
|
|
| 214 |
this.agentForm.message = ''
|
| 215 |
|
| 216 |
try {
|
| 217 |
+
// 读取现有的 agent submissions 数据
|
| 218 |
+
const { data: row, error: fetchError } = await supabase
|
| 219 |
+
.from('trading_decisions')
|
| 220 |
+
.select('agent_submissions_data')
|
| 221 |
+
.eq('agent_name', 'InvestorAgent')
|
| 222 |
+
.eq('date', '2025-08-01')
|
| 223 |
+
.eq('asset', 'BTC')
|
| 224 |
+
.eq('model', 'gpt_4.1')
|
| 225 |
+
.single()
|
| 226 |
+
|
| 227 |
+
if (fetchError) throw fetchError
|
| 228 |
+
|
| 229 |
+
let submissions = row?.agent_submissions_data || []
|
| 230 |
+
|
| 231 |
+
const agentSubmission = {
|
| 232 |
name: this.agentForm.name,
|
| 233 |
endpoint: this.agentForm.endpoint,
|
| 234 |
description: this.agentForm.description,
|
| 235 |
+
timestamp: new Date().toISOString(),
|
| 236 |
+
votes: 1
|
| 237 |
+
}
|
| 238 |
|
| 239 |
+
// 检查是否已存在相同 name 的 agent
|
| 240 |
+
const existingIndex = submissions.findIndex(s => s.name === agentSubmission.name)
|
| 241 |
+
if (existingIndex >= 0) {
|
| 242 |
+
// 重复提交时更新所有信息和增加投票
|
| 243 |
+
submissions[existingIndex].votes += 1
|
| 244 |
+
submissions[existingIndex].timestamp = agentSubmission.timestamp
|
| 245 |
+
submissions[existingIndex].endpoint = agentSubmission.endpoint
|
| 246 |
+
submissions[existingIndex].description = agentSubmission.description
|
| 247 |
+
} else {
|
| 248 |
+
submissions.push(agentSubmission)
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// 更新到 Supabase
|
| 252 |
+
const { error: updateError } = await supabase
|
| 253 |
+
.from('trading_decisions')
|
| 254 |
+
.update({ agent_submissions_data: submissions })
|
| 255 |
+
.eq('agent_name', 'InvestorAgent')
|
| 256 |
+
.eq('date', '2025-08-01')
|
| 257 |
+
.eq('asset', 'BTC')
|
| 258 |
+
.eq('model', 'gpt_4.1')
|
| 259 |
+
|
| 260 |
+
if (updateError) throw updateError
|
| 261 |
+
|
| 262 |
+
// 显示成功消息并清空表单
|
| 263 |
+
this.agentForm.message = 'Agent submitted successfully! Thank you for joining the arena.'
|
| 264 |
this.agentForm.messageType = 'success'
|
| 265 |
|
| 266 |
// 滚动到消息位置
|
|
|
|
| 271 |
}
|
| 272 |
})
|
| 273 |
|
| 274 |
+
// 5秒后清空表单
|
| 275 |
setTimeout(() => {
|
| 276 |
this.agentForm.name = ''
|
| 277 |
this.agentForm.endpoint = ''
|
|
|
|
| 281 |
|
| 282 |
} catch (error) {
|
| 283 |
console.error('Error submitting agent:', error)
|
| 284 |
+
console.error('Error details:', JSON.stringify(error, null, 2))
|
| 285 |
+
this.agentForm.message = `Failed to submit agent: ${error.message || 'Please try again'}`
|
| 286 |
this.agentForm.messageType = 'error'
|
| 287 |
|
| 288 |
// 滚动到消息位置
|