import sqlite3,json,sys
# Run with the server stopped, against its freshly-created synthetic replay thread.
text='Here is the percent SVG:\n\n![Percent SVG](data:image/svg+xml;utf8,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22100%%22%20height=%22100%%22%20viewBox=%220%200%20100%2050%22%3E%3Ctitle%3ECaf%C3%A9%3C/title%3E%3Crect%20width=%22100%%22%20height=%22100%%22%20fill=%22red%22/%3E%3C/svg%3E)'
c=sqlite3.connect(sys.argv[1])
for table,key,where in [('orchestration_v2_projection_messages','message_id',"role='assistant'"),('orchestration_v2_projection_turn_items','turn_item_id',"type='assistant_message'")]:
    rows=c.execute(f'SELECT {key},payload_json FROM {table} WHERE {where}').fetchall()
    assert len(rows)==1, (table,len(rows))
    for ident,raw in rows:
        payload=json.loads(raw); payload['text']=text
        c.execute(f'UPDATE {table} SET payload_json=? WHERE {key}=?',(json.dumps(payload,ensure_ascii=False),ident))
c.commit();c.close()
print('Seeded exact percent SVG in assistant message and turn item.')
