agentworkshop 0.11.3 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.AgentWorkShop/prompts/host-tools.json +4 -4
- package/.output/.AgentWorkShop/prompts/host-tools.json +4 -4
- package/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{DXXBGPAc.js → CsdezMu9.js} +4 -4
- package/.output/public/_nuxt/WL1R8lPA.js +1 -0
- package/.output/public/_nuxt/_id_.Czwkl50w.css +1 -0
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/2f96705b-cf57-4bde-87a4-1b818b268f0f.json +1 -0
- package/.output/server/chunks/_/access.mjs +1 -1
- package/.output/server/chunks/_/candidate-store.mjs +1 -1
- package/.output/server/chunks/_/catalog-view.mjs +1 -1
- package/.output/server/chunks/_/character-asset.repo.mjs +1 -1
- package/.output/server/chunks/_/data-export.mjs +6 -6
- package/.output/server/chunks/_/data-query.mjs +3 -3
- package/.output/server/chunks/_/eda-run.repo.mjs +2 -2
- package/.output/server/chunks/_/entity.mjs +1 -1
- package/.output/server/chunks/_/features.mjs +5 -5
- package/.output/server/chunks/_/golden.mjs +3 -3
- package/.output/server/chunks/_/host-bindings.mjs +1 -1
- package/.output/server/chunks/_/index.mjs +1 -1
- package/.output/server/chunks/_/line-scope.mjs +1 -1
- package/.output/server/chunks/_/mes-console.mjs +1 -1
- package/.output/server/chunks/_/mes-secrets.repo.mjs +1 -1
- package/.output/server/chunks/_/mes-templates.mjs +1 -1
- package/.output/server/chunks/_/nitro.mjs +4084 -2343
- package/.output/server/chunks/_/nitro.mjs.map +1 -1
- package/.output/server/chunks/_/ocap.mjs +1 -1
- package/.output/server/chunks/_/orchestrator.mjs +1 -1
- package/.output/server/chunks/_/promote.mjs +1 -1
- package/.output/server/chunks/_/rest-auth.mjs +1 -1
- package/.output/server/chunks/_/runtime.mjs +8 -8
- package/.output/server/chunks/_/scene-layout.repo.mjs +1 -1
- package/.output/server/chunks/_/spc.mjs +1 -1
- package/.output/server/chunks/_/validator.mjs +1 -1
- package/.output/server/chunks/build/TownView-DD1zY8xq.mjs +1 -1
- package/.output/server/chunks/build/{_id_-C0vNEbts.mjs → _id_-B9zi8WEg.mjs} +23 -12
- package/.output/server/chunks/build/_id_-B9zi8WEg.mjs.map +1 -0
- package/.output/server/chunks/build/_wsId_-LDv5SEW_.mjs +1 -1
- package/.output/server/chunks/build/daq-B5zlUIlb.mjs +1 -1
- package/.output/server/chunks/build/dcw-B-eoU7sq.mjs +1 -1
- package/.output/server/chunks/build/types-D6J7slEa.mjs +1 -1
- package/.output/server/chunks/build/useDaqAddNode-Dr5CfMpU.mjs +1 -1
- package/.output/server/chunks/build/useDaqDetailNode-DDq5osE-.mjs +1 -1
- package/.output/server/chunks/build/useDaqDetailParams-DdOcUvHG.mjs +1 -1
- package/.output/server/chunks/build/useDaqFilters-Y_NRhP6i.mjs +1 -1
- package/.output/server/chunks/build/useDaqStream-phwM5tIN.mjs +1 -1
- package/.output/server/chunks/build/useDaqTemplates-lKw2b01d.mjs +1 -1
- package/.output/server/chunks/build/useDcwAddNode-CT-oOFom.mjs +1 -1
- package/.output/server/chunks/build/useDcwStream-CNtMGcR0.mjs +1 -1
- package/.output/server/chunks/routes/api/mcp/workshop.mjs +1 -1
- package/.output/server/chunks/routes/api/system/backup/run.post.mjs +2 -2
- package/.output/server/chunks/routes/api/system/index.patch.mjs +2 -2
- package/.output/server/chunks/routes/api/system/shutdown.post.mjs +2 -2
- package/.output/server/chunks/routes/api/workshop/agent-tools/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/agent-tools/list.get.mjs +7 -2
- package/.output/server/chunks/routes/api/workshop/agent-tools/list.get.mjs.map +1 -1
- package/.output/server/chunks/routes/api/workshop/agents/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/datasets/_id/preview.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/datasets/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/datasets/_id_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/datasets/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/env/recheck.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/env/uv.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/env/venv.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index3.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index3.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index4.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index5.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index6.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/index7.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/jobs/_id/cancel.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/jobs/_id/logs.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/jobs/_id/retry.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/jobs/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/jobs/_id_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/models/_id/predict.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/models/_id/promote.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/models/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/models/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/models/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/training-plans/_id/train.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/training-plans/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/training-plans/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/training-plans/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/aml/twin/providers.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/analysis/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/analysis/_id_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/analysis/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/assets/devices/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/assets/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/assets/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channel-templates/_id/instantiate.post.mjs +2 -2
- package/.output/server/chunks/routes/api/workshop/channel-templates/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/activate.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/agents/_agentId_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/chat/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/execution-mode.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/harness-profiles/promote.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/improvement-proposals/decide.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index11.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index2.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index2.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index3.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index3.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index5.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index7.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/index7.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/line.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/members/join.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/memories/_memoryId/promote.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/memories/merge.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/products.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/products.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/terminals.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/tool-usage.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/tools/reset.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/twin-profile.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id/twin-profile.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels/index.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/channels.post.mjs +7 -7
- package/.output/server/chunks/routes/api/workshop/daq/_id/bind.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id/bindings.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id/frames/content.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id/frames.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id/ingest.post.mjs +2 -2
- package/.output/server/chunks/routes/api/workshop/daq/_id/samples.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id/test.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/alarms/_id/ack.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/controller.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/infra/reconnect.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/storage/retention.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/storage/rollup.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/storage.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/templates/_key_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/templates/_key_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/daq/test-driver.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id/bind.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id/bindings.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id/param-ledger.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id/read.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id/test.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id/write.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/controller.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index2.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index3.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index3.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index4.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index4.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index5.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index5.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index6.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index7.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/index8.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/journal/node/_nodeId/rollback.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/line/query.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/lines/_id/start.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/lines/_id/stop.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/lines/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/lines/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/mes-artifacts/file.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/mes-hook-test.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/mes-test-read.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id/judge.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id/rollback.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id/series.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/optimizations/_id_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/params/_id/read.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/params/_id/write.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/params/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/params/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/products/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/products/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/apply.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/mark-good.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/revert.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id/rollback-good.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/recipes/_id_.delete.mjs +2 -2
- package/.output/server/chunks/routes/api/workshop/dcw/recipes/index.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/runs/_id/close.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/runs/_id/data.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/runs/_id/rollback.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/templates/_key_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/templates/_key_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/dcw/test-driver.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/device-twins/_id/control.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/device-twins/_id/telemetry.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/device-twins/_id_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/device-twins/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/eda/commonality.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/eda/index6.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/eda/index6.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/eda/vm/predict.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/exp/confirmations/_id/decide.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/exp/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/fs/dirs.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/harnesses/_id/providers.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/harnesses.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/hitl/pending.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/hitl/respond.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index12.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index13.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index14.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index2.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index3.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index3.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index4.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index5.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index6.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index6.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index7.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index7.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index8.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index8.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/index9.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/mes/bridge.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/mes/datasets.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/autofix.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/compile.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/evidence.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/publish.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval-decision.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/transition.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/subgraph.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/validate.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId_.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/export/_ontologyId_.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/index.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/scene.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/traces/_ontologyId_.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId/compare.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId_.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/capabilities.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/index.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/index2.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/profiles/_id/publish.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/recommendations/_id/crosscheck.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/recommendations/_id/dispatch.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/optimization/solve.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/plugins/_name/disable.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/plugins/_name/enable.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/datasets.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/eligibility.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/experiments.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/index.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/specs/_id/publish.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/train.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/activate.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/approvals/_aid/decide.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/archive.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/channels/_channelId_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/complete.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/continue.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/deliverables/_did/waive.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/deliverables/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/deliverables/index.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/health.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index2.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index2.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index3.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index3.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index4.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index4.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index5.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index6.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index7.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/index8.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/kernel/tick.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/ledger.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/members/_userId_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/observability/activity.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/observability/route.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/observability/work-items/_wid_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/observability.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/pause.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/plan/request-approval.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/proposals/_decisionId/apply.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/reconcile.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/report.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/results/_rid/request-acceptance.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/results/_rid/review.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/results/_rid/submit.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/results/_rid/supersede.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/resume.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/sessions.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/snapshot.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/terminate.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/trace/_traceId_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/work-items/_wid/cancel.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/work-items/_wid/dispatch.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/work-items/_wid/retry.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/work-items/index.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id/work-items/index.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id_.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/_id_.patch.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/projects/instantiate.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/scene/layouts/_channelId_.delete.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/scene/layouts/_channelId_.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/tasks/_id/recovery-disposition.post.mjs +44 -0
- package/.output/server/chunks/routes/api/workshop/tasks/_id/recovery-disposition.post.mjs.map +1 -0
- package/.output/server/chunks/routes/api/workshop/tasks/recovery-holds.get.mjs +38 -0
- package/.output/server/chunks/routes/api/workshop/tasks/recovery-holds.get.mjs.map +1 -0
- package/.output/server/chunks/routes/api/workshop/teams/_id/deploy.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/teams/_id/index.put.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/teams/_id/index2.get.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/tools/sync.post.mjs +1 -1
- package/.output/server/chunks/routes/api/workshop/workspaces/_id/channel-templates/_tplId_.post.mjs +2 -2
- package/.output/server/chunks/routes/api/workshop/ws/ticket.post.mjs +1 -1
- package/.output/server/chunks/routes/renderer.mjs +2 -2
- package/.output/server/chunks/virtual/entry.mjs +6 -2
- package/.output/server/chunks/virtual/precomputed.mjs +1 -1
- package/.output/server/package.json +1 -1
- package/README-zh.md +19 -7
- package/README.md +21 -7
- package/app/components/dcw/DcwNodesTable.vue +24 -0
- package/config.yml +1 -1
- package/docs/cli.en.md +1 -1
- package/docs/cli.md +1 -1
- package/docs/mcp.en.md +30 -27
- package/docs/mcp.md +7 -3
- package/docs/plugin-idd-rag-contract.md +87 -0
- package/docs/plugins.en.md +5 -3
- package/docs/plugins.md +5 -3
- package/docs/sdk.en.md +1 -1
- package/docs/sdk.md +1 -1
- package/i18n/dicts/dcwDetail.json +221 -219
- package/i18n/locales/en.ts +2 -0
- package/i18n/locales/zh-CN.ts +2 -0
- package/package.json +3 -1
- package/scripts/check-docs-sync.mjs +20 -9
- package/scripts/onboarding/forge-channel.mjs +2 -1
- package/scripts/onboarding/lib.mjs +159 -3
- package/scripts/onboarding/onboard.mjs +2 -0
- package/scripts/onboarding/preflight.mjs +233 -231
- package/scripts/onboarding/provision-line.mjs +12 -2
- package/scripts/onboarding/sim-attest.mjs +103 -0
- package/scripts/onboarding/sim-twin.mjs +115 -19
- package/scripts/onboarding/test-connection.mjs +2 -1
- package/scripts/onboarding/v6-protected-api.mjs +41 -0
- package/scripts/onboarding/v6-protected-fixture.mjs +54 -0
- package/scripts/onboarding/verify-line.mjs +179 -136
- package/scripts/onboarding/verify-mirror.mjs +149 -145
- package/server/api/workshop/agent-tools/list.get.ts +10 -1
- package/server/api/workshop/tasks/[id]/recovery-disposition.post.ts +32 -0
- package/server/api/workshop/tasks/recovery-holds.get.ts +22 -0
- package/server/plugins-builtin/diag-bridge/host/deposit.mjs +232 -0
- package/server/plugins-builtin/diag-bridge/host/diagnosis.mjs +121 -38
- package/server/plugins-builtin/diag-bridge/host/external-v1.mjs +213 -0
- package/server/plugins-builtin/diag-bridge/host/helpers.mjs +4 -2
- package/server/plugins-builtin/diag-bridge/host/intents.mjs +65 -62
- package/server/plugins-builtin/diag-bridge/host/plugin.mjs +351 -82
- package/server/plugins-builtin/diag-bridge/host/receipt.mjs +83 -0
- package/server/plugins-builtin/diag-bridge/host/sweep.mjs +70 -91
- package/server/plugins-builtin/diag-bridge/i18n.json +4 -0
- package/server/plugins-builtin/rag-bridge/i18n.json +18 -0
- package/server/plugins-builtin/rag-bridge/index.mjs +570 -64
- package/server/services/workshop/agents/agent-interface.ts +3 -0
- package/server/services/workshop/agents/base-agent.ts +100 -4
- package/server/services/workshop/agents/execution-scope.ts +26 -0
- package/server/services/workshop/agents/hitl-capabilities.ts +3 -3
- package/server/services/workshop/agents/host-tool-bridge/dispatch.ts +42 -2
- package/server/services/workshop/agents/host-tool-bridge/tools/progress.ts +4 -0
- package/server/services/workshop/agents/host-tool-bridge/tools/tasks.ts +11 -28
- package/server/services/workshop/agents/host-tool-bridge/tools/team-delegation.ts +83 -129
- package/server/services/workshop/agents/industrial/dcw-tools.ts +27 -5
- package/server/services/workshop/agents/industrial/line-tools.ts +15 -4
- package/server/services/workshop/agents/industrial/ops-tools.ts +32 -6
- package/server/services/workshop/agents/industrial/optimization-tools.ts +28 -4
- package/server/services/workshop/agents/industrial/recipe-propose-tools.ts +26 -3
- package/server/services/workshop/agents/omp-agent/client.ts +2 -4
- package/server/services/workshop/agents/omp-agent/core.ts +3 -0
- package/server/services/workshop/agents/omp-agent/lifecycle.ts +70 -4
- package/server/services/workshop/agents/omp-agent/supervision-decision.ts +3 -1
- package/server/services/workshop/agents/omp-agent/tools-steer.ts +113 -32
- package/server/services/workshop/agents/tool-approvals.ts +113 -29
- package/server/services/workshop/agents/tool-classes.ts +72 -56
- package/server/services/workshop/db/database/open.ts +5 -2
- package/server/services/workshop/db/database/schema.ts +1 -0
- package/server/services/workshop/db/database/seed.ts +2 -2
- package/server/services/workshop/db/message.repo.ts +134 -26
- package/server/services/workshop/db/project-kernel.repo.ts +3 -3
- package/server/services/workshop/db/schema.sql +3 -1
- package/server/services/workshop/db/task.repo.ts +101 -0
- package/server/services/workshop/dcw/dcw-controller/actuation.ts +120 -9
- package/server/services/workshop/dcw/dcw-controller/contracts.ts +18 -16
- package/server/services/workshop/dcw/dcw-controller/crud.ts +23 -0
- package/server/services/workshop/dcw/dcw-controller/lines.ts +34 -2
- package/server/services/workshop/dcw/dcw-controller/recipes.ts +80 -6
- package/server/services/workshop/dcw/dcw-controller/state.ts +89 -88
- package/server/services/workshop/dcw/dcw-controller/types.ts +5 -0
- package/server/services/workshop/dcw/dcw-controller/write.ts +9 -6
- package/server/services/workshop/dcw/dcw-line.repo.ts +2 -0
- package/server/services/workshop/dcw/dcw-node.repo.ts +3 -1
- package/server/services/workshop/dcw/dcw-node.ts +346 -307
- package/server/services/workshop/dcw/dcw-runtime.ts +8 -4
- package/server/services/workshop/projects/effects.ts +47 -29
- package/server/services/workshop/projects/kernel.ts +8 -1
- package/server/services/workshop/projects/legacy-recovery.ts +36 -0
- package/server/services/workshop/projects/service.ts +15 -0
- package/server/services/workshop/runtime/agent-runtime/contracts.ts +1 -1
- package/server/services/workshop/runtime/agent-runtime/lifecycle.ts +7 -2
- package/server/services/workshop/runtime/agent-runtime/message-watchdog.ts +40 -0
- package/server/services/workshop/runtime/agent-runtime/message.ts +151 -21
- package/server/services/workshop/runtime/agent-runtime/state.ts +69 -13
- package/server/services/workshop/runtime/agent-runtime/supervise.ts +219 -42
- package/server/services/workshop/runtime/agent-runtime/types.ts +6 -0
- package/server/services/workshop/runtime/mailbox.ts +112 -21
- package/server/services/workshop/runtime/manager/admin-channel.ts +34 -22
- package/server/services/workshop/runtime/manager/host-tools.ts +18 -5
- package/server/services/workshop/runtime/manager/runtime-wiring.ts +101 -41
- package/server/services/workshop/runtime/manager/schedules.ts +3 -1
- package/server/services/workshop/runtime/manager/tasks.ts +41 -0
- package/server/services/workshop/runtime/memory/recall.ts +11 -4
- package/server/services/workshop/runtime/memory/types.ts +2 -0
- package/server/services/workshop/runtime/scheduler-loop/contracts.ts +29 -29
- package/server/services/workshop/runtime/scheduler-loop/execute.ts +7 -0
- package/server/services/workshop/runtime/scheduler-loop/rules.ts +3 -0
- package/server/services/workshop/runtime/scheduler-loop/snapshot.ts +10 -2
- package/server/services/workshop/runtime/scheduler-loop/state.ts +12 -0
- package/server/services/workshop/runtime/scheduler-loop/tick.ts +54 -5
- package/server/services/workshop/runtime/task-engine/create.ts +16 -0
- package/server/services/workshop/runtime/task-engine/helpers.ts +5 -0
- package/server/services/workshop/runtime/task-engine/legacy-recovery.ts +149 -0
- package/server/services/workshop/runtime/task-engine/lifecycle.ts +38 -1
- package/server/services/workshop/runtime/task-engine/transition.ts +4 -0
- package/server/services/workshop/runtime/task-engine/update.ts +6 -0
- package/server/services/workshop/runtime/task-engine/views.ts +61 -0
- package/server/services/workshop/tools/policy.ts +16 -1
- package/shared/dcw-protocol/line.ts +4 -0
- package/.output/public/_nuxt/C8QlHux5.js +0 -1
- package/.output/public/_nuxt/_id_.0EnzA0aA.css +0 -1
- package/.output/public/_nuxt/builds/meta/846b9c03-1442-4fcb-b3fc-1d9484eaa41b.json +0 -1
- package/.output/server/chunks/build/_id_-C0vNEbts.mjs.map +0 -1
|
@@ -2,19 +2,32 @@
|
|
|
2
2
|
* rag-bridge —— rag-knowledge 知识库桥接插件。
|
|
3
3
|
*
|
|
4
4
|
* 把本地 rag-knowledge 服务(FastAPI 后端 + Nuxt web)集成为 AgentWorkShop 的
|
|
5
|
-
*
|
|
6
|
-
* kb_agent
|
|
5
|
+
* 团队知识库:
|
|
6
|
+
* - 经验面:启动即确保「aw-industrial」知识库存在,注入 kb_agent / kb_agent_status
|
|
7
|
+
* ——检索/入库/经验全部由知识库内部 Agent 处理;
|
|
8
|
+
* - 文档面(v2.3):kb_doc_create / kb_doc_search / kb_doc_read / kb_catalog 四个
|
|
9
|
+
* 确定性工具,直接走 Web 层文档与两段检索端点(不依赖知识库内部 agent 回合)。
|
|
7
10
|
* 另开放 /health、/search、/experience 三个插件 API 便于运维探查。
|
|
8
11
|
* 服务不可达时工具返回 isError 文本(含原因与修复建议),绝不抛异常拖垮宿主。
|
|
12
|
+
*
|
|
13
|
+
* WS-0 封装约束(2026-11-18):工具名 `{前缀}_{动作}`;描述点名输入来源与输出形状;
|
|
14
|
+
* 输出首行机器可读键值;写类 riskClass='write' + noRefs;读类 riskClass='read';
|
|
15
|
+
* 调用计数入 kv(health 可见);读 ≤15s、写 ≤60s、长任务返 task_id。
|
|
9
16
|
*/
|
|
10
17
|
const KB_NAME = 'aw-industrial'
|
|
18
|
+
const DOCS_KB_NAME = 'aw-docs'
|
|
11
19
|
const DEFAULT_BASE = 'http://127.0.0.1:8770' // FastAPI 后端
|
|
12
|
-
const DEFAULT_WEB = 'http://127.0.0.1:6789' // Nuxt web(
|
|
20
|
+
const DEFAULT_WEB = 'http://127.0.0.1:6789' // Nuxt web(文档写盘/检索)
|
|
21
|
+
|
|
22
|
+
/** 读类调用超时(WS-0:读 ≤15s;两段检索允许 15s) */
|
|
23
|
+
const READ_TIMEOUT_MS = 15000
|
|
24
|
+
/** 写类调用超时(WS-0:写 ≤60s;create+reindex 合计预算) */
|
|
25
|
+
const WRITE_TIMEOUT_MS = 20000
|
|
13
26
|
|
|
14
27
|
export default {
|
|
15
28
|
name: 'rag-bridge',
|
|
16
|
-
version: '2.
|
|
17
|
-
description: 'rag-knowledge 知识库桥接 v2.
|
|
29
|
+
version: '2.3.0',
|
|
30
|
+
description: 'rag-knowledge 知识库桥接 v2.3:kb_agent 对话工具(功能解耦)+ 文档工具族(kb_doc_create/search/read/catalog,aw-docs 库,two-stage 检索)+ 韧性(有界 prompt/429 退避/L1 超时)',
|
|
18
31
|
auth: 'user', // 平台转发层按此声明统一校验(缺省 'none' 开放)
|
|
19
32
|
client: './client.mjs', // 前端面板(插件页注入;i18n 见 i18n.json)
|
|
20
33
|
// 插件配置分组:插件调用平台 API 增加自己的设置分区(设置页独立成区、可折叠)。
|
|
@@ -30,6 +43,7 @@ export default {
|
|
|
30
43
|
settings: [
|
|
31
44
|
{ key: 'base_url', type: 'string', default: DEFAULT_BASE, group: 'default', labelKey: 'plugin.rag-bridge.settings.base_url', label: 'rag-knowledge 后端地址', description: 'FastAPI 后端(http/https,host 限 127.0.0.1/localhost);保存即热生效' },
|
|
32
45
|
{ key: 'web_url', type: 'string', default: DEFAULT_WEB, group: 'default', labelKey: 'plugin.rag-bridge.settings.web_url', label: 'rag-knowledge Web 地址', description: 'Nuxt Web(文档写盘/目录);保存即热生效' },
|
|
46
|
+
{ key: 'docs_kb', type: 'string', default: DOCS_KB_NAME, group: 'default', labelKey: 'plugin.rag-bridge.settings.docs_kb', label: '文档知识库名', description: 'kb_doc_* 工具的缺省目标库(缺省 aw-docs;经验入库仍写 aw-industrial);保存即热生效' },
|
|
33
47
|
{ key: 'token', type: 'string', default: '', group: 'auth', labelKey: 'plugin.rag-bridge.settings.token', label: 'rag-knowledge API Token', description: '服务端开启鉴权时的 MCP/API Token(Authorization: Bearer);空=匿名;保存即热生效' },
|
|
34
48
|
{ key: 'agent_harness', type: 'string', default: '', group: 'default', labelKey: 'plugin.rag-bridge.settings.agent_harness', label: '知识库 Agent 引擎', description: '可选:rag-knowledge chat 的 harness(如 omp/claude);空=使用 RAG 服务默认。仅选择知识库内部 Agent 引擎,不改变平台固定的权限档。' },
|
|
35
49
|
],
|
|
@@ -39,6 +53,9 @@ export default {
|
|
|
39
53
|
const base = () => trimSlash(String(ctx.config?.get?.('plugins.rag-bridge.base_url') || ctx.kv.get('kb.base_url') || DEFAULT_BASE))
|
|
40
54
|
const web = () => trimSlash(String(ctx.config?.get?.('plugins.rag-bridge.web_url') || ctx.kv.get('kb.web_url') || DEFAULT_WEB))
|
|
41
55
|
const kbId = () => String(ctx.kv.get('kb.id') || '')
|
|
56
|
+
// 文档库独立 kv 键:双库复用同一键会互踩(经验库与文档库 kbId 不同)
|
|
57
|
+
const docsKbId = () => String(ctx.kv.get('docs.kb.id') || '')
|
|
58
|
+
const docsKbName = () => String(ctx.config?.get?.('plugins.rag-bridge.docs_kb') || ctx.kv.get('docs.kb.name') || DOCS_KB_NAME).trim() || DOCS_KB_NAME
|
|
42
59
|
// 鉴权 token(系统配置优先,kv 兜底):rag-knowledge 开启 server.auth 时所有 /api/*
|
|
43
60
|
// 要求 Bearer;backend 与 web 都认 Authorization: Bearer / X-KB-Token 两种头
|
|
44
61
|
const kbToken = () => String(ctx.config?.get?.('plugins.rag-bridge.token') || ctx.kv.get('kb.token') || '').trim()
|
|
@@ -54,6 +71,7 @@ export default {
|
|
|
54
71
|
if (ctx.kv.get('kb.base_url') == null) ctx.kv.set('kb.base_url', DEFAULT_BASE)
|
|
55
72
|
if (ctx.kv.get('kb.web_url') == null) ctx.kv.set('kb.web_url', DEFAULT_WEB)
|
|
56
73
|
ctx.kv.set('kb.name', KB_NAME)
|
|
74
|
+
if (ctx.kv.get('docs.kb.name') == null) ctx.kv.set('docs.kb.name', DOCS_KB_NAME)
|
|
57
75
|
|
|
58
76
|
// base_url/web_url 守卫:仅 http/https 且 host 必须是 127.0.0.1/localhost。
|
|
59
77
|
// web_url 也会带 Bearer token 出站(文档写盘/目录),不能只校验 base_url。
|
|
@@ -82,8 +100,8 @@ export default {
|
|
|
82
100
|
|
|
83
101
|
// ---- ensureKB:幂等初始化(失败仅告警,不阻塞装载) ----
|
|
84
102
|
try {
|
|
85
|
-
await
|
|
86
|
-
ctx.logger.info(`rag-bridge
|
|
103
|
+
await ensureKbByName(KB_NAME, 'kb.id', { experience: true })
|
|
104
|
+
ctx.logger.info(`rag-bridge 就绪:经验库=${KB_NAME}(${kbId() || '待建'}),文档库=${docsKbName()}(${docsKbId() || '按需自愈'}),出站=${state.outbound ? '启用' : '禁用'}`)
|
|
87
105
|
}
|
|
88
106
|
catch (err) {
|
|
89
107
|
ctx.logger.warn(`ensureKB 未完成(不影响装载,工具会在服务可用后按需重试):${err?.message ?? err}`)
|
|
@@ -95,21 +113,72 @@ export default {
|
|
|
95
113
|
return new Promise(resolve => ctx.timer.setTimeout(resolve, ms))
|
|
96
114
|
}
|
|
97
115
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
116
|
+
/** 工具调用计数(kv;health 可见 —— WS-4 S3 可观测三件套之一) */
|
|
117
|
+
function bump(tool, ok) {
|
|
118
|
+
const key = `usage.${tool}.${ok ? 'ok' : 'err'}`
|
|
119
|
+
try {
|
|
120
|
+
ctx.kv.set(key, Number(ctx.kv.get(key) ?? 0) + 1)
|
|
121
|
+
}
|
|
122
|
+
catch { /* 计数失败不影响调用 */ }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function toolCounters() {
|
|
126
|
+
const out = {}
|
|
127
|
+
for (const [k, v] of Object.entries(ctx.kv.all())) {
|
|
128
|
+
const m = /^usage\.(.+)\.(ok|err)$/.exec(k)
|
|
129
|
+
if (!m) continue
|
|
130
|
+
out[m[1]] ??= { ok: 0, err: 0 }
|
|
131
|
+
out[m[1]][m[2]] = Number(v) || 0
|
|
132
|
+
}
|
|
133
|
+
return out
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 写类操作审计(WS-4 S2:谁在何时写了哪个库的哪篇文档,由平台 ops 面留痕) */
|
|
137
|
+
async function auditWrite(entry) {
|
|
138
|
+
try {
|
|
139
|
+
const rec = await ctx.services.get('ops.record')
|
|
140
|
+
if (typeof rec === 'function') rec(entry)
|
|
141
|
+
}
|
|
142
|
+
catch { /* 审计不可用不阻断写入(与 diag 侧同纪律) */ }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 单次 JSON 请求;429/网络错误按 1s*重试次数退避,最多重试 2 次;
|
|
147
|
+
* retry429Ms>0 时对 429 额外等待一次(限流退避,文档 §4.5)后重试。
|
|
148
|
+
* 非 2xx 返回 { ok:false, status, error, body }(body 供调用方读 stage/error 细节)。
|
|
149
|
+
*/
|
|
150
|
+
async function callJson(method, url, body, { timeoutMs = 15000, retries = 2, headers = {}, retry429Ms = 0 } = {}) {
|
|
100
151
|
let lastErr = ''
|
|
152
|
+
let lastStatus = 0
|
|
101
153
|
const h = { ...authHeaders(), ...headers }
|
|
102
154
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
103
155
|
if (attempt > 0) await sleep(1000 * attempt) // 退避 1s*n
|
|
104
156
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
157
|
+
let res
|
|
158
|
+
if (method === 'GET') {
|
|
159
|
+
res = await ctx.http.get(url, { timeoutMs, headers: h })
|
|
160
|
+
}
|
|
161
|
+
else if (method === 'PATCH') {
|
|
162
|
+
if (typeof ctx.http.patch !== 'function') return { ok: false, error: '宿主不支持 PATCH 请求' }
|
|
163
|
+
res = await ctx.http.patch(url, body ?? {}, { timeoutMs, headers: h })
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
res = await ctx.http.post(url, body ?? {}, { timeoutMs, headers: h })
|
|
167
|
+
}
|
|
108
168
|
if (res.status === 429) {
|
|
109
|
-
lastErr =
|
|
169
|
+
lastErr = 'HTTP 429(限流)'
|
|
170
|
+
lastStatus = 429
|
|
171
|
+
if (retry429Ms > 0) {
|
|
172
|
+
ctx.logger.warn(`rag-knowledge 限流(429):退避 ${Math.round(retry429Ms / 1000)}s 后重试一次`)
|
|
173
|
+
await sleep(retry429Ms)
|
|
174
|
+
retry429Ms = 0 // 只退避一次
|
|
175
|
+
}
|
|
110
176
|
continue
|
|
111
177
|
}
|
|
112
|
-
if (!res.ok)
|
|
178
|
+
if (!res.ok) {
|
|
179
|
+
const errBody = await res.json().catch(() => null)
|
|
180
|
+
return { ok: false, status: res.status, error: `HTTP ${res.status}`, body: errBody }
|
|
181
|
+
}
|
|
113
182
|
const json = await res.json().catch(() => null)
|
|
114
183
|
if (json == null) return { ok: false, status: res.status, error: '响应不是合法 JSON' }
|
|
115
184
|
return { ok: true, status: res.status, body: json }
|
|
@@ -118,7 +187,7 @@ export default {
|
|
|
118
187
|
lastErr = err?.message ?? String(err) // 网络错误/超时(AbortSignal.timeout)
|
|
119
188
|
}
|
|
120
189
|
}
|
|
121
|
-
return { ok: false, error: lastErr || '未知错误' }
|
|
190
|
+
return { ok: false, status: lastStatus || undefined, error: lastErr || '未知错误' }
|
|
122
191
|
}
|
|
123
192
|
|
|
124
193
|
/** rag 业务调用:铁律——HTTP 200 但 body.success !== true 一律视为失败 */
|
|
@@ -126,13 +195,42 @@ export default {
|
|
|
126
195
|
const r = await callJson(method, url, body, opts)
|
|
127
196
|
if (!r.ok) return r
|
|
128
197
|
if (r.body?.success !== true) {
|
|
129
|
-
return { ok: false, error: `服务返回 success!=true:${JSON.stringify(r.body).slice(0, 200)}
|
|
198
|
+
return { ok: false, status: r.status, error: `服务返回 success!=true:${JSON.stringify(r.body).slice(0, 200)}`, body: r.body }
|
|
130
199
|
}
|
|
131
200
|
return r
|
|
132
201
|
}
|
|
133
202
|
|
|
134
203
|
const outboundOff = () => ({ ok: false, error: '出站调用已禁用:kv["kb.base_url"] 非法(仅允许 http/https 且 host 为 127.0.0.1/localhost)' })
|
|
135
204
|
|
|
205
|
+
// 失败分类文案(2026-11-16 实测回归,2026-11-18 扩文档面):过去一切失败都套同一句
|
|
206
|
+
// "请确认 rag-knowledge web 已启动" —— 401(token 过期)时把人引去查一个活着的
|
|
207
|
+
// web,完全误导。按 status/错误形态分类给出可执行的下一步。
|
|
208
|
+
const describeKbFailure = (r) => {
|
|
209
|
+
const st = Number(r?.status ?? 0)
|
|
210
|
+
const raw = String(r?.error ?? '')
|
|
211
|
+
const stage = String(r?.body?.stage ?? r?.body?.data?.stage ?? '')
|
|
212
|
+
if (st === 401 || st === 403) {
|
|
213
|
+
return `rag-knowledge Token 被拒绝(HTTP ${st}):token 可能已过期或权限不足 —— 请在设置页「rag-knowledge 鉴权」轮换 plugins.rag-bridge.token 后重试(`
|
|
214
|
+
+ `重铸路径:POST /api/auth/tokens,name=aw-bridge,scopes=[read,write];原登录会话不失效。web/backend 本身不受影响)。`
|
|
215
|
+
}
|
|
216
|
+
if (st === 429) {
|
|
217
|
+
return 'rag-knowledge 限流(HTTP 429,per-IP 600 req/60s):已退避重试一次仍限流 —— 请降低批量调用频率,稍后重试;单条检索可改用 kb_doc_search(以两段检索为主,请求更轻)。'
|
|
218
|
+
}
|
|
219
|
+
if (st === 404) {
|
|
220
|
+
return `目标资源不存在(HTTP 404):知识库/文档名可能拼错,或 async 任务已过期(2h/重启清空)。先用 kb_catalog 确认库名,再用 kb_doc_search 确认文档。原始:${raw}`
|
|
221
|
+
}
|
|
222
|
+
if (st === 502 || st === 503 || stage === 'timeout') {
|
|
223
|
+
return `知识库 Agent 面不可用(${st ? `HTTP ${st}` : ''}${stage ? `,stage=${stage}` : ''}):${raw}。只读检索可直接改用 kb_doc_search(两段检索,不依赖内部 agent 回合);若仍需 agent 面,稍后重试或改用 async + kb_agent_status。`
|
|
224
|
+
}
|
|
225
|
+
if (/abort|timeout|timed?\s*out/i.test(raw)) {
|
|
226
|
+
return `等待窗内知识库 Agent 未返回终态(${raw})——知识库内部执行慢或连接被对端挂断(服务端 600s 硬顶,客户端读超时已设 ≥750s)。建议改用 mode:'async' 提交,再用 kb_agent_status(task_id, wait_seconds=120) 轮询结果;只读检索可用 kb_doc_search 兜底。`
|
|
227
|
+
}
|
|
228
|
+
if (/fetch failed|ECONN|socket|network/i.test(raw)) {
|
|
229
|
+
return `到 rag-knowledge web(${web()})的请求失败(${raw})。请确认 web/backend 存活;若两者健康(可用 /api/plugins/rag-bridge/health 核对),多为知识库内部 agent 回合挂断 —— 同样建议改用 async + kb_agent_status,或只读用 kb_doc_search。`
|
|
230
|
+
}
|
|
231
|
+
return raw || '未知错误'
|
|
232
|
+
}
|
|
233
|
+
|
|
136
234
|
// ================= 异步任务生命周期(提交 → 跟踪 → 进度/结果 → 回执) =================
|
|
137
235
|
// rag-knowledge web 的任务登记表是进程内 Map(TTL 2h / 200 条),进程重启即丢失;
|
|
138
236
|
// 这里把 task_id 与发起者归因落到插件 kv,15s 轮询终态并主动投递平台通告 ——
|
|
@@ -241,47 +339,126 @@ export default {
|
|
|
241
339
|
}
|
|
242
340
|
}
|
|
243
341
|
|
|
244
|
-
// ================= ensureKB(catalog 查找 → 建库 → experience init) =================
|
|
342
|
+
// ================= ensureKB(catalog 查找 → 建库 → 可选 experience init) =================
|
|
245
343
|
|
|
246
|
-
|
|
344
|
+
/**
|
|
345
|
+
* 幂等确保某知识库存在并返回 kbId。
|
|
346
|
+
* ① catalog 查找同名库;② 无则建库;③ experience=true 时初始化经验文件夹(仅告警)。
|
|
347
|
+
* 双库分键:经验库 → kv 'kb.id',文档库 → kv 'docs.kb.id'(互不覆盖)。
|
|
348
|
+
*/
|
|
349
|
+
async function ensureKbByName(name, idKey, { experience = false } = {}) {
|
|
350
|
+
if (!state.outbound) throw new Error('出站调用已禁用')
|
|
247
351
|
// ① catalog 查找同名库(响应 {success,count,knowledgeBases:[{kbId,name,...}]})
|
|
248
|
-
const cat =
|
|
249
|
-
? await callJson('GET', `${web()}/api/kb/catalog`, null, { timeoutMs: 10000 })
|
|
250
|
-
: { ok: false, error: '出站已禁用' }
|
|
352
|
+
const cat = await callJson('GET', `${web()}/api/kb/catalog`, null, { timeoutMs: 10000 })
|
|
251
353
|
if (cat.ok) {
|
|
252
354
|
const list = Array.isArray(cat.body?.knowledgeBases) ? cat.body.knowledgeBases : []
|
|
253
|
-
const hit = list.find(kb => kb?.name ===
|
|
254
|
-
if (hit?.kbId) ctx.kv.set(
|
|
355
|
+
const hit = list.find(kb => kb?.name === name)
|
|
356
|
+
if (hit?.kbId) ctx.kv.set(idKey, hit.kbId)
|
|
255
357
|
}
|
|
256
358
|
else {
|
|
257
359
|
ctx.logger.warn(`catalog 不可达(${cat.error}),跳过查找直接尝试建库`)
|
|
258
360
|
}
|
|
259
361
|
// ② 无则建库(响应 {success,knowledgeBase:{id,name,path,...}})
|
|
260
|
-
if (!
|
|
261
|
-
const created =
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
362
|
+
if (!ctx.kv.get(idKey)) {
|
|
363
|
+
const created = await ragCall('POST', `${web()}/api/kb/create`, { name, description: `AgentWorkShop ${name === DOCS_KB_NAME ? '文档库(报告/规范/协议)' : '工业知识库(诊断报告/经验教训/操作规范)'}` }, { timeoutMs: WRITE_TIMEOUT_MS })
|
|
364
|
+
// 并发建库:重名 409 时按 catalog 回查一次(其他实例已建好)
|
|
365
|
+
if (!created.ok) {
|
|
366
|
+
if (created.status === 409) {
|
|
367
|
+
const again = await callJson('GET', `${web()}/api/kb/catalog`, null, { timeoutMs: 10000 })
|
|
368
|
+
const hit = (again.body?.knowledgeBases ?? []).find(kb => kb?.name === name)
|
|
369
|
+
if (hit?.kbId) ctx.kv.set(idKey, hit.kbId)
|
|
370
|
+
else throw new Error(`创建知识库 ${name} 返回 409 但 catalog 查不到同名库`)
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
throw new Error(`创建知识库 ${name} 失败:${created.error}`)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
const id = created.body?.knowledgeBase?.id
|
|
378
|
+
if (!id) throw new Error(`建库响应缺少 knowledgeBase.id:${JSON.stringify(created.body).slice(0, 200)}`)
|
|
379
|
+
ctx.kv.set(idKey, id)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// ③ 经验文件夹初始化(仅经验库;容忍已初始化/失败:仅告警)
|
|
383
|
+
if (experience) {
|
|
384
|
+
const init = await ragCall('POST', `${base()}/api/v1/experience/${ctx.kv.get(idKey)}/init`, {}, { timeoutMs: 15000 })
|
|
385
|
+
if (!init.ok) ctx.logger.warn(`experience init 未成功(可忽略或稍后手动重试):${init.error}`)
|
|
386
|
+
}
|
|
387
|
+
return String(ctx.kv.get(idKey) || '')
|
|
274
388
|
}
|
|
275
389
|
|
|
276
|
-
/** 工具侧兜底:kv 无 kb.id 时按需重跑
|
|
390
|
+
/** 工具侧兜底:kv 无 kb.id 时按需重跑 ensureKbByName */
|
|
277
391
|
async function requireKbId() {
|
|
278
392
|
if (kbId()) return kbId()
|
|
279
|
-
await
|
|
280
|
-
|
|
281
|
-
return null
|
|
393
|
+
await ensureKbByName(KB_NAME, 'kb.id', { experience: true })
|
|
394
|
+
return kbId() || null
|
|
282
395
|
}
|
|
283
396
|
|
|
284
|
-
|
|
397
|
+
/** 文档库按需自愈(懒初始化:装载期不增加一个建库往返) */
|
|
398
|
+
async function requireDocsKbId() {
|
|
399
|
+
if (docsKbId()) return docsKbId()
|
|
400
|
+
await ensureKbByName(docsKbName(), 'docs.kb.id')
|
|
401
|
+
ctx.kv.set('docs.kb.name', docsKbName())
|
|
402
|
+
return docsKbId() || null
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ================= 文档面基础调用(Web 层 §5.4/§5.5) =================
|
|
406
|
+
|
|
407
|
+
/** 目录缓存(30s):kb_doc_search/read 的 kb 解析与首个路径段归属判断用 */
|
|
408
|
+
let catalogCache = { at: 0, list: [] }
|
|
409
|
+
async function catalogList(force = false) {
|
|
410
|
+
if (!force && Date.now() - catalogCache.at < 30_000 && catalogCache.list.length) return { ok: true, list: catalogCache.list }
|
|
411
|
+
const r = await callJson('GET', `${web()}/api/kb/catalog`, null, { timeoutMs: 10000 })
|
|
412
|
+
if (!r.ok) return { ok: false, error: r.error, status: r.status }
|
|
413
|
+
const list = Array.isArray(r.body?.knowledgeBases) ? r.body.knowledgeBases : []
|
|
414
|
+
catalogCache = { at: Date.now(), list }
|
|
415
|
+
return { ok: true, list }
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** kb 参数(uuid 或名称)→ { kbId, name };缺省文档库 */
|
|
419
|
+
async function resolveKb(nameOrId) {
|
|
420
|
+
const want = String(nameOrId ?? '').trim()
|
|
421
|
+
if (!want) {
|
|
422
|
+
const id = await requireDocsKbId()
|
|
423
|
+
return id ? { ok: true, kbId: id, name: docsKbName() } : { ok: false, error: `文档库 ${docsKbName()} 不存在且自动建库失败(检查 web ${web()} 与 token)` }
|
|
424
|
+
}
|
|
425
|
+
const cat = await catalogList()
|
|
426
|
+
if (cat.ok) {
|
|
427
|
+
const hit = cat.list.find(kb => kb?.kbId === want || kb?.name === want || String(kb?.path ?? '').replace(/\\/g, '/') === want)
|
|
428
|
+
if (hit?.kbId) return { ok: true, kbId: hit.kbId, name: hit.name }
|
|
429
|
+
return { ok: false, error: `知识库「${want}」不存在。可用 kb_catalog 查看全部库名(缺省文档库=${docsKbName()})。` }
|
|
430
|
+
}
|
|
431
|
+
// catalog 不可达:直接按名称交给服务端解析(kb_id 接受 UUID 或相对路径名,§4.2)
|
|
432
|
+
return { ok: true, kbId: want, name: want }
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** 文档列表({success,kbId,count,documents:[{id,name,path,...}]}) */
|
|
436
|
+
async function docList(kbIdValue) {
|
|
437
|
+
return await ragCall('GET', `${web()}/api/kb/documents?kbId=${encodeURIComponent(kbIdValue)}`, null, { timeoutMs: READ_TIMEOUT_MS })
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const normSlashes = p => String(p ?? '').replace(/\\/g, '/').replace(/^\/+/, '')
|
|
441
|
+
|
|
442
|
+
/** 同名文档预查(幂等):服务端 create 对重名是自动改名去重而非 409,故幂等必须前置 */
|
|
443
|
+
function findDocByName(documents, fileName) {
|
|
444
|
+
const want = String(fileName).toLowerCase()
|
|
445
|
+
return (Array.isArray(documents) ? documents : []).find(d => String(d?.name ?? '').toLowerCase() === want)
|
|
446
|
+
?? (Array.isArray(documents) ? documents : []).find(d => normSlashes(d?.path).toLowerCase().endsWith('/' + want))
|
|
447
|
+
?? null
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** 若 doc_path 首段命中某个库名/路径,按该库解析(跨库读取正确归属) */
|
|
451
|
+
async function kbOfDocPath(docPath) {
|
|
452
|
+
const norm = normSlashes(docPath)
|
|
453
|
+
const seg = norm.includes('/') ? norm.slice(0, norm.indexOf('/')) : ''
|
|
454
|
+
if (!seg) return null
|
|
455
|
+
const cat = await catalogList()
|
|
456
|
+
if (!cat.ok) return null
|
|
457
|
+
const hit = cat.list.find(kb => String(kb?.name ?? '') === seg || normSlashes(kb?.path) === seg)
|
|
458
|
+
return hit ? { kbId: hit.kbId, name: hit.name } : null
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ================= 工具 ×2(kb_agent / kb_agent_status) =================
|
|
285
462
|
// 外部系统不再拼装检索/入库步骤:一个对话工具把任务原话交给 rag-knowledge
|
|
286
463
|
// 的原生 Agent(claude SDK + QDCVR skill + kb-mcp),检索/入库/经验/图谱全部
|
|
287
464
|
// 由知识库内部 Agent 自主完成,直接返回最终结果。
|
|
@@ -289,7 +466,7 @@ export default {
|
|
|
289
466
|
ctx.omp.registerTool({
|
|
290
467
|
name: 'kb_agent',
|
|
291
468
|
label: '知识库Agent',
|
|
292
|
-
description: '与 rag-knowledge 知识库的原生 Agent 对话(知识库操作唯一入口,功能解耦)。把任务原话交给它:检索问答(知识库侧自动走 QDCVR 全流程,返回带引用的可信答案)、文档入库(给出标题与完整 markdown 正文,action=ingest)、经验沉淀(action=ingest)、图谱关联等,全部由知识库内部 Agent 自主处理并返回最终结果。入库类动作会进入平台审批(HITL)
|
|
469
|
+
description: '与 rag-knowledge 知识库的原生 Agent 对话(知识库操作唯一入口,功能解耦)。把任务原话交给它:检索问答(知识库侧自动走 QDCVR 全流程,返回带引用的可信答案)、文档入库(给出标题与完整 markdown 正文,action=ingest)、经验沉淀(action=ingest)、图谱关联等,全部由知识库内部 Agent 自主处理并返回最终结果。入库类动作会进入平台审批(HITL),批准后才提交。只读检索若需确定性/低延迟,优先用 kb_doc_search。',
|
|
293
470
|
parameters: {
|
|
294
471
|
type: 'object',
|
|
295
472
|
properties: {
|
|
@@ -310,6 +487,7 @@ export default {
|
|
|
310
487
|
}
|
|
311
488
|
const prompt = String(args.prompt ?? '').trim()
|
|
312
489
|
if (!prompt) return { text: 'prompt 必填(把要做的任务完整描述给知识库 Agent)。', isError: true }
|
|
490
|
+
const action = String(args.action ?? '').trim().toLowerCase()
|
|
313
491
|
// 等待语义:wait=true 显式挂起到终态(成功/失败都给完整结果);wait=false/缺省=提交即返。
|
|
314
492
|
// 挂起期间 Agent 的回合被本工具调用占住——结构上保证"任务未完不能标记完成"。
|
|
315
493
|
const legacyAsync = args.wait === undefined && String(args.mode ?? '').trim().toLowerCase() === 'async'
|
|
@@ -319,16 +497,23 @@ export default {
|
|
|
319
497
|
// 缺省 'default' 标准审批档;此前缺省传递 bypassPermissions 允许 Agent 自行提权。
|
|
320
498
|
// RAG web 侧硬上限 600s(MAX_TIMEOUT_MS);异步入库给足上限,避免 540s 提前截断。
|
|
321
499
|
const harness = agentHarness()
|
|
322
|
-
|
|
500
|
+
// 有界 prompt(api-web §7.4):只读检索追加执行约束,降低无界深检索触发 600s 硬顶的概率。
|
|
501
|
+
// 入库(ingest)不改写业务内容,避免污染待入库正文。
|
|
502
|
+
const boundedPrompt = action === 'ingest' ? prompt : `${prompt}\n\n执行约束(平台侧追加):按 /knowledgebase-search skill 的快速路径作业(kb_list 甄别 → kb_search_vector → kb_laya_judge 一批 ≤6 refs → 至多 1-2 次 kb_doc_read 验证),不要委派子代理,不要浏览仓库文件。最终答案 ≤800 字并给出 doc_path 出处。`
|
|
503
|
+
const body = { prompt: boundedPrompt, timeout_ms: mode === 'sync' ? waitSec * 1000 : 600000, mode, permission: 'default', ...(harness ? { harness } : {}) }
|
|
323
504
|
|
|
324
505
|
if (mode === 'async') {
|
|
325
506
|
// 异步:立即返回 task_id,知识库后台完成;结果稍后用 kb_agent_status 查询
|
|
326
|
-
const sub = await ragCall('POST', web() + '/api/kb/agent/chat', body, { timeoutMs: 30000, retries: 0 })
|
|
507
|
+
const sub = await ragCall('POST', web() + '/api/kb/agent/chat', body, { timeoutMs: 30000, retries: 0, retry429Ms: 30000 })
|
|
327
508
|
if (!sub.ok) {
|
|
328
|
-
|
|
509
|
+
bump('kb_agent', false)
|
|
510
|
+
return { text: '知识库异步任务提交失败:' + describeKbFailure(sub), isError: true }
|
|
329
511
|
}
|
|
330
512
|
const taskId = String(sub.body?.task_id ?? '')
|
|
331
|
-
if (!taskId)
|
|
513
|
+
if (!taskId) {
|
|
514
|
+
bump('kb_agent', false)
|
|
515
|
+
return { text: '知识库异步任务提交异常:响应缺少 task_id。', isError: true }
|
|
516
|
+
}
|
|
332
517
|
// 落 kv:异步任务与发起者归因,供后台轮询主动回执;进程重启后仍可继续跟踪
|
|
333
518
|
ctx.kv.set(kbTaskKey(taskId), {
|
|
334
519
|
taskId,
|
|
@@ -338,15 +523,24 @@ export default {
|
|
|
338
523
|
channelId: agent?.channelId ?? '',
|
|
339
524
|
prompt: prompt.slice(0, 160),
|
|
340
525
|
})
|
|
526
|
+
bump('kb_agent', true)
|
|
341
527
|
return { text: '已提交知识库异步任务(后台执行中,无需等待):\ntask_id=' + taskId + '\n完成后平台会自动回执到你的信箱并唤醒你;空闲时也可调用 kb_agent_status(task_id, wait_seconds=120) 等待并获取结果。' }
|
|
342
528
|
}
|
|
343
529
|
|
|
344
|
-
// 同步请求禁止网络重试:POST
|
|
345
|
-
|
|
530
|
+
// 同步请求禁止网络重试:POST 可能已在知识库侧启动回合,重试会重复入库/重复生成。
|
|
531
|
+
// 读超时 ≥750s(L1:服务端 600s 硬顶,超时回合回包可能晚于 630s)。
|
|
532
|
+
const syncTimeoutMs = Math.max(waitSec * 1000 + 30_000, 750_000)
|
|
533
|
+
const r = await ragCall('POST', web() + '/api/kb/agent/chat', body, { timeoutMs: syncTimeoutMs, retries: 0, retry429Ms: 30000 })
|
|
346
534
|
if (!r.ok) {
|
|
347
|
-
|
|
535
|
+
bump('kb_agent', false)
|
|
536
|
+
// 只读检索类失败 → 追加确定性兜底指引(api-web §7.9:two-stage 可作只读降级)
|
|
537
|
+
const fallback = action !== 'ingest'
|
|
538
|
+
? '\n\n降级方案:本次为只读检索,可直接改用 kb_doc_search(query=同一个问题,kb=目标库) 走两段检索(不依赖知识库内部 Agent 回合)。'
|
|
539
|
+
: ''
|
|
540
|
+
return { text: '知识库 Agent 调用失败(本次调用即终态,失败结果已如实返回):' + describeKbFailure(r) + fallback, isError: true }
|
|
348
541
|
}
|
|
349
542
|
const reply = String(r.body?.reply ?? '').trim()
|
|
543
|
+
bump('kb_agent', true)
|
|
350
544
|
return { text: '✅ 知识库任务完成(等待到终态)。\n\n' + (reply || '(知识库 Agent 返回空回复)') }
|
|
351
545
|
},
|
|
352
546
|
})
|
|
@@ -364,6 +558,8 @@ export default {
|
|
|
364
558
|
required: ['task_id'],
|
|
365
559
|
},
|
|
366
560
|
roles: ['lead', 'worker'],
|
|
561
|
+
riskClass: 'read',
|
|
562
|
+
noRefs: true,
|
|
367
563
|
handler: async (args) => {
|
|
368
564
|
if (!state.outbound) {
|
|
369
565
|
return { text: '知识库 Agent 不可用:' + outboundOff().error + '。修复后重启服务。', isError: true }
|
|
@@ -406,6 +602,309 @@ export default {
|
|
|
406
602
|
},
|
|
407
603
|
})
|
|
408
604
|
|
|
605
|
+
// ================= 工具 ×4(文档面:确定性,不依赖内部 agent 回合) =================
|
|
606
|
+
|
|
607
|
+
ctx.omp.registerTool({
|
|
608
|
+
name: 'kb_doc_create',
|
|
609
|
+
label: '创建知识库文档',
|
|
610
|
+
description: '把 Markdown 文档写入 rag-knowledge 知识库(缺省 aw-docs)并重建索引。name=标题(同名已存在视为成功,幂等);content=完整正文;可选 description/tags。返回 doc_path,可直接交给 kb_doc_read/kb_doc_search 验证。写类工具,调用留审计。',
|
|
611
|
+
parameters: {
|
|
612
|
+
type: 'object',
|
|
613
|
+
properties: {
|
|
614
|
+
name: { type: 'string', description: '文档标题/文件名(自动补 .md;同名文档已存在时幂等返回既有 doc_path)' },
|
|
615
|
+
content: { type: 'string', description: '完整 Markdown 正文(纯文本直入;超过服务端大文档阈值时由服务端拆分)' },
|
|
616
|
+
description: { type: 'string', description: '文档描述(可选;进入检索元数据,建议 1-2 句)' },
|
|
617
|
+
kb: { type: 'string', description: `目标知识库名或 kbId(缺省 ${DOCS_KB_NAME};经验库是 ${KB_NAME},显式指定时输出漂移警告)` },
|
|
618
|
+
tags: { type: 'array', items: { type: 'string' }, description: '标签(可选,≤16 项;创建后尽力写入,失败不影响文档落盘)' },
|
|
619
|
+
},
|
|
620
|
+
required: ['name', 'content'],
|
|
621
|
+
},
|
|
622
|
+
roles: ['lead', 'worker'],
|
|
623
|
+
riskClass: 'write',
|
|
624
|
+
noRefs: true,
|
|
625
|
+
handler: async (args, agent) => {
|
|
626
|
+
try {
|
|
627
|
+
if (!state.outbound) return { text: '出站调用已禁用:' + outboundOff().error, isError: true }
|
|
628
|
+
const rawName = String(args.name ?? '').trim()
|
|
629
|
+
const content = String(args.content ?? '')
|
|
630
|
+
if (!rawName) return { text: 'name 必填(文档标题)。', isError: true }
|
|
631
|
+
if (!content.trim()) return { text: 'content 必填(文档正文不能为空)。', isError: true }
|
|
632
|
+
// 文件名净化:Windows 非法字符(<>:"/\|?* 与控制字符)会让服务端写盘 500;
|
|
633
|
+
// 在客户端先行替换为 '-' 并保留中文/空格,避免不可读的 500。
|
|
634
|
+
const unsafeChars = '<>:"/\\|?*'
|
|
635
|
+
const safeBase = Array.from(rawName)
|
|
636
|
+
.map(ch => (ch.charCodeAt(0) < 32 || unsafeChars.includes(ch) ? '-' : ch))
|
|
637
|
+
.join('')
|
|
638
|
+
.replace(/\s+/g, ' ')
|
|
639
|
+
.trim()
|
|
640
|
+
const fileName = /\.[A-Za-z0-9]+$/.test(safeBase) ? safeBase : `${safeBase}.md`
|
|
641
|
+
const kbSel = await resolveKb(args.kb)
|
|
642
|
+
if (!kbSel.ok) return { text: kbSel.error, isError: true }
|
|
643
|
+
const { kbId: targetKb, name: targetName } = kbSel
|
|
644
|
+
const drift = targetName === KB_NAME
|
|
645
|
+
? `\n⚠️ 目标库是经验库 ${KB_NAME};文档默认应入 ${docsKbName()}(已按显式指定执行,未拦截)。`
|
|
646
|
+
: ''
|
|
647
|
+
|
|
648
|
+
// 幂等前置:服务端 create 对重名是「自动改名 (n)」而非 409 —— 先按同名查既有文档,
|
|
649
|
+
// 命中即视为完成(同一份文档重复调用不会产生副本)。
|
|
650
|
+
const listed = await docList(targetKb)
|
|
651
|
+
if (listed.ok) {
|
|
652
|
+
const hit = findDocByName(listed.body?.documents, fileName)
|
|
653
|
+
if (hit?.path) {
|
|
654
|
+
bump('kb_doc_create', true)
|
|
655
|
+
return { text: `status=exists doc_path=${normSlashes(hit.path)} kb=${targetName} chars=${String(content).length} idempotent=yes\n文档「${fileName}」已存在于 ${targetName},本次未重复创建(幂等)。` + drift }
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
else if (listed.status === 401 || listed.status === 403) {
|
|
659
|
+
bump('kb_doc_create', false)
|
|
660
|
+
return { text: describeKbFailure(listed), isError: true }
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const created = await callJson('POST', `${web()}/api/kb/documents/create`,
|
|
664
|
+
{ kbId: targetKb, name: fileName, content, description: String(args.description ?? '').trim() },
|
|
665
|
+
{ timeoutMs: WRITE_TIMEOUT_MS, retries: 0 })
|
|
666
|
+
if (!created.ok) {
|
|
667
|
+
// 并发竞态或服务端策略:409 时回查同名文档,命中即按幂等成功
|
|
668
|
+
if (created.status === 409) {
|
|
669
|
+
const again = await docList(targetKb)
|
|
670
|
+
const hit = findDocByName(again.body?.documents, fileName)
|
|
671
|
+
if (hit?.path) {
|
|
672
|
+
bump('kb_doc_create', true)
|
|
673
|
+
return { text: `status=exists doc_path=${normSlashes(hit.path)} kb=${targetName} chars=${String(content).length} idempotent=yes\n重名冲突(HTTP 409)但同名文档已存在,按幂等成功处理。` + drift }
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
bump('kb_doc_create', false)
|
|
677
|
+
return { text: `文档创建失败(${describeKbFailure(created)})。先 kb_catalog 确认库「${targetName}」存在、token 有效后重试。`, isError: true }
|
|
678
|
+
}
|
|
679
|
+
const docPath = normSlashes(created.body?.document?.path ?? '')
|
|
680
|
+
const docId = String(created.body?.document?.id ?? '')
|
|
681
|
+
const partCount = Number(created.body?.part_count ?? 0) || 0
|
|
682
|
+
const splitNote = created.body?.split ? `(服务端按大文档拆分为 ${partCount} 篇,首篇 doc_path 如下)` : ''
|
|
683
|
+
|
|
684
|
+
// 单文档索引(documents/create 只写盘,不建向量/BM25 —— 文档 §5.5)。
|
|
685
|
+
// 走 backend /api/v1/search/index-document:向量 + 图谱 + **BM25 增量**
|
|
686
|
+
// (实测:web /api/search/reindex 不刷新 backend 进程内 BM25,新文档两段检索会 0 命中)。
|
|
687
|
+
let indexState = 'ok'
|
|
688
|
+
const idx = await callJson('POST', `${base()}/api/v1/search/index-document`,
|
|
689
|
+
docId
|
|
690
|
+
? { doc_id: docId, doc_name: fileName, description: String(args.description ?? '').trim() }
|
|
691
|
+
: { kb_id: targetKb, doc_path: docPath, doc_name: fileName, description: String(args.description ?? '').trim(), content },
|
|
692
|
+
{ timeoutMs: WRITE_TIMEOUT_MS, retries: 0 })
|
|
693
|
+
if (!idx.ok) {
|
|
694
|
+
// 索引失败不影响文档落盘:退一步整库 reindex(会重建向量;BM25 是否刷新取决于后端版本),如实标注降级
|
|
695
|
+
const rx = await callJson('POST', `${web()}/api/search/reindex`, { kb_id: targetKb }, { timeoutMs: WRITE_TIMEOUT_MS, retries: 0 })
|
|
696
|
+
indexState = rx.ok ? 'degraded(reindex)' : `failed(${idx.error})`
|
|
697
|
+
ctx.logger.warn(`kb_doc_create:index-document 失败(${idx.status ?? '?'} ${idx.error});fallback reindex=${rx.ok ? 'ok' : rx.error}`)
|
|
698
|
+
}
|
|
699
|
+
// 可见性窗口:create 已返回 path 时一次即时确认;缺失时按 3×5s 重试列表(≤15s)
|
|
700
|
+
let visible = Boolean(docPath)
|
|
701
|
+
if (!visible) {
|
|
702
|
+
for (let i = 0; i < 3 && !visible; i++) {
|
|
703
|
+
if (i > 0) await sleep(5000)
|
|
704
|
+
const again = await docList(targetKb)
|
|
705
|
+
const hit = findDocByName(again.body?.documents, fileName)
|
|
706
|
+
if (hit?.path) {
|
|
707
|
+
visible = true
|
|
708
|
+
break
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
// 标签:尽力写入(PATCH 失败不影响文档本体)
|
|
713
|
+
let tagsState = 'none'
|
|
714
|
+
if (Array.isArray(args.tags) && args.tags.length && docPath) {
|
|
715
|
+
const tagRes = await callJson('PATCH', `${web()}/api/kb/documents/tags`,
|
|
716
|
+
{ kbId: targetKb, docPath, tags: args.tags.map(String).slice(0, 16) },
|
|
717
|
+
{ timeoutMs: READ_TIMEOUT_MS, retries: 0 })
|
|
718
|
+
tagsState = tagRes.ok ? 'ok' : `failed(${tagRes.error})`
|
|
719
|
+
}
|
|
720
|
+
const finalPath = docPath || '(列表暂未确认,可稍后用 kb_doc_search 检索)'
|
|
721
|
+
bump('kb_doc_create', true)
|
|
722
|
+
await auditWrite({
|
|
723
|
+
actor: agent?.agentId ?? 'user', actorName: agent?.name ?? '', actorKind: agent ? 'agent' : 'user',
|
|
724
|
+
action: 'plugin.kb_doc.create', kind: 'write', scope: 'system',
|
|
725
|
+
targetKind: 'document', targetId: finalPath,
|
|
726
|
+
summary: `知识库文档创建 ${targetName}:${fileName}(${String(content).length} 字符)`,
|
|
727
|
+
detail: { kb: targetName, kbId: targetKb, docPath: finalPath, channelId: agent?.channelId ?? '', role: agent?.role ?? '' },
|
|
728
|
+
})
|
|
729
|
+
return {
|
|
730
|
+
text: [
|
|
731
|
+
`status=created doc_path=${finalPath} kb=${targetName} chars=${String(content).length} index=${indexState} tags=${tagsState}${splitNote ? ' split=yes' : ''}`,
|
|
732
|
+
`✅ 文档「${fileName}」已写入 ${targetName}${splitNote}。${visible ? '' : ' 列表可见性暂未确认(索引窗口),稍后 kb_doc_search 复核。'}`,
|
|
733
|
+
`调用者=${agent?.agentId ?? '(用户直调)'} 角色=${agent?.role ?? '-'}${drift}`,
|
|
734
|
+
`下一步:kb_doc_search(query=标题或关键词) 验证可检索;kb_doc_read(doc_path) 核对正文。`,
|
|
735
|
+
].filter(Boolean).join('\n'),
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
catch (err) {
|
|
739
|
+
bump('kb_doc_create', false)
|
|
740
|
+
return { text: `kb_doc_create 异常:${err?.message ?? err}`, isError: true }
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
ctx.omp.registerTool({
|
|
746
|
+
name: 'kb_doc_search',
|
|
747
|
+
label: '检索知识库文档',
|
|
748
|
+
description: '检索 rag-knowledge 文档(two-stage 两段检索为主,失败自动关键词兜底)。query=检索词(自然语言);kb 缺省 aw-docs,top_k 缺省 5。返回每条 doc_path+分数+片段,可直接接 kb_doc_read 读全文。只读、秒级。',
|
|
749
|
+
parameters: {
|
|
750
|
+
type: 'object',
|
|
751
|
+
properties: {
|
|
752
|
+
query: { type: 'string', description: '检索词/问题(自然语言;中文可直接用)' },
|
|
753
|
+
kb: { type: 'string', description: `知识库名或 kbId(缺省 ${DOCS_KB_NAME};不传=文档库)` },
|
|
754
|
+
top_k: { type: 'number', description: '返回条数(1-20,缺省 5)' },
|
|
755
|
+
},
|
|
756
|
+
required: ['query'],
|
|
757
|
+
},
|
|
758
|
+
roles: ['lead', 'worker'],
|
|
759
|
+
riskClass: 'read',
|
|
760
|
+
noRefs: true,
|
|
761
|
+
handler: async (args) => {
|
|
762
|
+
try {
|
|
763
|
+
if (!state.outbound) return { text: '出站调用已禁用:' + outboundOff().error, isError: true }
|
|
764
|
+
const query = String(args.query ?? '').trim()
|
|
765
|
+
if (!query) return { text: 'query 必填(检索词)。', isError: true }
|
|
766
|
+
const kbsel = await resolveKb(args.kb)
|
|
767
|
+
if (!kbsel.ok) return { text: kbsel.error, isError: true }
|
|
768
|
+
const topK = Math.min(Math.max(Math.round(Number(args.top_k) || 5), 1), 20)
|
|
769
|
+
const ts = await ragCall('POST', `${web()}/api/search/two-stage`, { query, kb_id: kbsel.kbId, stage2_top_k: topK }, { timeoutMs: READ_TIMEOUT_MS })
|
|
770
|
+
if (ts.ok) {
|
|
771
|
+
const results = Array.isArray(ts.body?.stage2?.results) ? ts.body.stage2.results.slice(0, topK) : []
|
|
772
|
+
const total = Number(ts.body?.total_results ?? results.length)
|
|
773
|
+
if (!results.length) {
|
|
774
|
+
bump('kb_doc_search', true)
|
|
775
|
+
return { text: `status=ok mode=two-stage hits=0 kb=${kbsel.name} total=${total}\n未命中。放宽关键词(去掉限定词),或确认文档是否已入库(kb_catalog 看 documentCount)。` }
|
|
776
|
+
}
|
|
777
|
+
const lines = results.map((r, i) => {
|
|
778
|
+
const snippet = String(r?.content ?? '').replace(/\s+/g, ' ').slice(0, 220)
|
|
779
|
+
return `${i + 1}. doc_path=${normSlashes(r?.doc_path)} score=${Number(r?.score ?? 0).toFixed(4)}${r?.chunk_index != null ? ` chunk=${r.chunk_index}` : ''}\n ${snippet}${snippet.length >= 220 ? '…' : ''}`
|
|
780
|
+
})
|
|
781
|
+
bump('kb_doc_search', true)
|
|
782
|
+
return {
|
|
783
|
+
text: [
|
|
784
|
+
`status=ok mode=two-stage hits=${results.length} kb=${kbsel.name} total=${total}`,
|
|
785
|
+
...lines,
|
|
786
|
+
'',
|
|
787
|
+
'读全文 → kb_doc_read(doc_path=<上面任一条>)。',
|
|
788
|
+
].join('\n'),
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
// 兜底:关键词检索(api-web §5.4/§7.9)
|
|
792
|
+
const kw = await ragCall('GET', `${web()}/api/kb/search?query=${encodeURIComponent(query)}&top_k=${topK}`, null, { timeoutMs: READ_TIMEOUT_MS })
|
|
793
|
+
if (kw.ok) {
|
|
794
|
+
const hits = Array.isArray(kw.body?.hits) ? kw.body.hits.slice(0, topK) : []
|
|
795
|
+
bump('kb_doc_search', hits.length > 0)
|
|
796
|
+
if (!hits.length) {
|
|
797
|
+
return { text: `status=ok mode=keyword-degraded hits=0 kb=(跨库) total=0\n两段检索不可用(${ts.error}),关键词兜底也未命中。稍后重试两段检索,或换关键词。` }
|
|
798
|
+
}
|
|
799
|
+
const lines = hits.map((h, i) => `${i + 1}. doc_path=${normSlashes(h?.path)} score=${Number(h?.score ?? 0).toFixed(2)} kb=${h?.kbName ?? '?'}\n 名称=${h?.docName ?? '?'} 描述=${String(h?.description ?? '').slice(0, 160)}`)
|
|
800
|
+
return {
|
|
801
|
+
text: [
|
|
802
|
+
`status=ok mode=keyword-degraded hits=${hits.length} kb=(跨库) degraded=two-stage(${ts.error})`,
|
|
803
|
+
...lines,
|
|
804
|
+
'',
|
|
805
|
+
'注意:两段检索(向量)不可用,本次为关键词元数据兜底(仅名称/描述匹配,不扫正文);命中后一定要 kb_doc_read 核实。',
|
|
806
|
+
].join('\n'),
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
bump('kb_doc_search', false)
|
|
810
|
+
return { text: `文档检索失败(two-stage:${describeKbFailure(ts)};关键词兜底:${kw.error})。检查 web 地址/token 与 IDD/RAG 服务状态。`, isError: true }
|
|
811
|
+
}
|
|
812
|
+
catch (err) {
|
|
813
|
+
bump('kb_doc_search', false)
|
|
814
|
+
return { text: `kb_doc_search 异常:${err?.message ?? err}`, isError: true }
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
})
|
|
818
|
+
|
|
819
|
+
ctx.omp.registerTool({
|
|
820
|
+
name: 'kb_doc_read',
|
|
821
|
+
label: '读取知识库文档',
|
|
822
|
+
description: '读取知识库文档正文(doc_path 来自 kb_doc_search / kb_doc_create)。kb 缺省 aw-docs;doc_path 含库名前缀时自动识别归属。max_chars 截断(缺省 4000,上限 20000)。返回正文与截断标记,可核对内容一致性。',
|
|
823
|
+
parameters: {
|
|
824
|
+
type: 'object',
|
|
825
|
+
properties: {
|
|
826
|
+
doc_path: { type: 'string', description: '文档路径(kb_doc_search 返回的 doc_path,或库内相对路径/文件名)' },
|
|
827
|
+
kb: { type: 'string', description: `知识库名或 kbId(缺省 ${DOCS_KB_NAME};doc_path 自带库名前缀时以路径为准)` },
|
|
828
|
+
max_chars: { type: 'number', description: '正文截断上限(500-20000,缺省 4000)' },
|
|
829
|
+
},
|
|
830
|
+
required: ['doc_path'],
|
|
831
|
+
},
|
|
832
|
+
roles: ['lead', 'worker'],
|
|
833
|
+
riskClass: 'read',
|
|
834
|
+
noRefs: true,
|
|
835
|
+
handler: async (args) => {
|
|
836
|
+
try {
|
|
837
|
+
if (!state.outbound) return { text: '出站调用已禁用:' + outboundOff().error, isError: true }
|
|
838
|
+
const docPath = String(args.doc_path ?? '').trim()
|
|
839
|
+
if (!docPath) return { text: 'doc_path 必填(先用 kb_doc_search 检索)。', isError: true }
|
|
840
|
+
const maxChars = Math.min(Math.max(Math.round(Number(args.max_chars) || 4000), 500), 20000)
|
|
841
|
+
let kbSel = await resolveKb(args.kb)
|
|
842
|
+
if (!kbSel.ok) return { text: kbSel.error, isError: true }
|
|
843
|
+
// 路径自带库名前缀(如 aw-docs/xxx.md)→ 按前缀解析归属,避免跨库读取时被拼错库根
|
|
844
|
+
const byPath = await kbOfDocPath(docPath)
|
|
845
|
+
if (byPath) kbSel = { ok: true, kbId: byPath.kbId, name: byPath.name }
|
|
846
|
+
const r = await ragCall('GET', `${web()}/api/kb/document?kbId=${encodeURIComponent(kbSel.kbId)}&docPath=${encodeURIComponent(docPath)}&max_chars=${maxChars}`, null, { timeoutMs: READ_TIMEOUT_MS })
|
|
847
|
+
if (!r.ok) {
|
|
848
|
+
bump('kb_doc_read', false)
|
|
849
|
+
const detail = r.status === 400
|
|
850
|
+
? 'doc_path 无法在目标库内解析(检查库名与路径;路径可来自 kb_doc_search)'
|
|
851
|
+
: r.status === 404
|
|
852
|
+
? '404 文档不存在(路径可能拼错;先用 kb_doc_search 重新获取 doc_path)'
|
|
853
|
+
: describeKbFailure(r)
|
|
854
|
+
return { text: `文档读取失败(${detail})。`, isError: true }
|
|
855
|
+
}
|
|
856
|
+
const content = String(r.body?.content ?? '')
|
|
857
|
+
bump('kb_doc_read', true)
|
|
858
|
+
return {
|
|
859
|
+
text: [
|
|
860
|
+
`status=ok doc_path=${normSlashes(r.body?.path ?? docPath)} kb=${kbSel.name} chars=${content.length} total_lines=${r.body?.totalLines ?? '?'} truncated=${r.body?.truncated ? 'yes' : 'no'}`,
|
|
861
|
+
content,
|
|
862
|
+
r.body?.truncated ? `…[已截断:max_chars=${maxChars};需要更多内容可提高 max_chars(≤20000)]` : '',
|
|
863
|
+
].filter(Boolean).join('\n'),
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
catch (err) {
|
|
867
|
+
bump('kb_doc_read', false)
|
|
868
|
+
return { text: `kb_doc_read 异常:${err?.message ?? err}`, isError: true }
|
|
869
|
+
}
|
|
870
|
+
},
|
|
871
|
+
})
|
|
872
|
+
|
|
873
|
+
ctx.omp.registerTool({
|
|
874
|
+
name: 'kb_catalog',
|
|
875
|
+
label: '知识库目录',
|
|
876
|
+
description: '列出 rag-knowledge 全部知识库:名称、kbId、文档数。用于确认目标库存在(如 aw-docs/aw-industrial)与挑选 kb_doc_search 的 kb 参数。只读一次调用,≤15s。',
|
|
877
|
+
parameters: { type: 'object', properties: {} },
|
|
878
|
+
roles: ['lead', 'worker'],
|
|
879
|
+
riskClass: 'read',
|
|
880
|
+
noRefs: true,
|
|
881
|
+
handler: async () => {
|
|
882
|
+
try {
|
|
883
|
+
if (!state.outbound) return { text: '出站调用已禁用:' + outboundOff().error, isError: true }
|
|
884
|
+
const cat = await catalogList(true)
|
|
885
|
+
if (!cat.ok) {
|
|
886
|
+
bump('kb_catalog', false)
|
|
887
|
+
return { text: `知识库目录不可用(${describeKbFailure(cat)})。`, isError: true }
|
|
888
|
+
}
|
|
889
|
+
const list = cat.list
|
|
890
|
+
const shown = list.slice(0, 60)
|
|
891
|
+
const lines = shown.map(kb => `- ${kb?.name ?? '?'} | ${kb?.kbId ?? '?'} | docs=${kb?.documentCount ?? '?'}${kb?.parentId ? ' (子库)' : ''}`)
|
|
892
|
+
bump('kb_catalog', true)
|
|
893
|
+
return {
|
|
894
|
+
text: [
|
|
895
|
+
`status=ok kbs=${list.length} shown=${shown.length} docs_kb=${docsKbName()}(${docsKbId() || '按需自愈'})`,
|
|
896
|
+
...lines,
|
|
897
|
+
list.length > shown.length ? `…还有 ${list.length - shown.length} 个库未列出(按需用 kb 参数直接指定名称)` : '',
|
|
898
|
+
].filter(Boolean).join('\n'),
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
catch (err) {
|
|
902
|
+
bump('kb_catalog', false)
|
|
903
|
+
return { text: `kb_catalog 异常:${err?.message ?? err}`, isError: true }
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
})
|
|
907
|
+
|
|
409
908
|
// 后台轮询:15s 一次,终态主动回执(与 diag-bridge sweep 同构)
|
|
410
909
|
ctx.timer.setInterval(() => {
|
|
411
910
|
pollKbTasks().catch(err => ctx.logger.warn(`知识库任务轮询异常(继续):${err?.message ?? err}`))
|
|
@@ -426,7 +925,7 @@ export default {
|
|
|
426
925
|
return q
|
|
427
926
|
}
|
|
428
927
|
|
|
429
|
-
// 健康:后端 + web
|
|
928
|
+
// 健康:后端 + web 存活、双 kb.id(缺失时按需自愈)、出站开关、token 实测、工具计数
|
|
430
929
|
ctx.route('GET', '/health', async () => {
|
|
431
930
|
const backend = state.outbound
|
|
432
931
|
? await callJson('GET', `${base()}/api/v1/health`, null, { timeoutMs: 5000, retries: 0 })
|
|
@@ -434,30 +933,37 @@ export default {
|
|
|
434
933
|
const webR = state.outbound
|
|
435
934
|
? await callJson('GET', `${web()}/api/kb/catalog`, null, { timeoutMs: 5000, retries: 0 })
|
|
436
935
|
: { ok: false, error: '出站已禁用' }
|
|
437
|
-
if (!kbId() && state.outbound &&
|
|
438
|
-
|
|
936
|
+
if ((!kbId() || !docsKbId()) && state.outbound && webR.ok) {
|
|
937
|
+
// 装载期 401/不可达导致 kb.id 缺失 → 探活时自愈(经验库与文档库各自独立)
|
|
938
|
+
if (!kbId()) await ensureKbByName(KB_NAME, 'kb.id', { experience: true }).catch(() => {})
|
|
939
|
+
if (!docsKbId()) await ensureKbByName(docsKbName(), 'docs.kb.id').catch(() => {})
|
|
439
940
|
}
|
|
941
|
+
// token 三态实测(api-web §3:Web 层 POST /api/auth/verify {token});未配 token 时按匿名
|
|
942
|
+
const verify = await (async () => {
|
|
943
|
+
if (!state.outbound) return { configured: Boolean(kbToken()), accepted: null, reason: '出站已禁用' }
|
|
944
|
+
if (!kbToken()) return { configured: false, accepted: true, reason: 'anonymous' }
|
|
945
|
+
const v = await callJson('POST', `${web()}/api/auth/verify`, { token: kbToken() }, { timeoutMs: 5000, retries: 0 })
|
|
946
|
+
if (v.ok) return { configured: true, accepted: v.body?.valid === true, reason: 'verify' }
|
|
947
|
+
// verify 端点不可用(旧后端)→ 回退到受保护 GET /auth/me
|
|
948
|
+
const me = await callJson('GET', `${base()}/api/v1/auth/me`, null, { timeoutMs: 5000, retries: 0 })
|
|
949
|
+
return { configured: true, accepted: me.ok ? true : (me.status === 401 || me.status === 403 ? false : null), reason: 'auth/me-fallback' }
|
|
950
|
+
})()
|
|
440
951
|
return {
|
|
441
952
|
plugin: 'rag-bridge',
|
|
953
|
+
version: '2.3.0',
|
|
442
954
|
outbound: state.outbound,
|
|
443
955
|
auth: kbToken() ? 'bearer' : 'anonymous',
|
|
444
|
-
// token 配置与「实测是否被接受」分开呈现:401/403 = 明确被拒(运维一眼看出 token 配错),
|
|
445
|
-
// 网络不通/超时为 null(未知),2xx 或非鉴权类失败为 true(未被拒)。
|
|
446
|
-
// 实测打受保护 GET /api/v1/auth/me —— rag 后端 GET 只读端点公开(/health 匿名可过,
|
|
447
|
-
// 测不出 token 对错),/auth/me 无 token/错 token 均 401。
|
|
448
956
|
token: {
|
|
449
957
|
configured: Boolean(kbToken()),
|
|
450
|
-
accepted:
|
|
451
|
-
|
|
452
|
-
if (!kbToken()) return backend.ok ? true : null
|
|
453
|
-
const me = await callJson('GET', `${base()}/api/v1/auth/me`, null, { timeoutMs: 5000, retries: 0 })
|
|
454
|
-
return me.ok ? true : (me.status === 401 || me.status === 403 ? false : null)
|
|
455
|
-
})(),
|
|
958
|
+
accepted: verify.accepted,
|
|
959
|
+
verify: verify.reason,
|
|
456
960
|
},
|
|
457
|
-
kb: { name: KB_NAME, id: kbId() || null },
|
|
961
|
+
kb: { name: KB_NAME, id: kbId() || null, role: 'experience' },
|
|
962
|
+
docs: { name: docsKbName(), id: docsKbId() || null, role: 'documents' },
|
|
458
963
|
backend: { url: base(), ok: backend.ok, ...(backend.ok ? { status: backend.body?.status ?? null } : { status: backend.status ?? null, error: backend.error }) },
|
|
459
964
|
web: { url: web(), ok: webR.ok, ...(webR.ok ? { knowledgeBases: webR.body?.count ?? null } : { error: webR.error }) },
|
|
460
965
|
counters: { store: ctx.kv.get('store.count') ?? 0, index: ctx.kv.get('index.count') ?? 0 },
|
|
966
|
+
toolCounters: toolCounters(),
|
|
461
967
|
}
|
|
462
968
|
})
|
|
463
969
|
|