-
Notifications
You must be signed in to change notification settings - Fork 685
fix: support embedded context in ACP mode for Zed @ file references #1264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,23 @@ def acp_blocks_to_content_parts(prompt: list[ACPContentBlock]) -> list[ContentPa | |||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| case acp.schema.EmbeddedResourceContentBlock(): | ||||||||||||||
| resource = block.resource | ||||||||||||||
| if isinstance(resource, acp.schema.TextResourceContents): | ||||||||||||||
| uri = resource.uri | ||||||||||||||
| text = resource.text | ||||||||||||||
| content.append(TextPart(text=f"<resource uri={uri!r}>\n{text}\n</resource>")) | ||||||||||||||
| else: | ||||||||||||||
| logger.warning( | ||||||||||||||
| "Unsupported embedded resource type: {type}", | ||||||||||||||
| type=type(resource).__name__, | ||||||||||||||
| ) | ||||||||||||||
| case acp.schema.ResourceContentBlock(): | ||||||||||||||
| # ResourceContentBlock is a link reference without inline content; | ||||||||||||||
| # include the URI so the model is at least aware of the reference. | ||||||||||||||
| content.append( | ||||||||||||||
| TextPart(text=f"<resource_link uri={block.uri!r} name={block.name!r} />") | ||||||||||||||
|
Comment on lines
+45
to
+46
|
||||||||||||||
| content.append( | |
| TextPart(text=f"<resource_link uri={block.uri!r} name={block.name!r} />") | |
| name = block.name or (block.uri.split("/")[-1] if getattr(block, "uri", None) else None) | |
| name_attr = f" name={name!r}" if name else "" | |
| content.append( | |
| TextPart(text=f"<resource_link uri={block.uri!r}{name_attr} />") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import acp | ||
|
|
||
| from kimi_cli.acp.convert import tool_result_to_acp_content | ||
| from kimi_cli.wire.types import DiffDisplayBlock, ToolReturnValue | ||
| from kimi_cli.acp.convert import acp_blocks_to_content_parts, tool_result_to_acp_content | ||
| from kimi_cli.wire.types import DiffDisplayBlock, TextPart, ToolReturnValue | ||
|
|
||
|
|
||
| def test_tool_result_to_acp_content_handles_diff_display(): | ||
|
|
@@ -21,3 +21,62 @@ def test_tool_result_to_acp_content_handles_diff_display(): | |
| assert content.path == "foo.txt" | ||
| assert content.old_text == "before" | ||
| assert content.new_text == "after" | ||
|
|
||
|
|
||
| def test_acp_blocks_to_content_parts_handles_embedded_text_resource(): | ||
| block = acp.schema.EmbeddedResourceContentBlock( | ||
| type="resource", | ||
| resource=acp.schema.TextResourceContents( | ||
| uri="file:///path/to/foo.py", | ||
| text="print('hello')", | ||
| ), | ||
| ) | ||
| parts = acp_blocks_to_content_parts([block]) | ||
| assert len(parts) == 1 | ||
| assert isinstance(parts[0], TextPart) | ||
| assert "file:///path/to/foo.py" in parts[0].text | ||
| assert "print('hello')" in parts[0].text | ||
|
Comment on lines
+26
to
+38
|
||
|
|
||
|
|
||
| def test_acp_blocks_to_content_parts_handles_resource_link(): | ||
| block = acp.schema.ResourceContentBlock( | ||
| type="resource_link", | ||
| uri="file:///path/to/bar.py", | ||
| name="bar.py", | ||
| ) | ||
| parts = acp_blocks_to_content_parts([block]) | ||
| assert len(parts) == 1 | ||
| assert isinstance(parts[0], TextPart) | ||
| assert "file:///path/to/bar.py" in parts[0].text | ||
| assert "bar.py" in parts[0].text | ||
|
|
||
|
|
||
| def test_acp_blocks_to_content_parts_skips_blob_resource(): | ||
| block = acp.schema.EmbeddedResourceContentBlock( | ||
| type="resource", | ||
| resource=acp.schema.BlobResourceContents( | ||
| uri="file:///path/to/image.png", | ||
| blob="iVBORw0KGgo=", | ||
| ), | ||
| ) | ||
| parts = acp_blocks_to_content_parts([block]) | ||
| assert len(parts) == 0 | ||
|
|
||
|
|
||
| def test_acp_blocks_to_content_parts_mixed_blocks(): | ||
| blocks = [ | ||
| acp.schema.TextContentBlock(type="text", text="Check this file:"), | ||
| acp.schema.EmbeddedResourceContentBlock( | ||
| type="resource", | ||
| resource=acp.schema.TextResourceContents( | ||
| uri="file:///src/main.py", | ||
| text="def main(): pass", | ||
| ), | ||
| ), | ||
| ] | ||
| parts = acp_blocks_to_content_parts(blocks) | ||
| assert len(parts) == 2 | ||
| assert isinstance(parts[0], TextPart) | ||
| assert parts[0].text == "Check this file:" | ||
| assert isinstance(parts[1], TextPart) | ||
| assert "def main(): pass" in parts[1].text | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test for non-text embedded resource types (e.g., BlobResourceContents) to verify that the warning is properly logged and the block is gracefully skipped. This would ensure the unsupported resource type handling path is tested.