$npx -y skills add PaodingAI/skills --skill chatdoc-studio-knowledgemateCreate and operate ChatDOC Studio knowledge bases through pd_router using a Bearer API key and JavaScript helpers. Use when Codex needs to upload one or more PDF/DOC/DOCX files, skip failed files without aborting the whole job, create a knowledge base from successful uploads, or
| 1 | # ChatDOC Studio KnowledgeMate |
| 2 | |
| 3 | Run a JavaScript workflow that uploads local PDF/DOC/DOCX files to ChatDOC Studio through PDRouter, waits for successful parsing, and creates a knowledge base from the successful uploads in one step. |
| 4 | |
| 5 | This is suitable for creating knowledge bases from local files or folders, then using the returned `library_id` for document listing, retrieval, grep, syllabus reading, and block reading. |
| 6 | |
| 7 | ## Installation |
| 8 | |
| 9 | ```bash |
| 10 | npx skills add PaodingAI/skills |
| 11 | ``` |
| 12 | |
| 13 | For a local Codex installation, place this skill directory under: |
| 14 | |
| 15 | ```bash |
| 16 | $CODEX_HOME/skills/chatdoc-studio-knowledgemate |
| 17 | ``` |
| 18 | |
| 19 | ## Usage |
| 20 | |
| 21 | Create a knowledge base from files: |
| 22 | |
| 23 | ```bash |
| 24 | node scripts/knowledge-mate.mjs upload-and-create \ |
| 25 | --name "Quarterly KB" \ |
| 26 | --file ./docs/a.pdf \ |
| 27 | --file ./docs/b.docx \ |
| 28 | --file ./docs/c.pdf |
| 29 | ``` |
| 30 | |
| 31 | Create a knowledge base from a folder recursively: |
| 32 | |
| 33 | ```bash |
| 34 | node scripts/knowledge-mate.mjs upload-and-create \ |
| 35 | --name "Quarterly KB" \ |
| 36 | --dir ./docs |
| 37 | ``` |
| 38 | |
| 39 | Query an existing knowledge base: |
| 40 | |
| 41 | ```bash |
| 42 | node scripts/knowledge-mate.mjs retrieval --library-id <id> --query <text> |
| 43 | node scripts/knowledge-mate.mjs list-documents --library-id <id> |
| 44 | node scripts/knowledge-mate.mjs stats --library-id <id> --upload-id <id> |
| 45 | node scripts/knowledge-mate.mjs grep --library-id <id> --upload-id <id> --pattern <text> |
| 46 | node scripts/knowledge-mate.mjs read --library-id <id> --upload-id <id> --offset <n> |
| 47 | node scripts/knowledge-mate.mjs read-syllabus --library-id <id> --upload-id <id> |
| 48 | ``` |
| 49 | |
| 50 | ## Execution Constraints |
| 51 | |
| 52 | - You must invoke `scripts/knowledge-mate.mjs` directly. Do not reimplement the PDRouter or ChatDOC Studio API flow yourself during normal use. |
| 53 | - Route every request through PDRouter at `/openapi/chatdoc-studio/...`. |
| 54 | - Authenticate only with `Authorization: Bearer <PAODINGAI_API_KEY>`. |
| 55 | - Do not call `chatdoc_studio` directly. |
| 56 | - Do not add internal `X-PD-*` signature headers in this skill. |
| 57 | - Do not expose or use separate upload-only or create-only commands; use `upload-and-create` for new knowledge bases. |
| 58 | - Only inspect or modify the script implementation when the script itself is unavailable, failing, or needs a fix. |
| 59 | - The behavior contract below explains what the script does, what it outputs, and when to use it. It is not a manual checklist for the model to imitate step by step. |
| 60 | |
| 61 | ## When to Use |
| 62 | |
| 63 | - Use this skill when the user wants to create a ChatDOC Studio knowledge base from local PDF, DOC, or DOCX files. |
| 64 | - Use this skill when the user provides a folder and asks to build a knowledge base from the documents inside it. |
| 65 | - Use this skill when the user wants knowledge retrieval, document search, document stats, syllabus inspection, or reading specific document blocks from a ChatDOC Studio knowledge base. |
| 66 | - Use this skill when the workflow must skip failed or unsupported files without aborting the entire upload batch. |
| 67 | - Use this skill only for PDRouter-backed ChatDOC Studio skill APIs, not for direct ChatDOC Studio internal APIs. |
| 68 | |
| 69 | ## Environment Variables |
| 70 | |
| 71 | - `PAODINGAI_API_KEY`: Required. The Bearer API key for PDRouter. If it is missing, the script fails immediately and tells the user to create a Bearer API Key in pdrouter, then export it before retrying. |
| 72 | |
| 73 | The PDRouter base URL is fixed in the script as `https://platform.paodingai.com`. The service code is fixed in the script as `chatdoc-studio`; users do not need to set base-url or service-code environment variables. |
| 74 | |
| 75 | The API key can be obtained from the PDRouter platform. |
| 76 | |
| 77 | ## Default Behavior and Optional Settings |
| 78 | |
| 79 | - Upload concurrency is fixed at `5`. |
| 80 | - Supported upload file types are `.pdf`, `.doc`, and `.docx`. |
| 81 | - `--dir` is scanned recursively. |
| 82 | - `--file` and `--dir` can be mixed in one command. |
| 83 | - Duplicate file paths are removed before upload. |
| 84 | - Unsupported file types are not uploaded and are reported as skipped failures. |
| 85 | - If more than `300` supported files are found, the script stops before uploading and asks the user to clean the folder to at most `300` PDF/DOC/DOCX files. |
| 86 | - If every file fails to upload or parse, knowledge-base creation is skipped and the script exits with a non-zero status. |
| 87 | |
| 88 | ## Script Behavior |
| 89 | |
| 90 | 1. Read `PAODINGAI_API_KEY` from the environment and use the fixed PDRouter base URL `https://platform.paodingai.com`. |
| 91 | 2. Expand all `--file` inputs and recursively scanned `--dir` inputs into one de-duplicated file list. |
| 92 | 3. Count supported `.pdf`, `.doc`, and `.do |