@xopcai/xopc 0.0.307 → 0.0.309
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/dist/browser-ext/_locales/en/messages.json +8 -0
- package/dist/browser-ext/_locales/zh_CN/messages.json +8 -0
- package/dist/browser-ext/dist/assets/{sidepanel-BbSQr-6P.css → sidepanel-DD6GEMvc.css} +16 -0
- package/dist/browser-ext/dist/sidepanel.html +1 -1
- package/dist/browser-ext/dist/sidepanel.js +537 -96
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-wgSB2HYK.js → activity-store-XKNYlFUI.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CZeQo09T.js → agent-avatar-dicebear-1S2TFECE.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-f0-YFMUz.js +1 -0
- package/dist/gateway/static/root/assets/{agents-BlrHMbRx.js → agents-CPqUMtCL.js} +1 -1
- package/dist/gateway/static/root/assets/{api-BKHmTb0w.js → api-BEUEE4f2.js} +1 -1
- package/dist/gateway/static/root/assets/api-CN4id43t.js +1 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-Bzw4fQP8.js → app-management-settings-panel-CgVBSqzu.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-8GZpUXva.js → appearance-settings-CoWdCokb.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-BkQQtIxH.js → apps-page-CexHOcWg.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-CQ2NaoHb.js → archive-plugin-C3ZA6LRS.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-BFi1H7yJ.js → attachment-load-CdgS6_zy.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-CDBXcii_.js → automations-page-BtHL2hpg.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-onJPfmO6.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-D07eWmOx.js → binary-plugins-CiDhtq_H.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-CtVnjyYU.js → block-editor-Br00T83w.js} +3 -3
- package/dist/gateway/static/root/assets/{browser-automation-inputs-BzkJog8e.js → browser-automation-inputs-D2tILykA.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-DyrSbDdG.js → browser-automations-page-BVuEmryB.js} +1 -1
- package/dist/gateway/static/root/assets/browser-settings-page-BgVTyPFY.js +3 -0
- package/dist/gateway/static/root/assets/capabilities-settings-panel-Dra8wj1S.js +8 -0
- package/dist/gateway/static/root/assets/{channels-settings-DAD9qE3J.js → channels-settings-CkxiMDJ4.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-status-swr-B2JwuTjG.js → channels-status-swr-Dtder4G_.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-B62SZdAo.js → chat-terminal-dock-JsMtzDao.js} +1 -1
- package/dist/gateway/static/root/assets/{computer-settings-page-ClSresNq.js → computer-settings-page-DHerePwo.js} +1 -1
- package/dist/gateway/static/root/assets/connector-service-page-DZFNUTiN.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-cl9ZrV4D.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-CTMi_tql.js → cron-expression-DAhdv_Xv.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-B71AJK50.js → date-picker-PacO1m3a.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-DlyGK-kA.js → dependency-picker-B-BcuG1y.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-DGkbTE8_.js → desktop-pet-CdBBhhdY.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BY8r9j66.js → desktop-pet-settings-Gy03NgMI.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-DzRrgd59.js → device-pairing-wizard-aV25nKag.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-L8Mm1n3A.js → extension-debug-page-BFp5eKtY.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-CFc4vSNU.js → extension-page-DL3vyyH6.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-B5zWyHr3.js → extension-settings-page-BXtvdAsY.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-B6wHa6ZI.js → gateway-config-swr-xAOGtenO.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-realtime-B53R0CA4.js → gateway-realtime-BuaTsMSi.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-realtime-store-BG95uGVW.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-settings-D7qmTH4R.js → gateway-settings-Dcr2Ikeh.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DRzGnEV-.js → gateway-startup-retry-BwDxKHd4.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-Glsl3X5b.js → heartbeat-settings-DOy3alvT.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-CDm3dGVy.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-Ck_pyDom.js → image-generation-api-wGMeI_yW.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-ByBX7ome.js → imports-page-zexFT5Rq.js} +1 -1
- package/dist/gateway/static/root/assets/index-D-vczw_0.css +1 -0
- package/dist/gateway/static/root/assets/index-DJo4DimT.js +79 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-C45RlO8a.js → keyboard-shortcuts-settings-CutG9zLh.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-DP0x2jpR.js → local-app-workbench-page-CwLvTwjn.js} +2 -2
- package/dist/gateway/static/root/assets/{local-apps-page-C_AQc2bI.js → local-apps-page-CJy6I7Dt.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-msTfRK8P.js → locale-store-DPZ79W1-.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-DvM8Pyok.js → logs-page-egGcPHNi.js} +1 -1
- package/dist/gateway/static/root/assets/{management-settings-D1uwSutV.js → management-settings-BQhIOELc.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-BInabSKf.js → markdown-view-p2P5hP1U.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-C4mhf13f.js → media-plugins-CsBylqlN.js} +1 -1
- package/dist/gateway/static/root/assets/messages-BiYTyLJr.js +3 -0
- package/dist/gateway/static/root/assets/note-detail-panel-c2k5Uz6X.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-BLQWJMhf.js +8 -0
- package/dist/gateway/static/root/assets/{page-tabs-1go_BtX1.js → page-tabs-ChQ4jJFs.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-DmoSC0j1.js → preview-open-alternatives-9B5W7nVE.js} +1 -1
- package/dist/gateway/static/root/assets/{proactive-page-xAjKTIID.js → proactive-page-iOjI0d_e.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-gmi5LLwM.js → product-open-page-BADxWEdP.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BcxbQn2M.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BuSvld0O.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-BSWtko7U.js → registry-api-B_e_nZSN.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CFS8LQKW.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-ClkOoxDl.js → runtime-tools-settings-panel-D-pwiIyp.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BuEmLiaU.js → schema-form-IWmb05DX.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-DZjc__ok.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-C1SM5B93.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-Dor39QON.js → settings-form-section-B0veRBZs.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-Xj-yvIc8.js → settings-page-CxRWyWYe.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-D9Rl7Tec.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BFWZoXdm.js → share-preview-page-CirpgkfD.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-CwCThBs0.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-DG6VGbOX.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-BdRJ2vnL.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-Ii8qeXhs.js → skills-page.utils-B42mpWKV.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-Di6OSO-0.js → system-settings-panel-DXIZpAvU.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-QXo9LJly.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-1SZ-HFHX.js → theme-store-BFbj_2Tu.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-DDOlOYlj.js → tunnel-api-Db2guRdW.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-CQ8uWNnB.js → use-autosave-DDY9qoXZ.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-CzPmMkaO.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-COTzshjL.js → voice-api-key-field-BZbKQ8HT.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-DgJML_uM.js → voice-config-api-SKCeQLrH.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-_URrXbi4.js → work-discovery-overlay-BRVTTXNG.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-CALs-1nd.js → workflow-run-setup-panel-D2kuwv5e.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-CQXtiYtq.js +6 -0
- package/dist/gateway/static/root/index.html +12 -12
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/notifications.js +1 -1
- package/dist/packages/gateway-contract/src/sessions.js +6 -1
- package/dist/src/agent/agent-manager.js +29 -4
- package/dist/src/agent/background-review/prompts.js +3 -1
- package/dist/src/agent/child-agent-factory.d.ts +1 -0
- package/dist/src/agent/child-agent-factory.js +18 -4
- package/dist/src/agent/coding/repository-instructions.d.ts +4 -0
- package/dist/src/agent/coding/repository-instructions.js +46 -2
- package/dist/src/agent/context/execution-context.js +4 -4
- package/dist/src/agent/data-acquisition/git.d.ts +17 -0
- package/dist/src/agent/data-acquisition/git.js +100 -0
- package/dist/src/agent/data-acquisition/render.d.ts +7 -0
- package/dist/src/agent/data-acquisition/render.js +79 -0
- package/dist/src/agent/data-acquisition/scheduler.d.ts +12 -0
- package/dist/src/agent/data-acquisition/scheduler.js +53 -0
- package/dist/src/agent/data-acquisition/schema.d.ts +75 -0
- package/dist/src/agent/data-acquisition/schema.js +206 -0
- package/dist/src/agent/data-acquisition/service.d.ts +10 -0
- package/dist/src/agent/data-acquisition/service.js +292 -0
- package/dist/src/agent/data-acquisition/types.d.ts +37 -0
- package/dist/src/agent/data-acquisition/types.js +5 -0
- package/dist/src/agent/embedded/run-turn.js +16 -4
- package/dist/src/agent/embedded/session-runner.d.ts +1 -0
- package/dist/src/agent/embedded/session-runner.js +3 -0
- package/dist/src/agent/embedded/tool-result-truncation.js +11 -0
- package/dist/src/agent/embedded/xopc-tools-bridge.js +2 -1
- package/dist/src/agent/external-tools/composio-provider.js +12 -1
- package/dist/src/agent/external-tools/gateway-tools.js +2 -1
- package/dist/src/agent/external-tools/index.js +8 -1
- package/dist/src/agent/external-tools/read-policy.d.ts +6 -0
- package/dist/src/agent/external-tools/read-policy.js +21 -0
- package/dist/src/agent/external-tools/service.d.ts +1 -0
- package/dist/src/agent/external-tools/service.js +4 -1
- package/dist/src/agent/external-tools/types.d.ts +2 -0
- package/dist/src/agent/memory/compaction-promotion.d.ts +1 -1
- package/dist/src/agent/memory/compaction-promotion.js +4 -3
- package/dist/src/agent/orchestration/agent-turn-policy.js +25 -10
- package/dist/src/agent/orchestration/delegation-scope.d.ts +9 -0
- package/dist/src/agent/orchestration/delegation-scope.js +11 -0
- package/dist/src/agent/prompt/sections/tooling.js +3 -1
- package/dist/src/agent/prompt/subagent-context.js +4 -2
- package/dist/src/agent/sandbox/fileAccess.d.ts +2 -0
- package/dist/src/agent/sandbox/fileAccess.js +31 -2
- package/dist/src/agent/tools/dataBatch.d.ts +4 -0
- package/dist/src/agent/tools/dataBatch.js +50 -0
- package/dist/src/agent/tools/delegate-tool.d.ts +6 -3
- package/dist/src/agent/tools/delegate-tool.js +65 -48
- package/dist/src/agent/tools/delegation-parent-policy.d.ts +7 -0
- package/dist/src/agent/tools/delegation-parent-policy.js +41 -0
- package/dist/src/agent/tools/delegation-policy.d.ts +16 -0
- package/dist/src/agent/tools/delegation-policy.js +93 -0
- package/dist/src/agent/tools/factory.d.ts +2 -0
- package/dist/src/agent/tools/factory.js +42 -3
- package/dist/src/agent/tools/fetch-text.d.ts +7 -0
- package/dist/src/agent/tools/fetch-text.js +86 -0
- package/dist/src/agent/tools/find.js +1 -1
- package/dist/src/agent/tools/grep.js +11 -23
- package/dist/src/agent/tools/index.d.ts +1 -0
- package/dist/src/agent/tools/index.js +2 -1
- package/dist/src/agent/tools/knowledge-memory-tool.d.ts +1 -1
- package/dist/src/agent/tools/knowledge-memory-tool.js +13 -5
- package/dist/src/agent/tools/read.js +7 -5
- package/dist/src/agent/tools/repository-search.d.ts +12 -2
- package/dist/src/agent/tools/repository-search.js +127 -74
- package/dist/src/agent/tools/user-context-tool.js +17 -7
- package/dist/src/agent/tools/web.js +19 -28
- package/dist/src/agent/workflow/subagent-runner.js +25 -3
- package/dist/src/agent/workflow/workflow-child-tools.js +13 -8
- package/dist/src/agent-config/schema.d.ts +7 -0
- package/dist/src/agent-config/schema.js +2 -0
- package/dist/src/chat-commands/builtins/understanding.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
- package/dist/src/config/schema.d.ts +6 -4
- package/dist/src/config/schema.js +2 -2
- package/dist/src/connectors/connected-source-understanding.d.ts +1 -0
- package/dist/src/connectors/connected-source-understanding.js +1 -0
- package/dist/src/connectors/learning-coordinator.js +31 -9
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/heartbeat/service.js +2 -2
- package/dist/src/gateway/hono/lib/config-payload.d.ts +4 -2
- package/dist/src/gateway/hono/routes/connectors.js +1 -1
- package/dist/src/gateway/hono/routes/context-sources.js +0 -23
- package/dist/src/gateway/hono/routes/lazy-bundles.js +8 -0
- package/dist/src/gateway/hono/routes/projects.js +8 -0
- package/dist/src/gateway/hono/routes/sessions.js +141 -13
- package/dist/src/gateway/hono/routes/user-model-refresh.d.ts +5 -0
- package/dist/src/gateway/hono/routes/user-model-refresh.js +128 -0
- package/dist/src/gateway/hono/routes/user-model.js +12 -5
- package/dist/src/gateway/hono/routes/work-discovery.js +0 -30
- package/dist/src/gateway/service.js +6 -6
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/infra/update-restart.js +1 -1
- package/dist/src/knowledge/connected-knowledge-pipeline.js +1 -1
- package/dist/src/knowledge-memory/index.js +2 -2
- package/dist/src/knowledge-memory/repository.d.ts +7 -0
- package/dist/src/knowledge-memory/repository.js +58 -8
- package/dist/src/memory-maintenance/service.js +61 -31
- package/dist/src/migrations/memory-config.d.ts +2 -0
- package/dist/src/migrations/memory-config.js +77 -0
- package/dist/src/migrations/runner.js +2 -2
- package/dist/src/notifications/planner.js +5 -5
- package/dist/src/notifications/service.d.ts +2 -2
- package/dist/src/notifications/service.js +1 -1
- package/dist/src/storage/sqlite/index.d.ts +1 -0
- package/dist/src/storage/sqlite/index.js +2 -1
- package/dist/src/storage/sqlite/migrations/184_memory_suppressions.sql +12 -0
- package/dist/src/storage/sqlite/migrations/185_understanding_refresh_batches.sql +6 -0
- package/dist/src/storage/sqlite/migrations/186_sidebar_layout.sql +16 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/sidebar-layout-repository.d.ts +12 -0
- package/dist/src/storage/sqlite/sidebar-layout-repository.js +53 -0
- package/dist/src/user-context/config.d.ts +4 -9
- package/dist/src/user-context/config.js +7 -27
- package/dist/src/user-context/memory-suppression.d.ts +7 -0
- package/dist/src/user-context/memory-suppression.js +23 -0
- package/dist/src/user-context/relationship-continuity.js +1 -1
- package/dist/src/user-context/sources/refresh-service.d.ts +48 -0
- package/dist/src/user-context/sources/refresh-service.js +221 -0
- package/dist/src/user-context/sources/repository.js +1 -1
- package/dist/src/user-model/bootstrap.js +27 -24
- package/dist/src/user-model/capture/executor.d.ts +1 -1
- package/dist/src/user-model/capture/executor.js +17 -11
- package/dist/src/user-model/capture/semantic.js +1 -1
- package/dist/src/user-model/domain.d.ts +6 -2
- package/dist/src/user-model/index.js +3 -3
- package/dist/src/user-model/profile.js +1 -1
- package/dist/src/user-model/repository.d.ts +4 -1
- package/dist/src/user-model/repository.js +96 -6
- package/dist/src/user-model/usage-policy.d.ts +2 -0
- package/dist/src/user-model/usage-policy.js +6 -2
- package/dist/src/work-discovery/project-understanding.js +2 -1
- package/dist/src/work-discovery/service.d.ts +8 -24
- package/dist/src/work-discovery/service.js +138 -180
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BPsRb9Ck.js +0 -1
- package/dist/gateway/static/root/assets/api-DFOlahZv.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-CUpiTTiY.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-CqTxLpil.js +0 -3
- package/dist/gateway/static/root/assets/capabilities-settings-panel-BZ_-pnS6.js +0 -8
- package/dist/gateway/static/root/assets/connector-service-page-CPqVmNvx.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-BUQyg3CW.js +0 -2
- package/dist/gateway/static/root/assets/gateway-realtime-store-BLDgrJ30.js +0 -1
- package/dist/gateway/static/root/assets/home-page-s9hDQ8Hc.js +0 -1
- package/dist/gateway/static/root/assets/index-RBCkv8a_.js +0 -79
- package/dist/gateway/static/root/assets/index-cFU4S35z.css +0 -1
- package/dist/gateway/static/root/assets/messages-F74LVAiU.js +0 -3
- package/dist/gateway/static/root/assets/note-detail-panel-D35sErp2.js +0 -5
- package/dist/gateway/static/root/assets/notes-page-8jCDklDn.js +0 -8
- package/dist/gateway/static/root/assets/project-detail-page-BUMQHy_N.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-DT-Mt7XR.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-Clz3byir.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-tQRwktKm.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DqWg9XS5.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BB_sMB7P.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-oDALm4b6.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-DmwelnfK.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-BE9JXz4U.js +0 -2
- package/dist/gateway/static/root/assets/task-detail-page-D1AWszc7.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-C00i4ea0.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-BUiBjz6m.js +0 -6
- package/dist/src/migrations/knowledge-memory-read-policy-config.d.ts +0 -2
- package/dist/src/migrations/knowledge-memory-read-policy-config.js +0 -48
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { Value } from "@sinclair/typebox/value";
|
|
3
|
+
//#region src/agent/data-acquisition/schema.ts
|
|
4
|
+
const id = Type.String({
|
|
5
|
+
minLength: 1,
|
|
6
|
+
maxLength: 48,
|
|
7
|
+
pattern: "^[a-zA-Z0-9_-]+$"
|
|
8
|
+
});
|
|
9
|
+
const path = Type.String({
|
|
10
|
+
minLength: 1,
|
|
11
|
+
maxLength: 1024
|
|
12
|
+
});
|
|
13
|
+
const DataBatchSchema = Type.Object({ operations: Type.Array(Type.Union([
|
|
14
|
+
Type.Object({
|
|
15
|
+
id,
|
|
16
|
+
kind: Type.Literal("file_read"),
|
|
17
|
+
path,
|
|
18
|
+
startLine: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
19
|
+
maxLines: Type.Optional(Type.Integer({
|
|
20
|
+
minimum: 1,
|
|
21
|
+
maximum: 500
|
|
22
|
+
}))
|
|
23
|
+
}, { additionalProperties: false }),
|
|
24
|
+
Type.Object({
|
|
25
|
+
id,
|
|
26
|
+
kind: Type.Literal("file_search"),
|
|
27
|
+
paths: Type.Array(path, {
|
|
28
|
+
minItems: 1,
|
|
29
|
+
maxItems: 8
|
|
30
|
+
}),
|
|
31
|
+
patterns: Type.Array(Type.String({
|
|
32
|
+
minLength: 1,
|
|
33
|
+
maxLength: 512
|
|
34
|
+
}), {
|
|
35
|
+
minItems: 1,
|
|
36
|
+
maxItems: 8
|
|
37
|
+
}),
|
|
38
|
+
literal: Type.Optional(Type.Boolean()),
|
|
39
|
+
ignoreCase: Type.Optional(Type.Boolean()),
|
|
40
|
+
glob: Type.Optional(Type.String({
|
|
41
|
+
minLength: 1,
|
|
42
|
+
maxLength: 512
|
|
43
|
+
})),
|
|
44
|
+
contextLines: Type.Optional(Type.Integer({
|
|
45
|
+
minimum: 0,
|
|
46
|
+
maximum: 10
|
|
47
|
+
}))
|
|
48
|
+
}, { additionalProperties: false }),
|
|
49
|
+
Type.Object({
|
|
50
|
+
id,
|
|
51
|
+
kind: Type.Literal("git_recent"),
|
|
52
|
+
paths: Type.Optional(Type.Array(path, {
|
|
53
|
+
minItems: 1,
|
|
54
|
+
maxItems: 8
|
|
55
|
+
})),
|
|
56
|
+
since: Type.Optional(Type.String({ pattern: "^\\d{4}-\\d{2}-\\d{2}$" })),
|
|
57
|
+
until: Type.Optional(Type.String({ pattern: "^\\d{4}-\\d{2}-\\d{2}$" }))
|
|
58
|
+
}, { additionalProperties: false }),
|
|
59
|
+
Type.Object({
|
|
60
|
+
id,
|
|
61
|
+
kind: Type.Literal("git_read"),
|
|
62
|
+
path,
|
|
63
|
+
commit: Type.String({ pattern: "^[a-fA-F0-9]{7,64}$" })
|
|
64
|
+
}, { additionalProperties: false }),
|
|
65
|
+
Type.Object({
|
|
66
|
+
id,
|
|
67
|
+
kind: Type.Literal("knowledge_search"),
|
|
68
|
+
query: Type.String({
|
|
69
|
+
minLength: 1,
|
|
70
|
+
maxLength: 1e3
|
|
71
|
+
}),
|
|
72
|
+
maxResults: Type.Optional(Type.Integer({
|
|
73
|
+
minimum: 1,
|
|
74
|
+
maximum: 20
|
|
75
|
+
}))
|
|
76
|
+
}, { additionalProperties: false }),
|
|
77
|
+
Type.Object({
|
|
78
|
+
id,
|
|
79
|
+
kind: Type.Literal("knowledge_get"),
|
|
80
|
+
knowledgeId: Type.String({
|
|
81
|
+
minLength: 1,
|
|
82
|
+
maxLength: 256
|
|
83
|
+
})
|
|
84
|
+
}, { additionalProperties: false }),
|
|
85
|
+
Type.Object({
|
|
86
|
+
id,
|
|
87
|
+
kind: Type.Literal("web_search"),
|
|
88
|
+
query: Type.String({
|
|
89
|
+
minLength: 1,
|
|
90
|
+
maxLength: 1e3
|
|
91
|
+
}),
|
|
92
|
+
count: Type.Optional(Type.Integer({
|
|
93
|
+
minimum: 1,
|
|
94
|
+
maximum: 10
|
|
95
|
+
}))
|
|
96
|
+
}, { additionalProperties: false }),
|
|
97
|
+
Type.Object({
|
|
98
|
+
id,
|
|
99
|
+
kind: Type.Literal("web_fetch"),
|
|
100
|
+
url: Type.String({
|
|
101
|
+
minLength: 1,
|
|
102
|
+
maxLength: 2048
|
|
103
|
+
}),
|
|
104
|
+
maxChars: Type.Optional(Type.Integer({
|
|
105
|
+
minimum: 100,
|
|
106
|
+
maximum: 12e3
|
|
107
|
+
}))
|
|
108
|
+
}, { additionalProperties: false }),
|
|
109
|
+
Type.Object({
|
|
110
|
+
id,
|
|
111
|
+
kind: Type.Literal("external_read"),
|
|
112
|
+
toolRef: Type.String({
|
|
113
|
+
minLength: 1,
|
|
114
|
+
maxLength: 512
|
|
115
|
+
}),
|
|
116
|
+
revision: Type.String({
|
|
117
|
+
minLength: 1,
|
|
118
|
+
maxLength: 128
|
|
119
|
+
}),
|
|
120
|
+
arguments: Type.Record(Type.String(), Type.Unknown())
|
|
121
|
+
}, { additionalProperties: false })
|
|
122
|
+
]), {
|
|
123
|
+
minItems: 1,
|
|
124
|
+
maxItems: 8
|
|
125
|
+
}) }, { additionalProperties: false });
|
|
126
|
+
const DATA_OPERATION_TOOLS = {
|
|
127
|
+
file_read: "read_file",
|
|
128
|
+
file_search: "grep",
|
|
129
|
+
git_recent: "exec_command",
|
|
130
|
+
git_read: "exec_command",
|
|
131
|
+
knowledge_search: "knowledge_search",
|
|
132
|
+
knowledge_get: "knowledge_get",
|
|
133
|
+
web_search: "web_search",
|
|
134
|
+
web_fetch: "web_fetch",
|
|
135
|
+
external_read: "xopc_tool_execute"
|
|
136
|
+
};
|
|
137
|
+
function nativeDataArgs(op) {
|
|
138
|
+
switch (op.kind) {
|
|
139
|
+
case "knowledge_search": return {
|
|
140
|
+
query: op.query,
|
|
141
|
+
maxResults: op.maxResults
|
|
142
|
+
};
|
|
143
|
+
case "knowledge_get": return { id: op.knowledgeId };
|
|
144
|
+
case "web_search": return {
|
|
145
|
+
query: op.query,
|
|
146
|
+
count: op.count
|
|
147
|
+
};
|
|
148
|
+
case "web_fetch": return {
|
|
149
|
+
url: op.url,
|
|
150
|
+
maxChars: op.maxChars ?? 8e3
|
|
151
|
+
};
|
|
152
|
+
case "external_read": return {
|
|
153
|
+
toolRef: op.toolRef,
|
|
154
|
+
revision: op.revision,
|
|
155
|
+
arguments: op.arguments,
|
|
156
|
+
readOnly: true
|
|
157
|
+
};
|
|
158
|
+
default: throw new Error("Not a native data operation");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Expose each underlying access to existing approval, hook and call-limit policies. */
|
|
162
|
+
function dataOperationCalls(args) {
|
|
163
|
+
validateDataBatch(args);
|
|
164
|
+
return args.operations.flatMap((op) => {
|
|
165
|
+
if (op.kind === "file_read") return [{
|
|
166
|
+
name: "read_file",
|
|
167
|
+
args: {
|
|
168
|
+
path: op.path,
|
|
169
|
+
offset: op.startLine,
|
|
170
|
+
limit: op.maxLines
|
|
171
|
+
}
|
|
172
|
+
}];
|
|
173
|
+
if (op.kind === "file_search") return op.paths.flatMap((path) => op.patterns.map((pattern) => ({
|
|
174
|
+
name: "grep",
|
|
175
|
+
args: {
|
|
176
|
+
path,
|
|
177
|
+
pattern,
|
|
178
|
+
literal: op.literal,
|
|
179
|
+
glob: op.glob,
|
|
180
|
+
ignoreCase: op.ignoreCase,
|
|
181
|
+
context: op.contextLines ?? 2
|
|
182
|
+
}
|
|
183
|
+
})));
|
|
184
|
+
if (op.kind === "git_read" || op.kind === "git_recent") return [{
|
|
185
|
+
name: "exec_command",
|
|
186
|
+
args: {
|
|
187
|
+
cmd: op.kind === "git_read" ? `git show ${op.commit} (file read)` : "git log HEAD (recent history)",
|
|
188
|
+
...op
|
|
189
|
+
}
|
|
190
|
+
}, ...op.kind === "git_read" ? [{
|
|
191
|
+
name: "read_file",
|
|
192
|
+
args: { path: op.path }
|
|
193
|
+
}] : []];
|
|
194
|
+
return [{
|
|
195
|
+
name: DATA_OPERATION_TOOLS[op.kind],
|
|
196
|
+
args: nativeDataArgs(op)
|
|
197
|
+
}];
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function validateDataBatch(args) {
|
|
201
|
+
if (!Value.Check(DataBatchSchema, args)) throw new Error("Invalid data_batch parameters");
|
|
202
|
+
if (new Set(args.operations.map((op) => op.id)).size !== args.operations.length) throw new Error("Operation ids must be unique");
|
|
203
|
+
if (Buffer.byteLength(JSON.stringify(args)) > 32e3) throw new Error("Batch input exceeds 32 KB");
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
export { DATA_OPERATION_TOOLS, DataBatchSchema, dataOperationCalls, nativeDataArgs, validateDataBatch };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import { type DataBatchArgs } from './schema.js';
|
|
3
|
+
import type { DataBatchResult } from './types.js';
|
|
4
|
+
/** Each batch owns its read cache; permissions are checked before sharing any data. */
|
|
5
|
+
export interface DataSourceOptions {
|
|
6
|
+
getTools?: () => readonly AgentTool[];
|
|
7
|
+
allowHostGit?: () => boolean;
|
|
8
|
+
canExecute?: (toolName: string) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function acquireData(workspace: string, args: DataBatchArgs, allowed: ReadonlySet<string>, signal?: AbortSignal, options?: DataSourceOptions): Promise<DataBatchResult>;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { executeWithTimeout } from "../lifecycle/timeout-wrapper.js";
|
|
2
|
+
import { checkedFilePath, readWorkspaceFileAsync } from "../sandbox/fileAccess.js";
|
|
3
|
+
import { dataScheduler } from "./scheduler.js";
|
|
4
|
+
import { checkFileSafety } from "../prompt/safety.js";
|
|
5
|
+
import { parseRepositoryMatch, repositorySearch } from "../tools/repository-search.js";
|
|
6
|
+
import { DATA_OPERATION_TOOLS, nativeDataArgs, validateDataBatch } from "./schema.js";
|
|
7
|
+
import { readGitData } from "./git.js";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { stat } from "node:fs/promises";
|
|
11
|
+
//#region src/agent/data-acquisition/service.ts
|
|
12
|
+
async function acquireData(workspace, args, allowed, signal, options = {}) {
|
|
13
|
+
validateDataBatch(args);
|
|
14
|
+
signal?.throwIfAborted();
|
|
15
|
+
const deadline = AbortSignal.any([...signal ? [signal] : [], AbortSignal.timeout(15e3)]);
|
|
16
|
+
const files = /* @__PURE__ */ new Map();
|
|
17
|
+
const result = {
|
|
18
|
+
schemaVersion: 1,
|
|
19
|
+
operations: [],
|
|
20
|
+
fragments: [],
|
|
21
|
+
sourceRequests: 0
|
|
22
|
+
};
|
|
23
|
+
let readBytes = 0;
|
|
24
|
+
const runOperation = async (op) => {
|
|
25
|
+
const started = Date.now();
|
|
26
|
+
const output = {
|
|
27
|
+
id: op.id,
|
|
28
|
+
kind: op.kind,
|
|
29
|
+
status: "ok",
|
|
30
|
+
fragmentIds: [],
|
|
31
|
+
scope: "",
|
|
32
|
+
sourceExhausted: false,
|
|
33
|
+
outputOmitted: false,
|
|
34
|
+
durationMs: 0
|
|
35
|
+
};
|
|
36
|
+
const fragments = [];
|
|
37
|
+
const add = (resource, text, startLine, revision) => {
|
|
38
|
+
fragments.push({
|
|
39
|
+
id: "",
|
|
40
|
+
operationIds: [op.id],
|
|
41
|
+
source: {
|
|
42
|
+
kind: "file",
|
|
43
|
+
resource,
|
|
44
|
+
revision,
|
|
45
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46
|
+
},
|
|
47
|
+
startLine,
|
|
48
|
+
endLine: startLine + text.split("\n").length - 1,
|
|
49
|
+
text
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
deadline.throwIfAborted();
|
|
54
|
+
const toolAllowed = () => allowed.has(DATA_OPERATION_TOOLS[op.kind]) && options.canExecute?.(DATA_OPERATION_TOOLS[op.kind]) !== false;
|
|
55
|
+
if (!toolAllowed()) {
|
|
56
|
+
output.status = "denied";
|
|
57
|
+
output.reason = "Underlying tool is not allowed";
|
|
58
|
+
return {
|
|
59
|
+
output,
|
|
60
|
+
fragments
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const checkPermission = () => {
|
|
64
|
+
if (!toolAllowed() || op.kind === "git_read" && options.canExecute?.("read_file") === false) throw new Error("Sandbox: data access was revoked");
|
|
65
|
+
};
|
|
66
|
+
if (op.kind === "git_read" && !allowed.has("read_file")) {
|
|
67
|
+
output.status = "denied";
|
|
68
|
+
output.reason = "Git object reads require read_file permission";
|
|
69
|
+
return {
|
|
70
|
+
output,
|
|
71
|
+
fragments
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const operationSignal = AbortSignal.any([deadline, AbortSignal.timeout(5e3)]);
|
|
75
|
+
const safePath = (input) => {
|
|
76
|
+
const safety = checkFileSafety("read", input);
|
|
77
|
+
if (!safety.allowed) throw new Error(`Sandbox: ${safety.message}`);
|
|
78
|
+
return checkedFilePath(workspace, resolve(workspace, input), "read");
|
|
79
|
+
};
|
|
80
|
+
if (op.kind === "file_read") {
|
|
81
|
+
const target = safePath(op.path);
|
|
82
|
+
const first = op.startLine ?? 1;
|
|
83
|
+
const count = op.maxLines ?? 120;
|
|
84
|
+
output.scope = `${target}:${first}-${first + count - 1}`;
|
|
85
|
+
let reading = files.get(target);
|
|
86
|
+
if (!reading) {
|
|
87
|
+
reading = dataScheduler.run(workspace, operationSignal, async () => {
|
|
88
|
+
checkPermission();
|
|
89
|
+
const bytes = (await stat(target)).size;
|
|
90
|
+
if (readBytes + bytes > 32 * 1024 * 1024) throw new Error("Batch read byte budget exceeded");
|
|
91
|
+
readBytes += bytes;
|
|
92
|
+
result.sourceRequests++;
|
|
93
|
+
const data = await readWorkspaceFileAsync(workspace, target, operationSignal, Math.min(bytes, 10 * 1024 * 1024));
|
|
94
|
+
if (data.includes(0)) throw new Error("Binary file: use the appropriate media or document tool");
|
|
95
|
+
return {
|
|
96
|
+
lines: data.toString("utf8").split("\n"),
|
|
97
|
+
revision: createHash("sha256").update(data).digest("hex")
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
files.set(target, reading);
|
|
101
|
+
}
|
|
102
|
+
const { lines, revision } = await reading;
|
|
103
|
+
operationSignal.throwIfAborted();
|
|
104
|
+
if (first > lines.length) throw new Error(`Offset ${first} exceeds ${lines.length} lines`);
|
|
105
|
+
const requestedEnd = Math.min(lines.length, first - 1 + count);
|
|
106
|
+
let end = first - 1, bytes = 0;
|
|
107
|
+
while (end < requestedEnd) {
|
|
108
|
+
const size = Buffer.byteLength(lines[end]) + 1;
|
|
109
|
+
if (bytes + size > Math.floor(256 * 1024 / args.operations.length)) break;
|
|
110
|
+
bytes += size;
|
|
111
|
+
end++;
|
|
112
|
+
}
|
|
113
|
+
if (end === first - 1) throw new Error("Line exceeds batch fragment budget; use a targeted search or a format-specific tool");
|
|
114
|
+
output.outputOmitted = end < requestedEnd;
|
|
115
|
+
add(target, lines.slice(first - 1, end).join("\n"), first, revision);
|
|
116
|
+
output.scope = `${target}:${first}-${end}`;
|
|
117
|
+
output.sourceExhausted = end === lines.length;
|
|
118
|
+
if (!output.sourceExhausted) output.next = {
|
|
119
|
+
path: target,
|
|
120
|
+
startLine: end + 1,
|
|
121
|
+
maxLines: count
|
|
122
|
+
};
|
|
123
|
+
} else if (op.kind === "file_search") {
|
|
124
|
+
const paths = op.paths.map(safePath);
|
|
125
|
+
output.scope = JSON.stringify({
|
|
126
|
+
paths,
|
|
127
|
+
patterns: op.patterns,
|
|
128
|
+
glob: op.glob
|
|
129
|
+
}).slice(0, 3e3);
|
|
130
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
131
|
+
let buffered = 0;
|
|
132
|
+
result.sourceRequests++;
|
|
133
|
+
const search = await repositorySearch(workspace, [
|
|
134
|
+
"--json",
|
|
135
|
+
"--line-number",
|
|
136
|
+
"--with-filename",
|
|
137
|
+
"--color",
|
|
138
|
+
"never",
|
|
139
|
+
"--context",
|
|
140
|
+
String(op.contextLines ?? 2),
|
|
141
|
+
...op.literal ? ["--fixed-strings"] : [],
|
|
142
|
+
...op.ignoreCase ? ["--ignore-case"] : [],
|
|
143
|
+
...op.glob ? ["--glob", op.glob] : [],
|
|
144
|
+
...op.patterns.flatMap((pattern) => ["-e", pattern]),
|
|
145
|
+
"--",
|
|
146
|
+
...paths
|
|
147
|
+
], operationSignal, {
|
|
148
|
+
maxBytes: Math.min(1024 * 1024, Math.floor(4 * 1024 * 1024 / args.operations.length)),
|
|
149
|
+
onLine: (line) => {
|
|
150
|
+
const match = parseRepositoryMatch(workspace, line);
|
|
151
|
+
if (!match) return;
|
|
152
|
+
const resource = match.path;
|
|
153
|
+
const text = match.text;
|
|
154
|
+
const bytes = Buffer.byteLength(text);
|
|
155
|
+
if (bytes > 4096 || buffered + bytes > Math.floor(256 * 1024 / args.operations.length)) {
|
|
156
|
+
output.outputOmitted = true;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const group = byFile.get(resource) ?? [];
|
|
160
|
+
const last = group.at(-1);
|
|
161
|
+
if (last && last.endLine === match.line - 1 && Buffer.byteLength(last.text) + bytes < 4096) {
|
|
162
|
+
last.text += `\n${text}`;
|
|
163
|
+
last.endLine = match.line;
|
|
164
|
+
} else if (group.length < 3 && fragments.length < 32) {
|
|
165
|
+
add(resource, text, match.line);
|
|
166
|
+
group.push(fragments.at(-1));
|
|
167
|
+
byFile.set(resource, group);
|
|
168
|
+
} else {
|
|
169
|
+
output.outputOmitted = true;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
buffered += bytes;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
output.sourceExhausted = !search.truncated;
|
|
176
|
+
if (search.truncated) {
|
|
177
|
+
output.status = "partial";
|
|
178
|
+
output.reason = "scan_budget";
|
|
179
|
+
}
|
|
180
|
+
} else if (op.kind === "git_read" || op.kind === "git_recent") {
|
|
181
|
+
if (options.allowHostGit?.() === false) throw new Error("Sandbox: use exec_command for Git in the configured isolated environment");
|
|
182
|
+
const git = await readGitData(workspace, op, operationSignal, () => {
|
|
183
|
+
result.sourceRequests++;
|
|
184
|
+
});
|
|
185
|
+
output.scope = JSON.stringify(op);
|
|
186
|
+
output.sourceExhausted = git.exhausted;
|
|
187
|
+
if (git.reason) {
|
|
188
|
+
output.status = "partial";
|
|
189
|
+
output.reason = git.reason;
|
|
190
|
+
output.outputOmitted = git.reason === "output_budget";
|
|
191
|
+
}
|
|
192
|
+
fragments.push({
|
|
193
|
+
id: "",
|
|
194
|
+
operationIds: [op.id],
|
|
195
|
+
source: {
|
|
196
|
+
kind: "git",
|
|
197
|
+
resource: git.resource,
|
|
198
|
+
revision: git.revision,
|
|
199
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
200
|
+
},
|
|
201
|
+
text: git.text
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
const tool = options.getTools?.().find((tool) => tool.name === DATA_OPERATION_TOOLS[op.kind]);
|
|
205
|
+
if (!tool) throw new Error("Data source tool is unavailable");
|
|
206
|
+
const resource = op.kind === "web_fetch" ? op.url : op.kind === "knowledge_get" ? op.knowledgeId : op.kind === "external_read" ? `${op.toolRef}#account=${encodeURIComponent(String(op.arguments.xopcAccountId ?? ""))}` : op.query;
|
|
207
|
+
output.scope = JSON.stringify({
|
|
208
|
+
kind: op.kind,
|
|
209
|
+
resource
|
|
210
|
+
});
|
|
211
|
+
const resourceKey = op.kind === "external_read" ? `connector:${op.toolRef.split(":").slice(0, 2).join(":")}:${String(op.arguments.xopcAccountId ?? "")}` : op.kind.startsWith("web_") ? `web:${op.kind === "web_fetch" ? new URL(op.url).hostname : "search"}` : workspace;
|
|
212
|
+
const native = await executeWithTimeout(() => dataScheduler.run(resourceKey, operationSignal, async () => {
|
|
213
|
+
checkPermission();
|
|
214
|
+
result.sourceRequests++;
|
|
215
|
+
return tool.execute(op.id, nativeDataArgs(op), operationSignal);
|
|
216
|
+
}), {
|
|
217
|
+
toolName: op.kind,
|
|
218
|
+
signal: operationSignal,
|
|
219
|
+
timeoutMs: 15e3
|
|
220
|
+
});
|
|
221
|
+
operationSignal.throwIfAborted();
|
|
222
|
+
const details = native.details;
|
|
223
|
+
if (details?.error || details?.status === "failed") throw new Error(String(details.error ?? "Data source failed"));
|
|
224
|
+
const text = native.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
|
|
225
|
+
if (text.length > 32e3) output.outputOmitted = true;
|
|
226
|
+
if (details?.truncated) output.outputOmitted = true;
|
|
227
|
+
fragments.push({
|
|
228
|
+
id: "",
|
|
229
|
+
operationIds: [op.id],
|
|
230
|
+
source: {
|
|
231
|
+
kind: op.kind,
|
|
232
|
+
resource,
|
|
233
|
+
revision: op.kind === "external_read" ? op.revision : void 0,
|
|
234
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
235
|
+
},
|
|
236
|
+
text: text.slice(0, 32e3)
|
|
237
|
+
});
|
|
238
|
+
output.sourceExhausted = details?.complete === true;
|
|
239
|
+
}
|
|
240
|
+
checkPermission();
|
|
241
|
+
if (output.outputOmitted) {
|
|
242
|
+
output.status = "partial";
|
|
243
|
+
output.reason ??= "output_budget";
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
output.status = deadline.aborted ? "cancelled" : String(error).includes("Sandbox:") ? "denied" : "error";
|
|
247
|
+
output.reason = (error instanceof Error ? error.message : String(error)).slice(0, 300);
|
|
248
|
+
if (fragments.length && output.status === "error") output.status = "partial";
|
|
249
|
+
if (output.status === "denied" || output.status === "cancelled") fragments.length = 0;
|
|
250
|
+
} finally {
|
|
251
|
+
output.durationMs = Date.now() - started;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
output,
|
|
255
|
+
fragments
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
const operations = new Array(args.operations.length);
|
|
259
|
+
let nextOperation = 0;
|
|
260
|
+
await Promise.all(Array.from({ length: Math.min(4, args.operations.length) }, async () => {
|
|
261
|
+
while (nextOperation < args.operations.length) {
|
|
262
|
+
const index = nextOperation++;
|
|
263
|
+
operations[index] = await runOperation(args.operations[index]);
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
const unique = /* @__PURE__ */ new Map();
|
|
267
|
+
for (const { output, fragments } of operations) {
|
|
268
|
+
for (const fragment of fragments) {
|
|
269
|
+
const key = JSON.stringify([
|
|
270
|
+
fragment.source.kind,
|
|
271
|
+
fragment.source.resource,
|
|
272
|
+
fragment.source.revision,
|
|
273
|
+
fragment.startLine,
|
|
274
|
+
fragment.text
|
|
275
|
+
]);
|
|
276
|
+
const previous = unique.get(key);
|
|
277
|
+
if (previous) {
|
|
278
|
+
previous.operationIds.push(output.id);
|
|
279
|
+
output.fragmentIds.push(previous.id);
|
|
280
|
+
} else {
|
|
281
|
+
fragment.id = `f${unique.size + 1}`;
|
|
282
|
+
unique.set(key, fragment);
|
|
283
|
+
output.fragmentIds.push(fragment.id);
|
|
284
|
+
result.fragments.push(fragment);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
result.operations.push(output);
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
//#endregion
|
|
292
|
+
export { acquireData };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface DataFragment {
|
|
2
|
+
id: string;
|
|
3
|
+
operationIds: string[];
|
|
4
|
+
source: {
|
|
5
|
+
kind: string;
|
|
6
|
+
resource: string;
|
|
7
|
+
revision?: string;
|
|
8
|
+
capturedAt: string;
|
|
9
|
+
};
|
|
10
|
+
startLine?: number;
|
|
11
|
+
endLine?: number;
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
export interface DataOperationResult {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: string;
|
|
17
|
+
status: 'ok' | 'partial' | 'error' | 'denied' | 'cancelled';
|
|
18
|
+
fragmentIds: string[];
|
|
19
|
+
scope: string;
|
|
20
|
+
sourceExhausted: boolean;
|
|
21
|
+
outputOmitted: boolean;
|
|
22
|
+
reason?: string;
|
|
23
|
+
next?: {
|
|
24
|
+
path: string;
|
|
25
|
+
startLine: number;
|
|
26
|
+
maxLines: number;
|
|
27
|
+
};
|
|
28
|
+
durationMs: number;
|
|
29
|
+
}
|
|
30
|
+
export interface DataBatchResult {
|
|
31
|
+
schemaVersion: 1;
|
|
32
|
+
operations: DataOperationResult[];
|
|
33
|
+
fragments: DataFragment[];
|
|
34
|
+
sourceRequests: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const DATA_MAX_CHARS = 12000;
|
|
37
|
+
export declare const DATA_MAX_BYTES: number;
|
|
@@ -2,6 +2,7 @@ import { createLogger } from "../../utils/logger/index.js";
|
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
3
|
import { getClarification, getClarificationResumeInput, isClarificationSuspended } from "../../storage/sqlite/clarification-wait-repository.js";
|
|
4
4
|
import { getConnectionResumeInput, init_connection_wait_repository, isConnectionSuspended } from "../../storage/sqlite/connection-wait-repository.js";
|
|
5
|
+
import { runWithEmbeddedExecutionSession } from "./execution-context.js";
|
|
5
6
|
import { isComputerControlActive, isComputerLeaseTool, stopComputerControl } from "../../computer/control-guard.js";
|
|
6
7
|
import { EmbeddedRunConflictError, abortEmbeddedRun, acquireEmbeddedRunLease, queueEmbeddedSteer } from "./runs.js";
|
|
7
8
|
import { lastAssistantPlainText, subscribeEmbeddedSessionEvents } from "./subscribe-session.js";
|
|
@@ -22,6 +23,7 @@ import { isPromptCacheExpired, recordPromptCacheTouch } from "../../providers/pr
|
|
|
22
23
|
import { markTurnToolResult } from "../memory/turn-provenance.js";
|
|
23
24
|
import { RepositoryInstructions } from "../coding/repository-instructions.js";
|
|
24
25
|
import { RunVerification } from "../coding/run-verification.js";
|
|
26
|
+
import { withDelegationScope } from "../orchestration/delegation-scope.js";
|
|
25
27
|
//#region src/agent/embedded/run-turn.ts
|
|
26
28
|
init_connection_wait_repository();
|
|
27
29
|
init_logger();
|
|
@@ -318,9 +320,16 @@ async function runXopcEmbeddedTurn(params) {
|
|
|
318
320
|
session.agent.afterToolCall = async (context) => {
|
|
319
321
|
connectionStopped ||= isConnectionSuspended(conversationId, runId);
|
|
320
322
|
clarificationStopped ||= isClarificationSuspended(conversationId, runId);
|
|
321
|
-
const scoped = context.toolCall.name === "read_file" ? await instructions.forTool(context.toolCall.name, context.args) : "";
|
|
323
|
+
const scoped = context.toolCall.name === "read_file" ? await instructions.forTool(context.toolCall.name, context.args) : context.toolCall.name === "data_batch" ? await instructions.forDataResult(context.result.content) : "";
|
|
322
324
|
const checked = await verification.afterTool(context);
|
|
323
|
-
if (scoped) checked.result
|
|
325
|
+
if (scoped && context.toolCall.name === "data_batch") checked.result = {
|
|
326
|
+
content: [{
|
|
327
|
+
type: "text",
|
|
328
|
+
text: `${scoped}\n\nNew directory instructions were discovered. Apply them before retrying the affected data queries; this result is not evidence of a complete search.`
|
|
329
|
+
}],
|
|
330
|
+
details: { status: "retry_required" }
|
|
331
|
+
};
|
|
332
|
+
else if (scoped) checked.result.content.unshift({
|
|
324
333
|
type: "text",
|
|
325
334
|
text: scoped
|
|
326
335
|
});
|
|
@@ -347,7 +356,10 @@ async function runXopcEmbeddedTurn(params) {
|
|
|
347
356
|
};
|
|
348
357
|
runAbortSignal.addEventListener("abort", abortListener, { once: true });
|
|
349
358
|
try {
|
|
350
|
-
await runAgentTurnWithTimeout(session.agent,
|
|
359
|
+
await runAgentTurnWithTimeout(session.agent, () => withDelegationScope({
|
|
360
|
+
tools,
|
|
361
|
+
authorizeToolCall: params.turnPolicy ? (context, signal) => runWithEmbeddedExecutionSession(conversationId, () => params.turnPolicy.beforeToolCall(context, signal), runId) : void 0
|
|
362
|
+
}, async () => {
|
|
351
363
|
const connectionResume = getConnectionResumeInput(conversationId, runId);
|
|
352
364
|
const clarificationResume = getClarificationResumeInput(conversationId, runId);
|
|
353
365
|
if (connectionResume) await session.sendCustomMessage({
|
|
@@ -392,7 +404,7 @@ async function runXopcEmbeddedTurn(params) {
|
|
|
392
404
|
}, { triggerTurn: true });
|
|
393
405
|
await session.agent.waitForIdle();
|
|
394
406
|
}
|
|
395
|
-
}, timeoutMs);
|
|
407
|
+
}), timeoutMs);
|
|
396
408
|
if (connectionStopped) runner.piSm.appendCustomEntry("connection_required", {
|
|
397
409
|
runId,
|
|
398
410
|
conversationId
|
|
@@ -23,6 +23,7 @@ function buildEmbeddedRunnerFingerprint(input) {
|
|
|
23
23
|
input.workspaceDir,
|
|
24
24
|
input.modelRef,
|
|
25
25
|
tools,
|
|
26
|
+
[...input.toolContracts].sort().join("\0"),
|
|
26
27
|
input.systemPrompt,
|
|
27
28
|
input.thinkingLevel,
|
|
28
29
|
input.credentialRevision
|
|
@@ -92,6 +93,7 @@ var EmbeddedSessionRunnerPool = class {
|
|
|
92
93
|
workspaceDir: params.workspaceDir,
|
|
93
94
|
modelRef: params.modelRef,
|
|
94
95
|
toolNames: params.tools.map((t) => t.name),
|
|
96
|
+
toolContracts: params.tools.map((tool) => JSON.stringify([tool.name, tool.parameters])),
|
|
95
97
|
systemPrompt: params.systemPrompt,
|
|
96
98
|
thinkingLevel: params.thinkingLevel ?? "medium",
|
|
97
99
|
credentialRevision: providerCredentialRevision(params.model.provider)
|
|
@@ -196,6 +198,7 @@ var EmbeddedSessionRunnerPool = class {
|
|
|
196
198
|
workspaceDir,
|
|
197
199
|
modelRef: params.modelRef,
|
|
198
200
|
toolNames,
|
|
201
|
+
toolContracts: tools.map((tool) => JSON.stringify([tool.name, tool.parameters])),
|
|
199
202
|
systemPrompt,
|
|
200
203
|
thinkingLevel: thinkingLevel ?? "medium",
|
|
201
204
|
credentialRevision: providerCredentialRevision(model.provider)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { init_string_coerce, normalizeLowercaseStringOrEmpty } from "../../utils/string-coerce.js";
|
|
2
|
+
import { isDataBatchResult, renderDataBatch } from "../data-acquisition/render.js";
|
|
2
3
|
import { formatContextLimitTruncationNotice } from "./tool-result-context-guard.js";
|
|
3
4
|
//#region src/agent/embedded/tool-result-truncation.ts
|
|
4
5
|
init_string_coerce();
|
|
@@ -101,6 +102,16 @@ function truncateToolResultMessage(msg, maxChars, options = {}) {
|
|
|
101
102
|
if (!Array.isArray(content)) return msg;
|
|
102
103
|
const totalTextChars = getToolResultTextLength(msg);
|
|
103
104
|
if (totalTextChars <= maxChars) return msg;
|
|
105
|
+
if (msg.toolName === "data_batch" && content.length === 1 && content[0]?.type === "text") try {
|
|
106
|
+
const batch = JSON.parse(content[0].text);
|
|
107
|
+
if (isDataBatchResult(batch)) return {
|
|
108
|
+
...msg,
|
|
109
|
+
content: [{
|
|
110
|
+
type: "text",
|
|
111
|
+
text: renderDataBatch(batch, maxChars).text
|
|
112
|
+
}]
|
|
113
|
+
};
|
|
114
|
+
} catch {}
|
|
104
115
|
const newContent = content.map((block) => {
|
|
105
116
|
if (!block || typeof block !== "object" || block.type !== "text") return block;
|
|
106
117
|
const textBlock = block;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withDataToolPermissions } from "../tools/dataBatch.js";
|
|
1
2
|
//#region src/agent/embedded/xopc-tools-bridge.ts
|
|
2
3
|
const APPLY_PATCH_BEGIN_MARKER = "*** Begin Patch";
|
|
3
4
|
const APPLY_PATCH_END_MARKER = "*** End Patch";
|
|
@@ -106,7 +107,7 @@ function xopcToolsToDefinitions(tools) {
|
|
|
106
107
|
const envelopeError = validateApplyPatchEnvelope(params);
|
|
107
108
|
if (envelopeError) return invalidApplyPatchEnvelopeResult(envelopeError);
|
|
108
109
|
}
|
|
109
|
-
return tool.execute(toolCallId, params, signal, onUpdate);
|
|
110
|
+
return withDataToolPermissions(new Set(tools.map((item) => item.name)), () => tool.execute(toolCallId, params, signal, onUpdate));
|
|
110
111
|
}
|
|
111
112
|
};
|
|
112
113
|
});
|