Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/controllers/console/knowledge_fs/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
KnowledgeFSInitialWebsiteSourcePreviewPayload,
KnowledgeFSJWKSResponse,
KnowledgeFSLogicalDocumentDeletePayload,
KnowledgeFSLogicalDocumentListQuery,
KnowledgeFSLogicalDocumentListResponse,
KnowledgeFSLogicalDocumentResponse,
KnowledgeFSMembersReplacePayload,
Expand Down Expand Up @@ -1652,7 +1653,7 @@ def get(self, control_space_id: str):
@console_ns.route("/knowledge-fs/spaces/<string:control_space_id>/logical-documents")
class KnowledgeFSSpaceLogicalDocumentsApi(Resource):
@error_responses(*_SPACE_CALL_ERRORS, KnowledgeFSResourceNotFoundHTTPError)
@console_ns.doc(params=query_params_from_model(KnowledgeFSCursorQuery))
@console_ns.doc(params=query_params_from_model(KnowledgeFSLogicalDocumentListQuery))
@console_ns.response(
HTTPStatus.OK,
"Agent Knowledge Base logical documents",
Expand All @@ -1664,12 +1665,15 @@ class KnowledgeFSSpaceLogicalDocumentsApi(Resource):
@_knowledge_fs_errors
def get(self, control_space_id: str):
actor_id, tenant_id = _actor()
query = KnowledgeFSCursorQuery.model_validate(request.args.to_dict())
query = KnowledgeFSLogicalDocumentListQuery.model_validate(request.args.to_dict())
result = _console_services().facade.list_logical_documents(
tenant_id=tenant_id,
account_id=actor_id,
control_space_id=control_space_id,
cursor=query.cursor,
limit=query.limit,
query=query.query,
status=query.status,
)
return dump_response(KnowledgeFSLogicalDocumentListResponse, result)

Expand Down
2 changes: 2 additions & 0 deletions api/openapi/markdown/console-openapi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion api/services/knowledge_fs/data_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
KnowledgeFSDocumentChunkResponse,
KnowledgeFSDocumentCompilationJobResponse,
KnowledgeFSDocumentDeletePayload,
KnowledgeFSDocumentDisplayStatus,
KnowledgeFSDocumentDownloadDescriptor,
KnowledgeFSDocumentListResponse,
KnowledgeFSDocumentMetadataPayload,
Expand Down Expand Up @@ -673,13 +674,20 @@ def list_logical_documents(
account_id: str,
control_space_id: str,
cursor: str | None,
limit: int = 50,
query: str | None = None,
status: KnowledgeFSDocumentDisplayStatus | None = None,
) -> KnowledgeFSLogicalDocumentListResponse:
raw = self._interactive(
tenant_id=tenant_id,
account_id=account_id,
control_space_id=control_space_id,
operation_id="listLogicalDocuments",
query=(("cursor", cursor),) if cursor else (),
query=tuple(
(key, str(value))
for key, value in (("cursor", cursor), ("limit", limit), ("query", query), ("status", status))
if value is not None
),
)
return KnowledgeFSLogicalDocumentListResponse.model_validate(raw)

Expand Down
13 changes: 13 additions & 0 deletions api/services/knowledge_fs/product_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,19 @@ class KnowledgeFSCursorQuery(BaseModel):
model_config = ConfigDict(extra="forbid")


type KnowledgeFSDocumentDisplayStatus = Literal["ready", "queued", "processing", "failed", "disabled"]


class KnowledgeFSLogicalDocumentListQuery(KnowledgeFSCursorQuery):
query: str | None = Field(default=None, max_length=200)
status: KnowledgeFSDocumentDisplayStatus | None = None

@field_validator("query")
@classmethod
def normalize_query(cls, value: str | None) -> str | None:
return value.strip() or None if value is not None else None


# Who produced a retrieval trace: the console retrieval test, a KnowledgeFS workflow node, the
# service API, an agent, or an MCP client. Mirrors KnowledgeFS `AnswerTraceSourceSchema`.
type KnowledgeFSTraceSource = Literal["retrieval_test", "workflow", "service_api", "agent", "mcp"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,7 @@ def test_logical_document_delete_preserves_initial_row_version() -> None:
KnowledgeFSDataFacade.list_logical_documents,
data_facade_module.KnowledgeFSLogicalDocumentListResponse,
"listLogicalDocuments",
{"cursor": "cursor-1"},
{"cursor": "cursor-1", "limit": 25, "query": "late report", "status": "processing"},
None,
),
(
Expand Down Expand Up @@ -2840,6 +2840,13 @@ def test_facade_public_methods_preserve_the_registered_operation_and_child_bindi

if child_resource_id is not None:
assert delegated_kwargs["resource_id"] == child_resource_id
if operation_id == "listLogicalDocuments":
assert delegated_kwargs["query"] == (
("cursor", "cursor-1"),
("limit", "25"),
("query", "late report"),
("status", "processing"),
)
if operation_id == "listDocumentRevisions":
assert delegated_kwargs["query"] == (("cursor", "cursor-1"), ("limit", "1"))
if operation_id in {"listGoldenQuestions", "listQualityBadCases"}:
Expand Down
14 changes: 14 additions & 0 deletions api/tests/unit_tests/services/knowledge_fs/test_product_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
KnowledgeFSGrepResponse,
KnowledgeFSListQuery,
KnowledgeFSListResponse,
KnowledgeFSLogicalDocumentListQuery,
KnowledgeFSLogicalDocumentResponse,
KnowledgeFSOverviewBaseStatsResponse,
KnowledgeFSOverviewHealthResponse,
Expand Down Expand Up @@ -1979,3 +1980,16 @@ def test_every_sync_policy_entry_point_applies_the_same_custom_interval_rules(
payload_type.model_validate({"enabled": True, "mode": "custom", **extra})
with pytest.raises(ValidationError, match="customIntervalSeconds is only valid"):
payload_type.model_validate({"enabled": True, "mode": "manual", "customIntervalSeconds": 3_600, **extra})


def test_logical_document_search_query_normalizes_and_validates_filters() -> None:
query = KnowledgeFSLogicalDocumentListQuery.model_validate(
{"query": " report ", "status": "processing", "cursor": "next", "limit": "25"}
)
assert query.query == "report"
assert query.status == "processing"
assert query.limit == 25
assert KnowledgeFSLogicalDocumentListQuery(query=" ").query is None
for payload in ({"status": "running"}, {"query": "x" * 201}, {"limit": 101}):
with pytest.raises(ValidationError):
KnowledgeFSLogicalDocumentListQuery.model_validate(payload)
5 changes: 0 additions & 5 deletions oxlint-suppressions.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading