blob: 6937a14d3cd8e6fdd8eea0aeb2ad44a5140148aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/bin/bash
# UserPromptSubmit hook: 从 broker 拉取长消息注入 context
# 每次 dispatcher 提交 prompt 时触发,检查有没有待注入的长消息
export PATH="/usr/bin:/bin:$PATH"
cd "$(dirname "$0")"
source .env 2>/dev/null
# 拉取 pending context
RESP=$(curl -sf -H "Authorization: Bearer $API_SECRET" \
"${BROKER_URL:-http://127.0.0.1:8000}/context/pending" 2>/dev/null) || exit 0
# 解析消息
CONTEXT=$(echo "$RESP" | /usr/bin/python3 -c "
import sys, json
d = json.load(sys.stdin)
msgs = d.get('messages', [])
if not msgs:
sys.exit(1)
print('\n---\n'.join(msgs))
" 2>/dev/null) || exit 0
# 有消息则注入 additionalContext
if [ -n "$CONTEXT" ]; then
/usr/bin/python3 -c "
import json, sys
ctx = sys.stdin.read()
print(json.dumps({
'hookSpecificOutput': {
'hookEventName': 'UserPromptSubmit',
'additionalContext': ctx
}
}))
" <<< "$CONTEXT"
fi
exit 0
|