$npx -y skills add cinience/alicloud-skills --skill aliyun-docmind-extractUse when working with Document Mind (DocMind) via Node.js SDK to submit document parsing jobs and poll results. Designed for Claude Code/Codex document understanding workflows.
| 1 | Category: provider |
| 2 | |
| 3 | # Document Mind (DocMind) — Node.js SDK |
| 4 | |
| 5 | Use DocMind to extract document structure, text, and layout with async jobs. |
| 6 | |
| 7 | ## Prerequisites |
| 8 | |
| 9 | - Install SDKs: |
| 10 | - `npm install @alicloud/docmind-api20220711 @alicloud/tea-util @alicloud/credentials` |
| 11 | - Provide credentials via standard Alibaba Cloud env vars: |
| 12 | - `ALIBABACLOUD_ACCESS_KEY_ID` |
| 13 | - `ALIBABACLOUD_ACCESS_KEY_SECRET` |
| 14 | - `ALIBABACLOUD_REGION_ID` (optional default; if unset, choose the most reasonable region for the task or ask the user) |
| 15 | |
| 16 | ## Quickstart (submit + poll) |
| 17 | |
| 18 | ```js |
| 19 | const Client = require('@alicloud/docmind-api20220711'); |
| 20 | const Credential = require('@alicloud/credentials'); |
| 21 | const Util = require('@alicloud/tea-util'); |
| 22 | |
| 23 | const cred = new Credential.default(); |
| 24 | const regionId = |
| 25 | process.env.ALIBABACLOUD_REGION_ID || |
| 26 | process.env.ALIBABA_CLOUD_REGION_ID || |
| 27 | process.env.ALICLOUD_REGION_ID || |
| 28 | 'cn-hangzhou'; // Example default; choose/ask if unset. |
| 29 | const client = new Client.default({ |
| 30 | endpoint: `docmind-api.${regionId}.aliyuncs.com`, |
| 31 | accessKeyId: cred.credential.accessKeyId, |
| 32 | accessKeySecret: cred.credential.accessKeySecret, |
| 33 | type: 'access_key', |
| 34 | regionId, |
| 35 | }); |
| 36 | |
| 37 | async function submitByUrl(fileUrl, fileName) { |
| 38 | const req = new Client.SubmitDocStructureJobRequest(); |
| 39 | req.fileUrl = fileUrl; |
| 40 | req.fileName = fileName; |
| 41 | const resp = await client.submitDocStructureJob(req); |
| 42 | return resp.body.data.id; |
| 43 | } |
| 44 | |
| 45 | async function pollResult(jobId) { |
| 46 | const req = new Client.GetDocStructureResultRequest(); |
| 47 | req.id = jobId; |
| 48 | const resp = await client.getDocStructureResult(req); |
| 49 | return resp.body; |
| 50 | } |
| 51 | |
| 52 | (async () => { |
| 53 | const jobId = await submitByUrl('https://example.com/example.pdf', 'example.pdf'); |
| 54 | console.log('jobId:', jobId); |
| 55 | |
| 56 | // Poll every 10s until completed. |
| 57 | for (;;) { |
| 58 | const result = await pollResult(jobId); |
| 59 | if (result.completed) { |
| 60 | console.log(result.status, result.data || result.message); |
| 61 | break; |
| 62 | } |
| 63 | await new Promise((r) => setTimeout(r, 10000)); |
| 64 | } |
| 65 | })(); |
| 66 | ``` |
| 67 | |
| 68 | ## Script quickstart |
| 69 | |
| 70 | ```bash |
| 71 | DOCMIND_FILE_URL="https://example.com/example.pdf" \\ |
| 72 | node skills/ai/text/aliyun-docmind-extract/scripts/quickstart.js |
| 73 | ``` |
| 74 | |
| 75 | Environment variables: |
| 76 | |
| 77 | - `DOCMIND_FILE_URL` |
| 78 | - `DOCMIND_FILE_NAME` (optional) |
| 79 | - `DOCMIND_POLL_INTERVAL_MS` (optional, default 10000) |
| 80 | - `DOCMIND_MAX_POLLS` (optional, default 120) |
| 81 | |
| 82 | ## Local file upload |
| 83 | |
| 84 | ```js |
| 85 | const fs = require('fs'); |
| 86 | const advanceReq = new Client.SubmitDocStructureJobAdvanceRequest(); |
| 87 | advanceReq.fileUrlObject = fs.createReadStream('./example.pdf'); |
| 88 | advanceReq.fileName = 'example.pdf'; |
| 89 | const runtime = new Util.RuntimeOptions({}); |
| 90 | const resp = await client.submitDocStructureJobAdvance(advanceReq, runtime); |
| 91 | ``` |
| 92 | |
| 93 | ## Notes for Claude Code/Codex |
| 94 | |
| 95 | - DocMind is async: submit a job, then poll until `completed=true`. |
| 96 | - Poll every ~10s; max processing window is 120 minutes. |
| 97 | - Keep files publicly accessible when using URL submission. |
| 98 | |
| 99 | ## Error handling |
| 100 | |
| 101 | - `UrlNotLegal`: URL not publicly accessible or malformed. |
| 102 | - `DocProcessing`: job still running; keep polling. |
| 103 | - `Fail`: check `message` and error code for root cause. |
| 104 | |
| 105 | ## Validation |
| 106 | |
| 107 | ```bash |
| 108 | mkdir -p output/aliyun-docmind-extract |
| 109 | for f in skills/ai/text/aliyun-docmind-extract/scripts/*.py; do |
| 110 | python3 -m py_compile "$f" |
| 111 | done |
| 112 | echo "py_compile_ok" > output/aliyun-docmind-extract/validate.txt |
| 113 | ``` |
| 114 | |
| 115 | Pass criteria: command exits 0 and `output/aliyun-docmind-extract/validate.txt` is generated. |
| 116 | |
| 117 | ## Output And Evidence |
| 118 | |
| 119 | - Save artifacts, command outputs, and API response summaries under `output/aliyun-docmind-extract/`. |
| 120 | - Include key parameters (region/resource id/time range) in evidence files for reproducibility. |
| 121 | |
| 122 | ## Workflow |
| 123 | |
| 124 | 1) Confirm user intent, region, identifiers, and whether the operation is read-only or mutating. |
| 125 | 2) Run one minimal read-only query first to verify connectivity and permissions. |
| 126 | 3) Execute the target operation with explicit parameters and bounded scope. |
| 127 | 4) Verify results and save output/evidence files. |
| 128 | |
| 129 | ## References |
| 130 | |
| 131 | - DocMind Node.js SDK: `@alicloud/docmind-api20220711` |
| 132 | |
| 133 | - Source list: `references/sources.md` |