@agentxv2/gateway 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +53 -0
- package/db/migrations/001_init.sql +117 -0
- package/db/migrations/002_agents.sql +20 -0
- package/db/migrations/003_a2a_results.sql +23 -0
- package/deploy/.env.deploy.example +23 -0
- package/deploy/add_swap_build.py +45 -0
- package/deploy/build_and_deploy.py +110 -0
- package/deploy/build_deploy_a2a.py +190 -0
- package/deploy/build_no_lint.py +52 -0
- package/deploy/build_on_fe.py +86 -0
- package/deploy/build_on_gw.py +98 -0
- package/deploy/build_prod.py +54 -0
- package/deploy/check_bal.py +31 -0
- package/deploy/check_code.py +47 -0
- package/deploy/check_deploy.sh +20 -0
- package/deploy/check_docs.py +16 -0
- package/deploy/check_frontend.py +42 -0
- package/deploy/check_frontend2.py +35 -0
- package/deploy/check_pks.py +34 -0
- package/deploy/check_status.py +32 -0
- package/deploy/check_v2.py +8 -0
- package/deploy/clean_install.py +28 -0
- package/deploy/deploy_a2a.py +58 -0
- package/deploy/deploy_a2a.sh +33 -0
- package/deploy/deploy_a2a_bg.sh +40 -0
- package/deploy/deploy_a2a_v2.py +151 -0
- package/deploy/deploy_a2a_v2.sh +36 -0
- package/deploy/deploy_bin.py +64 -0
- package/deploy/deploy_config.py +34 -0
- package/deploy/deploy_final.py +42 -0
- package/deploy/deploy_frontend.py +108 -0
- package/deploy/deploy_mcp.py +108 -0
- package/deploy/deploy_now.py +49 -0
- package/deploy/deploy_push_all.py +128 -0
- package/deploy/deploy_script.py +64 -0
- package/deploy/deploy_sep_a2a.sh +18 -0
- package/deploy/dev_mode.py +51 -0
- package/deploy/diag.py +12 -0
- package/deploy/diff_test.py +22 -0
- package/deploy/final_check.py +33 -0
- package/deploy/final_deploy.py +50 -0
- package/deploy/final_fix.py +54 -0
- package/deploy/final_push.py +114 -0
- package/deploy/find_frontend.py +38 -0
- package/deploy/fix_a2a.py +43 -0
- package/deploy/fix_and_build.py +77 -0
- package/deploy/fix_and_verify.py +56 -0
- package/deploy/fix_build.py +51 -0
- package/deploy/forge_deploy.py +67 -0
- package/deploy/full_push.py +101 -0
- package/deploy/full_push2.py +106 -0
- package/deploy/go_prod.py +59 -0
- package/deploy/gw_deploy.py +133 -0
- package/deploy/gw_final.py +206 -0
- package/deploy/gw_restart.py +28 -0
- package/deploy/gw_status.py +18 -0
- package/deploy/inline_build.py +99 -0
- package/deploy/one_shot.py +84 -0
- package/deploy/ox_deploy.py +32 -0
- package/deploy/pg_setup.py +36 -0
- package/deploy/prod_deploy.py +126 -0
- package/deploy/prod_final.py +140 -0
- package/deploy/prod_go.py +61 -0
- package/deploy/prod_one_shot.py +139 -0
- package/deploy/prod_setup.sh +62 -0
- package/deploy/prod_v2.py +91 -0
- package/deploy/prod_v3.py +103 -0
- package/deploy/push_docs.py +93 -0
- package/deploy/push_mcp.py +66 -0
- package/deploy/push_mcp_doc.py +28 -0
- package/deploy/push_v063.py +80 -0
- package/deploy/push_v2.py +71 -0
- package/deploy/qcheck.py +13 -0
- package/deploy/qcheck2.py +18 -0
- package/deploy/quick_check.py +8 -0
- package/deploy/rebuild.py +47 -0
- package/deploy/rebuild_frontend.py +44 -0
- package/deploy/restart.py +28 -0
- package/deploy/restore_frontend.py +42 -0
- package/deploy/restore_frontend2.py +41 -0
- package/deploy/restore_gateway.py +34 -0
- package/deploy/restore_quick.py +33 -0
- package/deploy/run_bash.py +19 -0
- package/deploy/run_sep.py +20 -0
- package/deploy/sdk_upgrade.py +50 -0
- package/deploy/server_prepare.py +41 -0
- package/deploy/server_setup.py +41 -0
- package/deploy/ssh_check.py +14 -0
- package/deploy/ssh_push.py +24 -0
- package/deploy/start_deploy.py +35 -0
- package/deploy/start_frontend.py +12 -0
- package/deploy/start_v2.py +29 -0
- package/deploy/stat.py +18 -0
- package/deploy/tail_log.py +11 -0
- package/deploy/update_env.py +32 -0
- package/deploy/upload_and_start.py +107 -0
- package/deploy/verify_a2a.py +13 -0
- package/deploy/verify_mcp.py +37 -0
- package/deploy/verify_sdk.py +21 -0
- package/dist/config.d.ts +26 -0
- package/dist/config.js +41 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +149 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/crypto.d.ts +2 -0
- package/dist/lib/crypto.js +43 -0
- package/dist/lib/crypto.js.map +1 -0
- package/dist/lib/db.d.ts +3 -0
- package/dist/lib/db.js +26 -0
- package/dist/lib/db.js.map +1 -0
- package/dist/lib/ethers-utils.d.ts +60 -0
- package/dist/lib/ethers-utils.js +186 -0
- package/dist/lib/ethers-utils.js.map +1 -0
- package/dist/middleware/adminAuth.d.ts +2 -0
- package/dist/middleware/adminAuth.js +31 -0
- package/dist/middleware/adminAuth.js.map +1 -0
- package/dist/middleware/auth.d.ts +22 -0
- package/dist/middleware/auth.js +192 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/error-handler.d.ts +36 -0
- package/dist/middleware/error-handler.js +100 -0
- package/dist/middleware/error-handler.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +5 -0
- package/dist/middleware/rate-limiter.js +107 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/routes/a2a.d.ts +2 -0
- package/dist/routes/a2a.js +84 -0
- package/dist/routes/a2a.js.map +1 -0
- package/dist/routes/admin.d.ts +2 -0
- package/dist/routes/admin.js +180 -0
- package/dist/routes/admin.js.map +1 -0
- package/dist/routes/agents.d.ts +2 -0
- package/dist/routes/agents.js +43 -0
- package/dist/routes/agents.js.map +1 -0
- package/dist/routes/chat.d.ts +2 -0
- package/dist/routes/chat.js +183 -0
- package/dist/routes/chat.js.map +1 -0
- package/dist/routes/history.d.ts +2 -0
- package/dist/routes/history.js +92 -0
- package/dist/routes/history.js.map +1 -0
- package/dist/routes/mcp.d.ts +13 -0
- package/dist/routes/mcp.js +513 -0
- package/dist/routes/mcp.js.map +1 -0
- package/dist/routes/tenant.d.ts +2 -0
- package/dist/routes/tenant.js +154 -0
- package/dist/routes/tenant.js.map +1 -0
- package/dist/services/a2a-worker.d.ts +7 -0
- package/dist/services/a2a-worker.js +406 -0
- package/dist/services/a2a-worker.js.map +1 -0
- package/dist/services/agent-indexer.d.ts +4 -0
- package/dist/services/agent-indexer.js +124 -0
- package/dist/services/agent-indexer.js.map +1 -0
- package/e2e_wallet.js +175 -0
- package/ecosystem.config.js +17 -0
- package/package.json +33 -0
- package/src/config.ts +47 -0
- package/src/index.ts +143 -0
- package/src/lib/crypto.ts +44 -0
- package/src/lib/db.ts +25 -0
- package/src/lib/ethers-utils.ts +229 -0
- package/src/middleware/adminAuth.ts +34 -0
- package/src/middleware/auth.ts +244 -0
- package/src/middleware/error-handler.ts +109 -0
- package/src/middleware/rate-limiter.ts +115 -0
- package/src/routes/a2a.ts +97 -0
- package/src/routes/admin.ts +219 -0
- package/src/routes/agents.ts +52 -0
- package/src/routes/chat.ts +219 -0
- package/src/routes/history.ts +114 -0
- package/src/routes/mcp.ts +567 -0
- package/src/routes/tenant.ts +196 -0
- package/src/services/a2a-worker.ts +486 -0
- package/src/services/agent-indexer.ts +127 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// AgentX Gateway — Chat History Routes
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
import { Router, Request, Response } from 'express'
|
|
6
|
+
import { getPool } from '../lib/db'
|
|
7
|
+
|
|
8
|
+
const router = Router()
|
|
9
|
+
|
|
10
|
+
// GET /api/v1/chat/history/:agentId
|
|
11
|
+
router.get('/history/:agentId', async (req: Request, res: Response) => {
|
|
12
|
+
const agentId = parseInt(req.params.agentId, 10)
|
|
13
|
+
if (isNaN(agentId)) {
|
|
14
|
+
res.status(400).json({ error: 'Invalid agentId' })
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const limit = Math.min(parseInt(req.query.limit as string || '100', 10), 500)
|
|
19
|
+
const before = req.query.before as string | undefined
|
|
20
|
+
|
|
21
|
+
const pool = getPool()
|
|
22
|
+
let result
|
|
23
|
+
if (before) {
|
|
24
|
+
result = await pool.query(
|
|
25
|
+
`SELECT id, agent_id, role, content, tool_name, tool_input, tool_output, created_at
|
|
26
|
+
FROM chat_messages
|
|
27
|
+
WHERE tenant_id = $1 AND agent_id = $2 AND id < $3
|
|
28
|
+
ORDER BY id DESC
|
|
29
|
+
LIMIT $4`,
|
|
30
|
+
[req.tenant!.id, agentId, before, limit]
|
|
31
|
+
)
|
|
32
|
+
} else {
|
|
33
|
+
result = await pool.query(
|
|
34
|
+
`SELECT id, agent_id, role, content, tool_name, tool_input, tool_output, created_at
|
|
35
|
+
FROM chat_messages
|
|
36
|
+
WHERE tenant_id = $1 AND agent_id = $2
|
|
37
|
+
ORDER BY id DESC
|
|
38
|
+
LIMIT $3`,
|
|
39
|
+
[req.tenant!.id, agentId, limit]
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
res.json({
|
|
44
|
+
messages: result.rows.reverse(),
|
|
45
|
+
agent_id: agentId,
|
|
46
|
+
has_more: result.rows.length >= limit,
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// POST /api/v1/chat/history/:agentId
|
|
51
|
+
router.post('/history/:agentId', async (req: Request, res: Response) => {
|
|
52
|
+
const agentId = parseInt(req.params.agentId, 10)
|
|
53
|
+
if (isNaN(agentId)) {
|
|
54
|
+
res.status(400).json({ error: 'Invalid agentId' })
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { messages } = req.body
|
|
59
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
60
|
+
res.status(400).json({ error: 'messages array is required' })
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const pool = getPool()
|
|
65
|
+
const client = await pool.connect()
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await client.query('BEGIN')
|
|
69
|
+
await client.query(
|
|
70
|
+
`DELETE FROM chat_messages WHERE tenant_id = $1 AND agent_id = $2`,
|
|
71
|
+
[req.tenant!.id, agentId]
|
|
72
|
+
)
|
|
73
|
+
for (const msg of messages) {
|
|
74
|
+
await client.query(
|
|
75
|
+
`INSERT INTO chat_messages (tenant_id, agent_id, role, content, tool_name, tool_input, tool_output)
|
|
76
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
|
|
77
|
+
[
|
|
78
|
+
req.tenant!.id,
|
|
79
|
+
agentId,
|
|
80
|
+
msg.role,
|
|
81
|
+
msg.content || '',
|
|
82
|
+
msg.tool_name || null,
|
|
83
|
+
msg.tool_input ? JSON.stringify(msg.tool_input) : null,
|
|
84
|
+
msg.tool_output ? JSON.stringify(msg.tool_output) : null,
|
|
85
|
+
]
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
await client.query('COMMIT')
|
|
89
|
+
res.json({ saved: messages.length, agent_id: agentId })
|
|
90
|
+
} catch (err) {
|
|
91
|
+
await client.query('ROLLBACK')
|
|
92
|
+
throw err
|
|
93
|
+
} finally {
|
|
94
|
+
client.release()
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// DELETE /api/v1/chat/history/:agentId
|
|
99
|
+
router.delete('/history/:agentId', async (req: Request, res: Response) => {
|
|
100
|
+
const agentId = parseInt(req.params.agentId, 10)
|
|
101
|
+
if (isNaN(agentId)) {
|
|
102
|
+
res.status(400).json({ error: 'Invalid agentId' })
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const pool = getPool()
|
|
107
|
+
await pool.query(
|
|
108
|
+
`DELETE FROM chat_messages WHERE tenant_id = $1 AND agent_id = $2`,
|
|
109
|
+
[req.tenant!.id, agentId]
|
|
110
|
+
)
|
|
111
|
+
res.json({ cleared: true, agent_id: agentId })
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
export default router
|