Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(parse): escape pipes and line breaks in Feishu Markdown tables (#5435)
Mohammad Hijjawi47b0c408efaf
diff --git a/openviking/parse/base.py b/openviking/parse/base.pyindex 5e934f8c4..2a12130e2 100644--- a/openviking/parse/base.py+++ b/openviking/parse/base.py@@ -54,18 +54,23 @@ def format_table_to_markdown(rows: List[List[str]], has_header: bool = True) ->if not rows:return ""- # Calculate maximum width for each column+ # Escape pipes and fold line breaks so each cell stays inside its column and row+ rows = [+ ["<br>".join(str(cell).replace("|", "\\|").splitlines()) for cell in row] for row in rows+ ]++ # Calculate maximum width for each column; a delimiter cell needs at least "---"col_count = max(len(row) for row in rows)- col_widths = [0] * col_count+ col_widths = [3] * col_countfor row in rows:for i, cell in enumerate(row):- col_widths[i] = max(col_widths[i], len(str(cell)))+ col_widths[i] = max(col_widths[i], len(cell))lines = []for row_idx, row in enumerate(rows):# Pad missing columns- padded_row = list(row) + [""] * (col_count - len(row))- cells = [str(cell).ljust(col_widths[i]) for i, cell in enumerate(padded_row)]+ padded_row = row + [""] * (col_count - len(row))+ cells = [cell.ljust(col_widths[i]) for i, cell in enumerate(padded_row)]lines.append("| " + " | ".join(cells) + " |")# Add separator row after headerdiff --git a/tests/parse/test_feishu_accessor.py b/tests/parse/test_feishu_accessor.pyindex 891eed68d..6f0385b04 100644--- a/tests/parse/test_feishu_accessor.py+++ b/tests/parse/test_feishu_accessor.py@@ -1532,7 +1532,9 @@ def test_parse_sheets_handles_grid_and_embedded_bitable(monkeypatch):b'"columnCount":0,"blockInfo":{"blockType":"BITABLE_BLOCK",'b'"blockToken":"app-token_table-1"}}]}}'),- _FakeMediaResponse(b'{"data":{"valueRange":{"values":[["name","amount"],["A",1]]}}}'),+ _FakeMediaResponse(+ b'{"data":{"valueRange":{"values":[["name","","amount"],["Rent | Fees\\nQ1","",1]]}}}'+ ),_FakeMediaResponse(b"\x89PNG\r\n"),])@@ -1606,7 +1608,11 @@ def test_parse_sheets_handles_grid_and_embedded_bitable(monkeypatch):)assert title == "Budget"- assert "| name | amount |" in markdown+ assert (+ "| name | | amount |\n"+ "| ------------------ | --- | ------ |\n"+ "| Rent \\| Fees<br>Q1 | | 1 |"+ ) in markdownassert "1 more rows truncated" in markdownassert "2 columns after Z omitted" in markdownassert "### Content Calendar" in markdown