Skip to content

feat(resource): add preserve_structure option for directory scanning#509

Merged
MaojiaSheng merged 2 commits intovolcengine:mainfrom
r266-tech:feat/preserve-structure
Mar 10, 2026
Merged

feat(resource): add preserve_structure option for directory scanning#509
MaojiaSheng merged 2 commits intovolcengine:mainfrom
r266-tech:feat/preserve-structure

Conversation

@r266-tech
Copy link
Contributor

Summary

Support preserving nested directory structure when adding resources via add_resource.

  • preserve_structure=True (default): files maintain their relative path hierarchy under the resource URI root
  • preserve_structure=False: all files are flattened to a single level (legacy behavior)
  • Default is configurable via ov.conf (directory.preserve_structure)

Changes

File Change
openviking/parse/parsers/directory.py Core logic: route preserve_structure through _process_one_file and _direct_upload_file
openviking/server/routers/resources.py API layer: expose preserve_structure query parameter
openviking_cli/client/http.py CLI HTTP client: pass parameter through
openviking_cli/utils/config/open_viking_config.py Config: read default from OpenVikingConfig
openviking_cli/utils/config/parser_config.py Config model: add DirectoryConfig with preserve_structure field
tests/parse/test_add_directory.py 3 new tests covering True/False/default behavior

Design Decisions

  • Default True per maintainer @MaojiaSheng's guidance
  • No max_depth — dropped per maintainer feedback (unnecessary API complexity)
  • Non-breaking: existing behavior preserved when preserve_structure=False
  • Config fallback chain: API param → ov.conf → hardcoded default (True)

Closes #490

Support preserving nested directory structure when adding resources.
When preserve_structure=True (default), files maintain their relative
path hierarchy under the resource URI root.
When False, all files are flattened to a single level (legacy behavior).

Configurable default via ov.conf.

Closes volcengine#490

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix import sorting (I001) across 15+ files
- Remove unused imports (F401): signal, hashlib, time, asyncio, pytest, etc.
- Remove unused variables (F841): level, e
- Rename unused loop vars (B007): idx -> _idx
- Replace lambda with def (E731) in feishu.py
- Replace dict() with literal (C408) in resources.py
- Remove f-strings without placeholders (F541)
- Add TYPE_CHECKING imports for ExecToolConfig/CronService (F821)
- Add FastAPI/Depends/Header imports in openapi.py (F821)
- Remove duplicate import of load_config (F811)
- Auto-format 4 files with ruff format
@MaojiaSheng MaojiaSheng merged commit 8d97736 into volcengine:main Mar 10, 2026
47 of 50 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature]: add_resource 函数支持在处理目录时原样保留嵌套结构

2 participants