backend: let a model ask for a line break, and read the 参考文献 list back
The paper model gained two things while the MCP layer was not looking, and both were invisible from a tool call. `paper_sentence.line_break_before` — the flag a paragraph needs so a formula, a list of items or an author line can start a line of its own — was not in `SentenceSpec`, and `sentence_inputs` dropped it on the floor: a model could write the field, watch the call succeed, and get prose back. It is now part of every write path (`paragraph_write`, `paper_write`, `sentence_add`, `sentence_update`) and of every read path (`sentence_row` reports it, so a model can see the lines before moving one). Two bugs fell out of doing it properly: * `paragraph_move` rebuilt its sentences without the flag, so moving a paragraph that carried a formula turned it into prose. It also passed the *source* sorts through, which interleaved the moved sentences with the target's own — the merged paragraph read in an order neither writer wrote. Both are fixed; the tool now appends, as its own description promised. * `document_text` printed a formula run into the sentence before it. The paper view renders `$$…$$` as a block, so the seam rules are now the same in both places, with a comment on each side naming the other. `PaperDocumentRead.references` and `reference_style` — the per-work 参考文献 list the backend now assembles and formats — were reachable over REST but not over MCP: `paper_document(format="json")` returned citations and nothing to point them at, even though docs/MCP.md already described the list. The json form now carries the entries (index, reference_id, text, missing, citations) and the style name, so a model quotes the bibliography instead of assembling a second one out of the same fields. smoke_mcp.py grows from 76 checks to 99 over two new steps — the line-break step pins the display-formula rule, the marker toggle and the moving case; the bibliography step cites one work from two sentences and checks that the text, the entry and both markers agree on one number.
This commit is contained in:
@@ -74,7 +74,7 @@ def register(server: MCPServer) -> None:
|
||||
str | None, Field(description="段落标题,如 “2. Methods”")
|
||||
] = None,
|
||||
) -> str:
|
||||
"""读一个段落:拼好的正文、逐句内容与 id、引用、段间分隔符。"""
|
||||
"""读一个段落:拼好的正文、逐句内容与 id、引用、段间分隔符与换行。"""
|
||||
with s.session() as db:
|
||||
paper = s.paper_or_fail(db, paper_id)
|
||||
field_sort = s.resolve_position(paper, position=position, heading=heading)
|
||||
@@ -109,7 +109,13 @@ def register(server: MCPServer) -> None:
|
||||
] = None,
|
||||
sentences: Annotated[
|
||||
list[SentenceItem] | None,
|
||||
Field(description="句子数组:字符串、{content, citations} 或 {text, split}"),
|
||||
Field(
|
||||
description=(
|
||||
"句子数组:字符串、{content, citations} 或 {text, split}。"
|
||||
"要某一句另起一行(公式、分条列举、作者行),用对象形式加上 "
|
||||
"line_break_before: true"
|
||||
)
|
||||
),
|
||||
] = None,
|
||||
text: Annotated[
|
||||
str | None, Field(description="整段文本;与 sentences 二选一")
|
||||
@@ -199,7 +205,18 @@ def register(server: MCPServer) -> None:
|
||||
s.fail(f"第 {source} 段没有内容可以搬")
|
||||
|
||||
inputs = [
|
||||
SentenceInput(content=row.content, sort=row.sort, citations=list(row.citations))
|
||||
SentenceInput(
|
||||
content=row.content,
|
||||
# ``sort`` is deliberately left unset so that
|
||||
# :func:`app.crud.paper.replace_paragraph` numbers the block
|
||||
# from the *target's* current maximum. Carrying the old
|
||||
# numbers over instead would interleave the two paragraphs —
|
||||
# the moved sentence with ``sort=1`` would sort against the
|
||||
# target's own sentence with ``sort=1`` — and the merge would
|
||||
# read in an order neither writer wrote.
|
||||
line_break_before=row.line_break_before,
|
||||
citations=list(row.citations),
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
paper_crud.replace_paragraph(
|
||||
@@ -258,6 +275,7 @@ def _write(
|
||||
SentenceCreate(
|
||||
paper_template_filed_sort=field_sort,
|
||||
content=item.content,
|
||||
line_break_before=item.line_break_before,
|
||||
citations=item.citations,
|
||||
sort=item.sort,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user