Schedule consultation bridges on demand and preserve delivery evidence
This commit is contained in:
@@ -21,6 +21,27 @@ def browser_body(text):
|
||||
return text[match.end():] if match else text
|
||||
|
||||
|
||||
def delivery_fields(row):
|
||||
"""Expose evidence-based transport stages without private queue receipts."""
|
||||
if row.get('source') != 'human' or row.get('origin') != 'coordination':
|
||||
return {}
|
||||
status = row.get('status')
|
||||
submission = row.get('submission') or {}
|
||||
if isinstance(submission, str):
|
||||
submission = json.loads(submission)
|
||||
if status in ('uncertain', 'failed'):
|
||||
return dict(delivery_stage='blocked', delivery_reason=(
|
||||
'执行结果待核对,请勿重复发送' if status == 'uncertain' else '处理失败,请查看记录'))
|
||||
if status == 'completed' and row.get('response_id'):
|
||||
return dict(delivery_stage='replied')
|
||||
if submission.get('state') == 'observed':
|
||||
return dict(delivery_stage='processing')
|
||||
if submission.get('state') == 'accepted':
|
||||
return dict(delivery_stage='delivered')
|
||||
# A local start or submitting record is not proof of host acceptance.
|
||||
return dict(delivery_stage='queued')
|
||||
|
||||
|
||||
def project(rows, links):
|
||||
by_id = {row['id']: row for row in rows}
|
||||
metadata = {link['message_id']: link for link in links}
|
||||
@@ -101,5 +122,6 @@ def project(rows, links):
|
||||
if key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
result.append({**{k: row.get(k) for k in ('id', 'source', 'status', 'created')}, 'text': text, 'log_id':incident_links.get(group)})
|
||||
result.append({**{k: row.get(k) for k in ('id', 'source', 'status', 'created', 'reply_to')},
|
||||
**delivery_fields(row), 'text': text, 'log_id':incident_links.get(group)})
|
||||
return result
|
||||
|
||||
+10
-1
@@ -888,11 +888,13 @@ class Store:
|
||||
|
||||
@staticmethod
|
||||
def public_message(row):
|
||||
from .conversation import delivery_fields
|
||||
result = {k: row[k] for k in ('id','session_id','text','source','reply_to','status','created','response_id')}
|
||||
result['outcome'] = row['status'] if row['status'] in ('completed','failed','uncertain') else None
|
||||
result['origin'] = row['origin']
|
||||
result['execution'] = 'started' if row['started'] else 'not_started'
|
||||
result['submission'] = json.loads(row['submission']) if row['submission'] else None
|
||||
result.update(delivery_fields(dict(row)))
|
||||
return result
|
||||
|
||||
def send(self, data):
|
||||
@@ -1905,9 +1907,16 @@ class Store:
|
||||
value=self._decision(row)
|
||||
if value['session_id']:
|
||||
session=self._get(db,'sessions',value['session_id'])
|
||||
rows=db.execute("SELECT * FROM messages WHERE session_id=? AND source='human' AND origin='coordination' AND status IN ('queued','claimed','uncertain')", (value['session_id'],)).fetchall()
|
||||
now=time.time()
|
||||
queued=[m for m in rows if m['status']=='queued' or (m['status']=='claimed' and not m['started'] and (m['lease_until'] or 0)<=now)]
|
||||
uncertain=[m for m in rows if m['status']=='uncertain' or (m['status']=='claimed' and m['started'] and (m['lease_until'] or 0)<=now)]
|
||||
inflight=[m for m in rows if m not in queued and m not in uncertain]
|
||||
demand=dict(queued=len(queued),inflight=len(inflight),uncertain=len(uncertain),
|
||||
human_queued=len(queued),oldest_queued_at=min((m['created'] for m in queued),default=None))
|
||||
bindings.append(dict(decision_id=value['id'],session_id=value['session_id'],thread_id=value['session_thread_id'],
|
||||
worktree=session['worktree'],status=value['status'],archive_status=value['archive_status'],
|
||||
pending_messages=self._decision_pending(db,value)))
|
||||
pending_messages=self._decision_pending(db,value),demand=demand))
|
||||
return {'bindings':bindings}
|
||||
|
||||
def decision_consultation(self, did, data=None):
|
||||
|
||||
Reference in New Issue
Block a user