{"schema":"pcces.browser-agent-api","version":"1.0.0","entrypoint":"window.PCCESAgent","transport":"same-origin browser JavaScript","guideline":"/agent-guideline.md","human_guide":"/agent-guide.html","manifest":"/agent-manifest.json","invocation":"await PCCESAgent.invoke(method, parameters)","direct_call":"await PCCESAgent.search({query: \"穗花木藍\", limit: 50})","response":{"success":{"ok":true,"api_version":"1.0.0","call_id":"...","result":{}},"error":{"ok":false,"api_version":"1.0.0","call_id":"...","error":{"code":"...","message":"...","details":{}}}},"policy":{"automatic_assignment":false,"plan_ttl_ms":600000,"max_plans":64,"max_upload_bytes":20971520,"max_export_bytes":67108864,"business_write_requires":"explicit confirm on the open case; applying an item also needs a preview first","authorization":"檔案檢查未通過","unsupported":["delete cases","change settings"]},"methods":{"health":{"effect":"read","description":"讀取服務狀態。","input_schema":{"type":"object","additionalProperties":false,"properties":{},"required":[]},"returns":"{status, database_connected}；status 為 \"ok\" 表示服務正常。"},"getGuideline":{"effect":"read","description":"讀取完整 Agent 操作指南。","input_schema":{"type":"object","additionalProperties":false,"properties":{},"required":[]},"returns":"{format: \"markdown\", text}"},"getState":{"effect":"read","description":"讀取目前頁面、開啟中的案件與已勾選工項。","input_schema":{"type":"object","additionalProperties":false,"properties":{},"required":[]},"returns":"{session_id, case_id, summary, total_items, filter, search, selected: [{record_id, code}], rates, write_busy, member: {signed_in, members_only, uses, uses_per_budget}, pending_upload}"},"listCases":{"effect":"read","description":"列出近期案件。","input_schema":{"type":"object","additionalProperties":false,"properties":{"limit":{"type":"integer","minimum":1,"maximum":200},"display_only":{"type":"boolean"}},"required":[]},"returns":"{items: [案件]}；案件見 getCase。"},"getCase":{"effect":"read","description":"讀取案件的處理進度。","input_schema":{"type":"object","additionalProperties":false,"properties":{"case_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"}},"required":["case_id"]},"returns":"案件：{id, kind, title, state, completed, total, result_ready, created_at, finished_at}；state 為 QUEUED、RUNNING、SUCCEEDED、FAILED、CANCELLED 或 TIMED_OUT。"},"getCaseResult":{"effect":"read","description":"讀取已完成案件的結果；預設不含全部工項。","input_schema":{"type":"object","additionalProperties":false,"properties":{"case_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"include_items":{"type":"boolean"}},"required":["case_id"]},"returns":"{session_id, summary}；include_items 為 true 時另含 items。"},"waitForCase":{"effect":"read","description":"在限定時間內等待案件完成；時間到仍未完成不會取消案件。","input_schema":{"type":"object","additionalProperties":false,"properties":{"case_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"max_wait_ms":{"type":"integer","minimum":0,"maximum":30000}},"required":["case_id"]},"returns":"{finished, job}"},"openCase":{"effect":"ui","description":"在頁面上開啟已完成的案件；不修改工項。","input_schema":{"type":"object","additionalProperties":false,"properties":{"case_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"}},"required":["case_id"]},"returns":"與 getState 相同。"},"listItems":{"effect":"read","description":"分頁讀取案件的工項。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"offset":{"type":"integer","minimum":0,"maximum":1000000},"limit":{"type":"integer","minimum":1,"maximum":500},"status":{"type":"string","minLength":0,"maxLength":50},"q":{"type":"string","minLength":0,"maxLength":500}},"required":["session_id"]},"returns":"{total, offset, limit, items: [工項]}；工項見 getItem。"},"getItem":{"effect":"read","description":"讀取單一工項的最新內容。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"record_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"}},"required":["session_id","record_id"]},"returns":"工項：{record_id, fingerprint, review_revision, original: {code, name, unit}, suggested, alternatives, editable}"},"search":{"effect":"analysis","description":"依文字搜尋 PCCES 工項候選（5–50 筆）；不修改案件。","input_schema":{"type":"object","additionalProperties":false,"properties":{"query":{"type":"string","minLength":1,"maxLength":200},"limit":{"type":"integer","minimum":5,"maximum":50}},"required":["query"]},"returns":"{display_candidates: [{code, name, unit, native_valid}]}；順序與畫面相同。"},"getUnits":{"effect":"analysis","description":"取得一個工項可用的完整單位碼；不修改案件。","input_schema":{"type":"object","additionalProperties":false,"properties":{"candidate_code":{"type":"string","minLength":1,"maxLength":80,"pattern":"^[A-Za-z0-9#_-]+$"}},"required":["candidate_code"]},"returns":"{unit_options: [{code, name, unit, native_valid}]}"},"getProductForm":{"effect":"analysis","description":"查詢一個完整單位碼是否有 PCCES 接受的產品碼（M＋該編碼）；不修改案件。","input_schema":{"type":"object","additionalProperties":false,"properties":{"code":{"type":"string","minLength":1,"maxLength":80,"pattern":"^[A-Za-z0-9#_-]+$"}},"required":["code"]},"returns":"{product_option: {code, name, unit} 或 null}"},"submitXml":{"effect":"create_case","description":"分析頁面上已選取的 PCCES XML 或預算書 Excel（.xlsx）；需 confirm 與 request_id，不接受任意檔案路徑。","input_schema":{"type":"object","additionalProperties":false,"properties":{"confirm":{"type":"boolean"},"request_id":{"type":"string","minLength":1,"maxLength":32,"pattern":"^[a-f0-9]{32}$"},"candidate_limit":{"type":"integer","minimum":5,"maximum":50}},"required":["confirm","request_id"]},"returns":"{job: {id, state}, request_id}"},"previewApply":{"effect":"preview","description":"建立一個工項的套用計畫並列出變更與警示；不儲存工項。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"record_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"fingerprint":{"type":"string","minLength":1,"maxLength":64,"pattern":"^[a-f0-9]{64}$"},"expected_revision":{"type":"integer","minimum":0,"maximum":2147483647},"candidate_code":{"type":"string","minLength":1,"maxLength":80,"pattern":"^[A-Za-z0-9#_-]+$"},"code":{"type":"string","minLength":1,"maxLength":80,"pattern":"^[A-Za-z0-9#_-]+$"},"action":{"type":"string","enum":["OFFICIAL","CUSTOM"]},"custom_name":{"type":"string","minLength":1,"maxLength":1000},"allow_unit_change":{"type":"boolean"},"notes":{"type":"string","minLength":0,"maxLength":1000}},"required":["session_id","record_id","fingerprint","expected_revision","candidate_code","code"]},"returns":"計畫：{plan_id, request_id, status, expires_at, summary: {source, target, action, custom_name, unit_change, replaces_verified_or_confirmed, warnings, required_acknowledgements}}"},"commitApply":{"effect":"write","description":"確認並執行套用計畫；結果不確定時以同一個計畫重送。","input_schema":{"type":"object","additionalProperties":false,"properties":{"plan_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"confirm":{"type":"boolean"},"acknowledge_warnings":{"type":"boolean"},"acknowledge_existing_selection":{"type":"boolean"}},"required":["plan_id","confirm"]},"returns":"{request_id, receipt: {item: {code, name, unit}}, updated_rows, ui_synced}"},"getBudget":{"effect":"read","description":"分頁讀取預算書各列的類型、數量、單價、複價與百分比，以及總價。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"offset":{"type":"integer","minimum":0,"maximum":1000000},"limit":{"type":"integer","minimum":1,"maximum":500},"q":{"type":"string","minLength":0,"maxLength":100},"changed_only":{"type":"boolean"}},"required":["session_id"]},"returns":"{total, file_total, edits, editable, reasons, matching, offset, limit, items: [列]}；列：{record_id, item_no, name, unit, code, kind, type, depth, analysis, quantity, price, amount, percent, file: {quantity, price, amount, percent}, can: {quantity, price, percent}, edited: {quantity, price, percent}, corrected: {code, name, unit} 或 null}。數字以字串表示；can 為 true 的欄位才能修改。name、code、unit 是檔案原本的內容；corrected 是該列已套用的修正（納入匯出時寫入的編碼、名稱與單位），沒有修正的列為 null。"},"getBudgetAnalysis":{"effect":"read","description":"讀取一個工項的單價分析子項。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"record_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"}},"required":["session_id","record_id"]},"returns":"{record_id, code, name, output_quantity, price, items: [列]}；列見 getBudget。"},"setBudgetValue":{"effect":"write","description":"修改一列的數量、單價或百分比，金額與總價隨之更新；value 為空字串表示還原為檔案原值。需 confirm。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"record_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"field":{"type":"string","enum":["quantity","price","percent"]},"value":{"type":"string","minLength":0,"maxLength":24,"pattern":"^(|[-+]?[0-9]{1,12}([.][0-9]{1,4})?)$"},"confirm":{"type":"boolean"}},"required":["session_id","record_id","field","value","confirm"]},"returns":"{total, file_total, edits, linked, items: [有變動的列], ui_synced}；linked 為一併修改的列數。"},"resetBudget":{"effect":"write","description":"還原所有修改過的數量、單價與百分比。需 confirm。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"confirm":{"type":"boolean"}},"required":["session_id","confirm"]},"returns":"{total, file_total, edits, ui_synced}"},"previewExport":{"effect":"preview","description":"以明列的已核准工項建立匯出計畫；空陣列表示原文匯出。","input_schema":{"type":"object","additionalProperties":false,"properties":{"session_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"record_ids":{"type":"array","items":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"maxItems":5000,"uniqueItems":true}},"required":["session_id","record_ids"]},"returns":"計畫：{plan_id, status, expires_at, summary: {selected_count, record_ids, original_only}}"},"commitExport":{"effect":"export","description":"確認並產生修正後的 XML；不自動下載。","input_schema":{"type":"object","additionalProperties":false,"properties":{"plan_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"confirm":{"type":"boolean"}},"required":["plan_id","confirm"]},"returns":"{artifact_id, filename, bytes, expires_at, summary: {selected_count, changed_count, budget_edits, rates}}"},"getPlan":{"effect":"read","description":"讀取本分頁內計畫的狀態、摘要與結果。","input_schema":{"type":"object","additionalProperties":false,"properties":{"plan_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"}},"required":["plan_id"]},"returns":"計畫，另含 result 或 last_error。"},"discardPlan":{"effect":"local","description":"捨棄尚未送出的計畫；不能撤回已送出的修改。","input_schema":{"type":"object","additionalProperties":false,"properties":{"plan_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"}},"required":["plan_id"]},"returns":"{discarded: true}"},"readArtifact":{"effect":"read","description":"分段讀取匯出檔案（Base64），每次最多 256 KiB。","input_schema":{"type":"object","additionalProperties":false,"properties":{"artifact_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"offset":{"type":"integer","minimum":0,"maximum":67108864},"length":{"type":"integer","minimum":1,"maximum":262144}},"required":["artifact_id"]},"returns":"{artifact_id, filename, bytes, encoding: \"base64\", offset, next_offset, eof, data}"},"downloadArtifact":{"effect":"download","description":"確認後讓瀏覽器下載匯出檔案。","input_schema":{"type":"object","additionalProperties":false,"properties":{"artifact_id":{"type":"string","minLength":1,"maxLength":100,"pattern":"^[A-Za-z0-9_-]+$"},"confirm":{"type":"boolean"}},"required":["artifact_id","confirm"]},"returns":"{artifact_id, filename, download_status: \"dispatched\"}"}}}