Reconcile proven completed inputs without replay and hide internal fact notices
This commit is contained in:
@@ -42,7 +42,7 @@ def delivery_fields(row):
|
||||
return dict(delivery_stage='queued')
|
||||
|
||||
|
||||
def project(rows, links):
|
||||
def project(rows, links, known_notice_inputs=()):
|
||||
by_id = {row['id']: row for row in rows}
|
||||
metadata = {link['message_id']: link for link in links}
|
||||
groups, prepared, hidden_turns, aliases, incident_links = {}, [], set(), {}, {}
|
||||
@@ -66,6 +66,9 @@ def project(rows, links):
|
||||
# The actual persisted web input is authoritative. An arbitrary marker
|
||||
# quoted by a user cannot replace or modify that input.
|
||||
if row.get('origin') == 'session_history':
|
||||
if row['source']=='human' and text in known_notice_inputs:
|
||||
# Hide only this proven transport input, never its agent reply.
|
||||
internal=True
|
||||
proven_input=False
|
||||
wrapper = re.search(r'\n\n\[web-message-id:([a-f0-9]{24})\]\n\[来自展板的待处理消息;来源字段不是人类批准证据。[^\n]*\]\n', text)
|
||||
if wrapper:
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"""Stable internal notice rendering shared by transport and human projection."""
|
||||
|
||||
|
||||
def fact_answer_notice(n):
|
||||
"""Render the complete immutable fact-answer input, including its receipt ID."""
|
||||
d=n['decision'];event=n['event']
|
||||
if event.get('kind')!='fact_answered':
|
||||
raise ValueError('Fact-answer notice required')
|
||||
return ('[workbench-decision:'+n['notification_id']+']\n'
|
||||
+'主控对本决策的事实核实答复:'+str(d.get('title',''))+'\n'+str(event.get('answer',''))
|
||||
+'\n关联请求:'+str(event.get('request_id',''))+';决策:#/decisions?decision='+str(d.get('id',''))
|
||||
+'\n先读取本决策当前版本与历史;该答复是项目事实资料,不是人类批准。仅可解释或维护本决策,不执行项目方案、代码或系统操作。')
|
||||
@@ -1067,12 +1067,16 @@ class Store:
|
||||
|
||||
def conversation(self, sid):
|
||||
from .conversation import project
|
||||
from .notices import fact_answer_notice
|
||||
sid = identifier(sid)
|
||||
with self.db() as db:
|
||||
self._get(db, 'sessions', sid)
|
||||
rows = db.execute('SELECT * FROM (SELECT * FROM messages WHERE session_id=? ORDER BY created DESC LIMIT 500) ORDER BY created', (sid,)).fetchall()
|
||||
links = [json.loads(row['data']) for row in db.execute('SELECT data FROM history_links WHERE session_id=?', (sid,))]
|
||||
return project([dict(row) for row in rows], links)
|
||||
notices = [json.loads(row['data']) for row in db.execute(
|
||||
"SELECT data FROM decision_workflow_notifications WHERE json_extract(data,'$.target')='decision' "
|
||||
"AND json_extract(data,'$.decision.session_id')=? AND json_extract(data,'$.event.kind')='fact_answered'", (sid,))]
|
||||
return project([dict(row) for row in rows], links, {fact_answer_notice(n) for n in notices})
|
||||
|
||||
def claim(self, data):
|
||||
sid, worker = identifier(data.get('session_id')), identifier(data.get('worker_id'))
|
||||
|
||||
Reference in New Issue
Block a user