@allbluecn/web-app 0.28.6 → 0.28.8
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/package.json +6 -4
- package/src/__tests__/integration/harness-p1a-schedule.test.ts +805 -0
- package/src/__tests__/vitest-config.test.ts +30 -0
- package/src/components/command/__tests__/session-search.test.tsx +108 -0
- package/src/components/command/command-palette.tsx +44 -3
- package/src/components/harness/__tests__/resource-uri.test.ts +26 -0
- package/src/components/harness/conversation-panel/composer/command/__tests__/command-server-source.test.tsx +37 -3
- package/src/components/harness/conversation-panel/composer/command/command-suggestion-menu.tsx +3 -1
- package/src/components/harness/conversation-panel/composer/extension/__tests__/command-menu.test.ts +11 -0
- package/src/components/harness/conversation-panel/composer/extension/command-menu.ts +1 -0
- package/src/components/harness/conversation-panel/messages/__tests__/feedback.test.tsx +292 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/__tests__/empty-state.test.tsx +24 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/__tests__/goal-status-bar.test.tsx +134 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/__tests__/harness-transport.test.ts +68 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/__tests__/question-answer-card.test.tsx +135 -1
- package/src/components/harness/conversation-panel/messages/harness-chain/__tests__/use-harness-chat-adapter.test.ts +130 -1
- package/src/components/harness/conversation-panel/messages/harness-chain/goal-status-bar.tsx +55 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/harness-session-appchat.tsx +16 -3
- package/src/components/harness/conversation-panel/messages/harness-chain/harness-transport.ts +63 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/question-answer-card.tsx +115 -36
- package/src/components/harness/conversation-panel/messages/harness-chain/use-goal.ts +19 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/use-harness-chat-adapter.ts +21 -12
- package/src/components/harness/conversation-panel/messages/harness-chain/use-harness-session.ts +23 -2
- package/src/components/harness/conversation-panel/messages/harness-chain/view-message-adapter.tsx +1 -5
- package/src/components/harness/conversation-panel/messages/harness-message.tsx +1 -9
- package/src/components/harness/conversation-panel/messages/message-actions.tsx +100 -5
- package/src/components/harness/conversation-panel/messages/parts-registry.tsx +47 -23
- package/src/components/harness/conversation-panel/messages/tools/__tests__/__screenshots__/deliverable-card.vrt.test.tsx/deliverable-card-dark-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/conversation-panel/messages/tools/__tests__/__screenshots__/deliverable-card.vrt.test.tsx/deliverable-card-light-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/conversation-panel/messages/tools/__tests__/deliverable-card.test.tsx +131 -0
- package/src/components/harness/conversation-panel/messages/tools/__tests__/deliverable-card.vrt.test.tsx +27 -0
- package/src/components/harness/conversation-panel/messages/tools/deliverable-card-view.tsx +47 -0
- package/src/components/harness/conversation-panel/messages/tools/deliverable-card.tsx +17 -0
- package/src/components/harness/conversation-panel/messages/tools/dsh-card-view.tsx +6 -4
- package/src/components/harness/conversation-panel/messages/tools/harness-tool-card.tsx +2 -1
- package/src/components/harness/extension-panel/dock/__tests__/resource-preview-thread-file.test.tsx +42 -1
- package/src/components/harness/extension-panel/dock/dock-surface.tsx +35 -0
- package/src/components/harness/extension-panel/dock/resource-preview.tsx +40 -0
- package/src/components/harness/extension-panel/dock/resource-uri.ts +24 -8
- package/src/components/harness/extension-panel/panels/agents/__tests__/agent-tree.test.tsx +269 -0
- package/src/components/harness/extension-panel/panels/agents/agent-detail.tsx +83 -0
- package/src/components/harness/extension-panel/panels/agents/agent-tree.tsx +299 -0
- package/src/components/harness/extension-panel/panels/agents/kind.tsx +28 -0
- package/src/components/harness/extension-panel/panels/agents/transcript-parts.ts +131 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/__screenshots__/review-panel.vrt.test.tsx/review-panel-empty-dark-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/__screenshots__/review-panel.vrt.test.tsx/review-panel-empty-light-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/__screenshots__/review-panel.vrt.test.tsx/review-panel-list-dark-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/__screenshots__/review-panel.vrt.test.tsx/review-panel-list-light-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/__screenshots__/review-panel.vrt.test.tsx/review-panel-snapshot-dark-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/__screenshots__/review-panel.vrt.test.tsx/review-panel-snapshot-light-baseline-1-chromium-darwin.png +0 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/review-panel.test.tsx +187 -0
- package/src/components/harness/extension-panel/panels/deliverable/__tests__/review-panel.vrt.test.tsx +50 -0
- package/src/components/harness/extension-panel/panels/deliverable/kind.tsx +36 -0
- package/src/components/harness/extension-panel/panels/deliverable/review-panel-view.tsx +103 -0
- package/src/components/harness/extension-panel/panels/deliverable/review-panel.tsx +113 -0
- package/src/components/harness/extension-panel/panels/jobs/__tests__/jobs-panel.test.tsx +222 -0
- package/src/components/harness/extension-panel/panels/jobs/jobs-panel.tsx +82 -0
- package/src/components/harness/extension-panel/panels/jobs/jobs-store.ts +225 -0
- package/src/components/harness/extension-panel/panels/jobs/kind.tsx +29 -0
- package/src/components/harness/extension-panel/panels/mcp/kind.tsx +20 -0
- package/src/components/harness/extension-panel/panels/mcp/mcp-panel.tsx +523 -0
- package/src/components/harness/extension-panel/panels/plugin/__tests__/model-search-settings.test.tsx +86 -0
- package/src/components/harness/extension-panel/panels/plugin/__tests__/plugin-page.test.tsx +8 -0
- package/src/components/harness/extension-panel/panels/plugin/model-search-settings.tsx +51 -0
- package/src/components/harness/extension-panel/panels/plugin/plugin-page.tsx +2 -0
- package/src/components/harness/extension-panel/panels/schedule/__tests__/schedule-panel.test.tsx +216 -0
- package/src/components/harness/extension-panel/panels/schedule/kind.tsx +20 -0
- package/src/components/harness/extension-panel/panels/schedule/schedule-panel.tsx +356 -0
- package/src/components/harness/shared/deliverable-item.tsx +69 -0
- package/src/components/harness/shared/deliverable-view.ts +170 -0
- package/src/components/harness/shared/harness-chat-slots.ts +58 -0
- package/src/components/harness/shared/use-todo-projection.ts +1 -0
- package/src/components/harness/workbench/workbench-connection.tsx +8 -1
- package/src/components/settings/harness/__tests__/settings.test.tsx +291 -0
- package/src/components/settings/harness/preset-picker.tsx +99 -0
- package/src/components/settings/harness/presets.ts +98 -0
- package/src/components/settings/harness/settings-cards.tsx +238 -0
- package/src/components/settings/harness/settings-shell.tsx +196 -0
- package/src/lib/changelog/sdk-versions.ts +4 -4
- package/src/lib/harness/capability-settings.ts +66 -0
- package/src/lib/harness/goal-selector.ts +21 -0
- package/src/lib/harness/jobs-events.ts +36 -0
- package/src/lib/harness/mcp-form.ts +31 -0
- package/src/lib/queries/__tests__/harness-schedule-queries.test.ts +56 -0
- package/src/lib/queries/harness-feedback.ts +17 -0
- package/src/lib/queries/harness-mcp.ts +22 -0
- package/src/lib/queries/harness-schedule.ts +22 -0
- package/src/lib/queries/harness-search.ts +24 -0
- package/src/lib/queries/harness-settings.ts +22 -0
- package/src/lib/queries/harness.ts +76 -1
- package/src/paraglide/README.md +1 -1
- package/src/paraglide/messages/_index.js +214 -0
- package/src/paraglide/messages/capabilities_agents.js +29 -0
- package/src/paraglide/messages/capabilities_coreharness1.js +30 -0
- package/src/paraglide/messages/capabilities_deliverables.js +29 -0
- package/src/paraglide/messages/capabilities_goal.js +29 -0
- package/src/paraglide/messages/capabilities_mcp.js +29 -0
- package/src/paraglide/messages/capabilities_question.js +29 -0
- package/src/paraglide/messages/capabilities_schedule.js +29 -0
- package/src/paraglide/messages/capabilities_team.js +29 -0
- package/src/paraglide/messages/common_command_groupsessionsearch2.js +30 -0
- package/src/paraglide/messages/harness_agents_backtotree2.js +30 -0
- package/src/paraglide/messages/harness_agents_cancel.js +29 -0
- package/src/paraglide/messages/harness_agents_description.js +29 -0
- package/src/paraglide/messages/harness_agents_empty.js +29 -0
- package/src/paraglide/messages/harness_agents_loaderror1.js +30 -0
- package/src/paraglide/messages/harness_agents_loading.js +29 -0
- package/src/paraglide/messages/harness_agents_opentree1.js +30 -0
- package/src/paraglide/messages/harness_agents_readonlytitle2.js +30 -0
- package/src/paraglide/messages/harness_agents_status_cancelled.js +29 -0
- package/src/paraglide/messages/harness_agents_status_completed.js +29 -0
- package/src/paraglide/messages/harness_agents_status_failed.js +29 -0
- package/src/paraglide/messages/harness_agents_status_running.js +29 -0
- package/src/paraglide/messages/harness_agents_status_waiting.js +29 -0
- package/src/paraglide/messages/harness_agents_title.js +29 -0
- package/src/paraglide/messages/harness_agents_transcriptempty1.js +30 -0
- package/src/paraglide/messages/harness_command_goal.js +29 -0
- package/src/paraglide/messages/harness_command_goaldesc1.js +30 -0
- package/src/paraglide/messages/harness_command_goalhint1.js +30 -0
- package/src/paraglide/messages/harness_deliverable_emptydescription1.js +30 -0
- package/src/paraglide/messages/harness_deliverable_emptytitle1.js +30 -0
- package/src/paraglide/messages/harness_deliverable_file.js +29 -0
- package/src/paraglide/messages/harness_deliverable_loaderror1.js +30 -0
- package/src/paraglide/messages/harness_deliverable_loading.js +29 -0
- package/src/paraglide/messages/harness_deliverable_loadmore1.js +30 -0
- package/src/paraglide/messages/harness_deliverable_media.js +29 -0
- package/src/paraglide/messages/harness_deliverable_snapshot.js +29 -0
- package/src/paraglide/messages/harness_deliverable_snapshotdiff1.js +30 -0
- package/src/paraglide/messages/harness_deliverable_title.js +29 -0
- package/src/paraglide/messages/harness_deliverable_url.js +29 -0
- package/src/paraglide/messages/harness_feedback_loadfailed1.js +30 -0
- package/src/paraglide/messages/harness_feedback_savefailed1.js +30 -0
- package/src/paraglide/messages/harness_goal_note.js +29 -0
- package/src/paraglide/messages/harness_goal_resume.js +29 -0
- package/src/paraglide/messages/harness_goal_round.js +29 -0
- package/src/paraglide/messages/harness_goal_status_active.js +29 -0
- package/src/paraglide/messages/harness_goal_status_met.js +29 -0
- package/src/paraglide/messages/harness_goal_status_paused.js +29 -0
- package/src/paraglide/messages/harness_goal_status_stopped.js +29 -0
- package/src/paraglide/messages/harness_goal_title.js +29 -0
- package/src/paraglide/messages/harness_jobs_description.js +29 -0
- package/src/paraglide/messages/harness_jobs_empty_description.js +29 -0
- package/src/paraglide/messages/harness_jobs_empty_title.js +29 -0
- package/src/paraglide/messages/harness_jobs_exit_code.js +29 -0
- package/src/paraglide/messages/harness_jobs_output_empty.js +29 -0
- package/src/paraglide/messages/harness_jobs_status_ended.js +29 -0
- package/src/paraglide/messages/harness_jobs_status_running.js +29 -0
- package/src/paraglide/messages/harness_jobs_title.js +29 -0
- package/src/paraglide/messages/harness_mcp_add.js +29 -0
- package/src/paraglide/messages/harness_mcp_cancel.js +29 -0
- package/src/paraglide/messages/harness_mcp_confirm_delete.js +29 -0
- package/src/paraglide/messages/harness_mcp_create_title.js +29 -0
- package/src/paraglide/messages/harness_mcp_credential_unavailable.js +29 -0
- package/src/paraglide/messages/harness_mcp_delete.js +29 -0
- package/src/paraglide/messages/harness_mcp_delete_description.js +29 -0
- package/src/paraglide/messages/harness_mcp_delete_title.js +29 -0
- package/src/paraglide/messages/harness_mcp_description.js +29 -0
- package/src/paraglide/messages/harness_mcp_disabled.js +29 -0
- package/src/paraglide/messages/harness_mcp_edit.js +29 -0
- package/src/paraglide/messages/harness_mcp_edit_title.js +29 -0
- package/src/paraglide/messages/harness_mcp_empty_description.js +29 -0
- package/src/paraglide/messages/harness_mcp_empty_title.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_args.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_command.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_enabled.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_envnames1.js +30 -0
- package/src/paraglide/messages/harness_mcp_field_name.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_secret.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_transport.js +29 -0
- package/src/paraglide/messages/harness_mcp_field_url.js +29 -0
- package/src/paraglide/messages/harness_mcp_form_description.js +29 -0
- package/src/paraglide/messages/harness_mcp_last_probe.js +29 -0
- package/src/paraglide/messages/harness_mcp_load_failed.js +29 -0
- package/src/paraglide/messages/harness_mcp_loading.js +29 -0
- package/src/paraglide/messages/harness_mcp_never_probed.js +29 -0
- package/src/paraglide/messages/harness_mcp_operation_failed.js +29 -0
- package/src/paraglide/messages/harness_mcp_probe.js +29 -0
- package/src/paraglide/messages/harness_mcp_probe_failed.js +29 -0
- package/src/paraglide/messages/harness_mcp_probe_ok.js +29 -0
- package/src/paraglide/messages/harness_mcp_probe_succeeded.js +29 -0
- package/src/paraglide/messages/harness_mcp_probing.js +29 -0
- package/src/paraglide/messages/harness_mcp_retry.js +29 -0
- package/src/paraglide/messages/harness_mcp_save.js +29 -0
- package/src/paraglide/messages/harness_mcp_secret_hint.js +29 -0
- package/src/paraglide/messages/harness_mcp_stdio_hint.js +29 -0
- package/src/paraglide/messages/harness_mcp_stdio_unavailable.js +29 -0
- package/src/paraglide/messages/harness_mcp_title.js +29 -0
- package/src/paraglide/messages/harness_panel_deliverables.js +29 -0
- package/src/paraglide/messages/harness_panel_plugin_modelsearch_desc1.js +30 -0
- package/src/paraglide/messages/harness_panel_plugin_modelsearch_label1.js +30 -0
- package/src/paraglide/messages/harness_panel_plugin_modelsearch_title1.js +30 -0
- package/src/paraglide/messages/harness_panel_resource_mediaunavailable1.js +30 -0
- package/src/paraglide/messages/harness_panel_resource_openmedia1.js +30 -0
- package/src/paraglide/messages/harness_question_disconnected.js +29 -0
- package/src/paraglide/messages/harness_question_expired.js +29 -0
- package/src/paraglide/messages/harness_question_expiresin1.js +30 -0
- package/src/paraglide/messages/harness_question_skip.js +29 -0
- package/src/paraglide/messages/harness_schedule_confirmdelete1.js +30 -0
- package/src/paraglide/messages/harness_schedule_delete.js +29 -0
- package/src/paraglide/messages/harness_schedule_deletedescription1.js +30 -0
- package/src/paraglide/messages/harness_schedule_deletetitle1.js +30 -0
- package/src/paraglide/messages/harness_schedule_description.js +29 -0
- package/src/paraglide/messages/harness_schedule_edit.js +29 -0
- package/src/paraglide/messages/harness_schedule_editdescription1.js +30 -0
- package/src/paraglide/messages/harness_schedule_edittitle1.js +30 -0
- package/src/paraglide/messages/harness_schedule_emptydescription1.js +30 -0
- package/src/paraglide/messages/harness_schedule_emptytitle1.js +30 -0
- package/src/paraglide/messages/harness_schedule_errortitle1.js +30 -0
- package/src/paraglide/messages/harness_schedule_lasterror1.js +30 -0
- package/src/paraglide/messages/harness_schedule_loadfailed1.js +30 -0
- package/src/paraglide/messages/harness_schedule_loading.js +29 -0
- package/src/paraglide/messages/harness_schedule_nextrun1.js +30 -0
- package/src/paraglide/messages/harness_schedule_nonextrun2.js +30 -0
- package/src/paraglide/messages/harness_schedule_operationfailed1.js +30 -0
- package/src/paraglide/messages/harness_schedule_pause.js +29 -0
- package/src/paraglide/messages/harness_schedule_promptlabel1.js +30 -0
- package/src/paraglide/messages/harness_schedule_resume.js +29 -0
- package/src/paraglide/messages/harness_schedule_save.js +29 -0
- package/src/paraglide/messages/harness_schedule_status_active.js +29 -0
- package/src/paraglide/messages/harness_schedule_status_deleted.js +29 -0
- package/src/paraglide/messages/harness_schedule_status_ended.js +29 -0
- package/src/paraglide/messages/harness_schedule_status_paused.js +29 -0
- package/src/paraglide/messages/harness_schedule_title.js +29 -0
- package/src/paraglide/messages/harness_schedule_titlelabel1.js +30 -0
- package/src/paraglide/messages/settings_harness_bashtimeoutms2.js +30 -0
- package/src/paraglide/messages/settings_harness_bashtimeoutms_description2.js +30 -0
- package/src/paraglide/messages/settings_harness_description.js +29 -0
- package/src/paraglide/messages/settings_harness_general_description.js +29 -0
- package/src/paraglide/messages/settings_harness_general_inheritlanguage1.js +30 -0
- package/src/paraglide/messages/settings_harness_general_inherittheme1.js +30 -0
- package/src/paraglide/messages/settings_harness_general_language.js +29 -0
- package/src/paraglide/messages/settings_harness_general_theme.js +29 -0
- package/src/paraglide/messages/settings_harness_general_title.js +29 -0
- package/src/paraglide/messages/settings_harness_invalidnumber1.js +30 -0
- package/src/paraglide/messages/settings_harness_loadfailed1.js +30 -0
- package/src/paraglide/messages/settings_harness_loadfaileddescription2.js +30 -0
- package/src/paraglide/messages/settings_harness_maxcallsperturn3.js +30 -0
- package/src/paraglide/messages/settings_harness_maxcallsperturn_description3.js +30 -0
- package/src/paraglide/messages/settings_harness_maxconcurrent1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxconcurrent_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxcost1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxcost_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxdepth1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxdepth_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxtokens1.js +30 -0
- package/src/paraglide/messages/settings_harness_maxtokens_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_mode.js +29 -0
- package/src/paraglide/messages/settings_harness_mode_confirmfullaction2.js +30 -0
- package/src/paraglide/messages/settings_harness_mode_confirmfulldescription2.js +30 -0
- package/src/paraglide/messages/settings_harness_mode_confirmfulltitle2.js +30 -0
- package/src/paraglide/messages/settings_harness_mode_description.js +29 -0
- package/src/paraglide/messages/settings_harness_mode_full.js +29 -0
- package/src/paraglide/messages/settings_harness_mode_readonly.js +29 -0
- package/src/paraglide/messages/settings_harness_mode_workspacewrite1.js +30 -0
- package/src/paraglide/messages/settings_harness_model_description.js +29 -0
- package/src/paraglide/messages/settings_harness_model_title.js +29 -0
- package/src/paraglide/messages/settings_harness_modelsearchenabled2.js +30 -0
- package/src/paraglide/messages/settings_harness_modelsearchenabled_description2.js +30 -0
- package/src/paraglide/messages/settings_harness_orchestration_description.js +29 -0
- package/src/paraglide/messages/settings_harness_orchestration_locked.js +29 -0
- package/src/paraglide/messages/settings_harness_orchestration_lockeddescription1.js +30 -0
- package/src/paraglide/messages/settings_harness_orchestration_title.js +29 -0
- package/src/paraglide/messages/settings_harness_preset_applied.js +29 -0
- package/src/paraglide/messages/settings_harness_preset_confirmfullaction2.js +30 -0
- package/src/paraglide/messages/settings_harness_preset_confirmfulldescription2.js +30 -0
- package/src/paraglide/messages/settings_harness_preset_confirmfulltitle2.js +30 -0
- package/src/paraglide/messages/settings_harness_preset_cordis.js +29 -0
- package/src/paraglide/messages/settings_harness_preset_failed.js +29 -0
- package/src/paraglide/messages/settings_harness_preset_minimal.js +29 -0
- package/src/paraglide/messages/settings_harness_preset_ptc.js +29 -0
- package/src/paraglide/messages/settings_harness_preset_ptcunavailable1.js +30 -0
- package/src/paraglide/messages/settings_harness_preset_standard.js +29 -0
- package/src/paraglide/messages/settings_harness_presets_description.js +29 -0
- package/src/paraglide/messages/settings_harness_presets_title.js +29 -0
- package/src/paraglide/messages/settings_harness_readonly1.js +30 -0
- package/src/paraglide/messages/settings_harness_readonlydescription2.js +30 -0
- package/src/paraglide/messages/settings_harness_reasoning.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_description.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_high.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_low.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_max.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_medium.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_minimal.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_off.js +29 -0
- package/src/paraglide/messages/settings_harness_reasoning_xhigh.js +29 -0
- package/src/paraglide/messages/settings_harness_rule_allow.js +29 -0
- package/src/paraglide/messages/settings_harness_rule_ask.js +29 -0
- package/src/paraglide/messages/settings_harness_rule_deny.js +29 -0
- package/src/paraglide/messages/settings_harness_savefailed1.js +30 -0
- package/src/paraglide/messages/settings_harness_section_general.js +29 -0
- package/src/paraglide/messages/settings_harness_section_model.js +29 -0
- package/src/paraglide/messages/settings_harness_section_orchestration.js +29 -0
- package/src/paraglide/messages/settings_harness_section_tools.js +29 -0
- package/src/paraglide/messages/settings_harness_selectthread1.js +30 -0
- package/src/paraglide/messages/settings_harness_selectthreaddescription2.js +30 -0
- package/src/paraglide/messages/settings_harness_selectthreadtitle2.js +30 -0
- package/src/paraglide/messages/settings_harness_stdioenabled1.js +30 -0
- package/src/paraglide/messages/settings_harness_stdioenabled_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_thread.js +29 -0
- package/src/paraglide/messages/settings_harness_title.js +29 -0
- package/src/paraglide/messages/settings_harness_tools_description.js +29 -0
- package/src/paraglide/messages/settings_harness_tools_rules.js +29 -0
- package/src/paraglide/messages/settings_harness_tools_rulesdescription1.js +30 -0
- package/src/paraglide/messages/settings_harness_tools_title.js +29 -0
- package/src/paraglide/messages/settings_harness_untitledthread1.js +30 -0
- package/src/paraglide/messages/settings_tabs_harness.js +29 -0
- package/src/routeTree.gen.ts +121 -21
- package/src/routes/__tests__/route-tree-structure.test.ts +5 -0
- package/src/routes/_nav/harness/$threadId.lazy.tsx +65 -0
- package/src/routes/_nav/harness/$threadId.tsx +4 -0
- package/src/routes/_nav/harness/__tests__/thread-message-anchor.test.tsx +145 -0
- package/src/routes/_nav/settings/-settings-tabs.tsx +2 -1
- package/src/routes/_nav/settings/harness/general.tsx +8 -0
- package/src/routes/_nav/settings/harness/model.tsx +8 -0
- package/src/routes/_nav/settings/harness/orchestration.tsx +8 -0
- package/src/routes/_nav/settings/harness/route.lazy.tsx +72 -0
- package/src/routes/_nav/settings/harness/route.tsx +19 -0
- package/src/routes/_nav/settings/harness/tools.tsx +8 -0
- package/src/routes/api/harness/$.ts +1 -128
- package/src/server/__tests__/chat-conversations.test.ts +16 -0
- package/src/server/harness/__tests__/access-trusted-context.test.ts +19 -9
- package/src/server/harness/__tests__/api-route.test.ts +35 -0
- package/src/server/harness/__tests__/cordis-l1-lazy-factory.test.ts +23 -23
- package/src/server/harness/__tests__/credentials.server.test.ts +5 -1
- package/src/server/harness/__tests__/define-execution-world.test.ts +352 -0
- package/src/server/harness/__tests__/execution-context.test.ts +744 -0
- package/src/server/harness/__tests__/gate.server.test.ts +26 -2
- package/src/server/harness/__tests__/goal.test.ts +442 -0
- package/src/server/harness/__tests__/host-schedule-worker.test.ts +174 -0
- package/src/server/harness/__tests__/permission-mode-sync.test.ts +15 -1
- package/src/server/harness/__tests__/read-path.test.ts +306 -0
- package/src/server/harness/__tests__/session-control.test.ts +404 -0
- package/src/server/harness/__tests__/stream-ticket.test.ts +57 -0
- package/src/server/harness/__tests__/tool-entitlements.test.ts +179 -10
- package/src/server/harness/agents/__tests__/agent-control.test.ts +872 -0
- package/src/server/harness/agents/__tests__/budget.test.ts +68 -0
- package/src/server/harness/agents/__tests__/naming.test.ts +38 -0
- package/src/server/harness/agents/agent-control.plugin.ts +669 -0
- package/src/server/harness/agents/budget.server.ts +109 -0
- package/src/server/harness/agents/naming.server.ts +51 -0
- package/src/server/harness/agents/orchestration-settings.ts +42 -0
- package/src/server/harness/agents/run-view.server.ts +245 -0
- package/src/server/harness/audit/__tests__/audit-middleware.test.ts +263 -0
- package/src/server/harness/audit/audit-middleware.server.ts +139 -0
- package/src/server/harness/audit/dimensions.ts +39 -0
- package/src/server/harness/capabilities/__tests__/__snapshots__/matrix.test.ts.snap +589 -0
- package/src/server/harness/capabilities/__tests__/capability-settings.test.ts +35 -0
- package/src/server/harness/capabilities/__tests__/conformance.test.ts +142 -0
- package/src/server/harness/capabilities/__tests__/matrix.test.ts +28 -0
- package/src/server/harness/capabilities/__tests__/p2-matrix.test.ts +776 -0
- package/src/server/harness/capabilities/__tests__/validate.test.ts +366 -0
- package/src/server/harness/capabilities/availability.ts +117 -0
- package/src/server/harness/capabilities/capability-settings.server.ts +46 -0
- package/src/server/harness/capabilities/manifests/agents.ts +32 -0
- package/src/server/harness/capabilities/manifests/core-harness.ts +42 -0
- package/src/server/harness/capabilities/manifests/deliverables.ts +22 -0
- package/src/server/harness/capabilities/manifests/goal.ts +26 -0
- package/src/server/harness/capabilities/manifests/jobs.ts +39 -0
- package/src/server/harness/capabilities/manifests/legacy-builtin.ts +60 -0
- package/src/server/harness/capabilities/manifests/mcp.ts +45 -0
- package/src/server/harness/capabilities/manifests/question.ts +22 -0
- package/src/server/harness/capabilities/manifests/schedule.ts +28 -0
- package/src/server/harness/capabilities/manifests/session-search.ts +26 -0
- package/src/server/harness/capabilities/manifests/team.ts +28 -0
- package/src/server/harness/capabilities/registry.ts +47 -0
- package/src/server/harness/capabilities/tool-risk-index.ts +40 -0
- package/src/server/harness/capabilities/types.ts +47 -0
- package/src/server/harness/capabilities/validate.ts +96 -0
- package/src/server/harness/cloud-workspace.server.ts +1 -0
- package/src/server/harness/commercial/__tests__/adapters.test.ts +540 -0
- package/src/server/harness/commercial/__tests__/assemble.test.ts +742 -0
- package/src/server/harness/commercial/__tests__/registry.test.ts +114 -0
- package/src/server/harness/commercial/__tests__/session.test.ts +536 -0
- package/src/server/harness/commercial/adapters/audit.server.ts +38 -0
- package/src/server/harness/commercial/adapters/billing.server.ts +17 -0
- package/src/server/harness/commercial/adapters/hosted-ai.server.ts +135 -0
- package/src/server/harness/commercial/adapters/rbac.server.ts +160 -0
- package/src/server/harness/commercial/assemble.server.ts +513 -0
- package/src/server/harness/commercial/contracts.ts +49 -0
- package/src/server/harness/commercial/registry.server.ts +26 -0
- package/src/server/harness/commercial/session.server.ts +206 -0
- package/src/server/harness/cordis-l1.server.ts +11 -18
- package/src/server/harness/credentials.server.ts +149 -43
- package/src/server/harness/define.server.ts +122 -101
- package/src/server/harness/deliverables/__tests__/present.test.ts +412 -0
- package/src/server/harness/deliverables/present.plugin.ts +85 -0
- package/src/server/harness/deliverables/validate.server.ts +261 -0
- package/src/server/harness/deliverables/view.ts +55 -0
- package/src/server/harness/execution-context.server.ts +248 -0
- package/src/server/harness/feedback/__tests__/feedback.test.ts +387 -0
- package/src/server/harness/feedback/feedback.server.ts +82 -0
- package/src/server/harness/gate.server.ts +5 -2
- package/src/server/harness/goal/goal-tools.server.ts +82 -0
- package/src/server/harness/goal/goal.plugin.ts +15 -0
- package/src/server/harness/goal/types.ts +6 -0
- package/src/server/harness/host.server.ts +55 -98
- package/src/server/harness/http/handle-request.server.ts +88 -0
- package/src/server/harness/jobs/__tests__/jobs-events.test.ts +90 -0
- package/src/server/harness/jobs/__tests__/jobs.test.ts +236 -0
- package/src/server/harness/jobs/jobs.plugin.ts +101 -0
- package/src/server/harness/jobs/jobs.server.ts +327 -0
- package/src/server/harness/mcp/__tests__/config.test.ts +218 -0
- package/src/server/harness/mcp/__tests__/plugin.test.ts +210 -0
- package/src/server/harness/mcp/__tests__/probe.test.ts +119 -0
- package/src/server/harness/mcp/mcp-config.server.ts +481 -0
- package/src/server/harness/mcp/mcp-fetch.server.ts +34 -0
- package/src/server/harness/mcp/mcp-probe.server.ts +133 -0
- package/src/server/harness/mcp/mcp.plugin.ts +354 -0
- package/src/server/harness/metadata-store-binding.server.ts +27 -0
- package/src/server/harness/outbox/__tests__/outbox-dispatcher.test.ts +913 -0
- package/src/server/harness/outbox/outbox-dispatcher.server.ts +289 -0
- package/src/server/harness/outbox/outbox-store.server.ts +164 -0
- package/src/server/harness/permission-mode.server.ts +9 -1
- package/src/server/harness/persistence/__tests__/log-store.server.test.ts +120 -0
- package/src/server/harness/persistence/__tests__/session-index-store.server.test.ts +31 -7
- package/src/server/harness/persistence/log-store.server.ts +40 -1
- package/src/server/harness/persistence/prisma-persistence.server.ts +5 -3
- package/src/server/harness/persistence/session-index-store.server.ts +6 -17
- package/src/server/harness/plugins/__tests__/tool-risk-audit.test.ts +26 -6
- package/src/server/harness/plugins/builtin/__tests__/agent-terminal.plugin.test.ts +8 -14
- package/src/server/harness/plugins/builtin/agent-terminal.plugin.ts +9 -8
- package/src/server/harness/providers/__tests__/credential-broker.test.ts +198 -0
- package/src/server/harness/providers/__tests__/supervisor.test.ts +505 -0
- package/src/server/harness/providers/contracts.ts +92 -0
- package/src/server/harness/providers/credential-broker.server.ts +18 -0
- package/src/server/harness/providers/execution-world.server.ts +79 -0
- package/src/server/harness/providers/jobs.server.ts +35 -0
- package/src/server/harness/providers/mcp.server.ts +49 -0
- package/src/server/harness/providers/registry.ts +94 -0
- package/src/server/harness/providers/sandbox-absent.server.ts +22 -0
- package/src/server/harness/providers/scheduler.server.ts +34 -0
- package/src/server/harness/providers/session-search.server.ts +29 -0
- package/src/server/harness/providers/supervisor.server.ts +325 -0
- package/src/server/harness/question/__tests__/ask-question-host.test.ts +211 -0
- package/src/server/harness/question/__tests__/ask-question.test.ts +406 -0
- package/src/server/harness/question/ask-question.plugin.ts +171 -0
- package/src/server/harness/question/expiry.ts +12 -0
- package/src/server/harness/read-path.server.ts +261 -0
- package/src/server/harness/sandbox-policy.server.ts +54 -0
- package/src/server/harness/schedule/__tests__/recurrence-ssr.test.ts +24 -0
- package/src/server/harness/schedule/__tests__/recurrence.test.ts +551 -0
- package/src/server/harness/schedule/__tests__/schedule-dispatcher-cancellation.test.ts +190 -0
- package/src/server/harness/schedule/__tests__/schedule.plugin.test.ts +307 -0
- package/src/server/harness/schedule/__tests__/schedule.service.test.ts +904 -0
- package/src/server/harness/schedule/prompt.ts +7 -0
- package/src/server/harness/schedule/recurrence.ts +810 -0
- package/src/server/harness/schedule/schedule-dispatcher.server.ts +577 -0
- package/src/server/harness/schedule/schedule-materializer.server.ts +266 -0
- package/src/server/harness/schedule/schedule.plugin.ts +363 -0
- package/src/server/harness/schedule/schedule.service.server.ts +484 -0
- package/src/server/harness/schedule/types.ts +8 -0
- package/src/server/harness/search/__tests__/indexer.test.ts +1739 -0
- package/src/server/harness/search/__tests__/lifecycle.test.ts +350 -0
- package/src/server/harness/search/__tests__/search.plugin.test.ts +183 -0
- package/src/server/harness/search/__tests__/search.test.ts +203 -0
- package/src/server/harness/search/__tests__/tokenizer.test.ts +28 -0
- package/src/server/harness/search/search.plugin.ts +241 -0
- package/src/server/harness/search/session-search-indexer.server.ts +1335 -0
- package/src/server/harness/search/session-search-lifecycle.server.ts +105 -0
- package/src/server/harness/search/session-search.service.server.ts +108 -0
- package/src/server/harness/search/thread-map.server.ts +77 -0
- package/src/server/harness/search/tokenizer.ts +18 -0
- package/src/server/harness/session-control.server.ts +175 -0
- package/src/server/harness/settings.server.ts +255 -0
- package/src/server/harness/stream-ticket.server.ts +107 -0
- package/src/server/harness/team/__tests__/store.test.ts +316 -0
- package/src/server/harness/team/__tests__/team.plugin.test.ts +457 -0
- package/src/server/harness/team/__tests__/validate.test.ts +147 -0
- package/src/server/harness/team/availability.server.ts +45 -0
- package/src/server/harness/team/store.server.ts +87 -0
- package/src/server/harness/team/team.plugin.ts +258 -0
- package/src/server/harness/team/types.ts +29 -0
- package/src/server/harness/team/validate.ts +130 -0
- package/src/server/harness/tool-entitlements.server.ts +62 -23
- package/src/server/harness/tool-identity.server.ts +5 -2
- package/src/server/harness/tool-permissions.server.ts +7 -6
- package/src/server/harness/tool-risk.ts +5 -89
- package/src/server/harness/trusted-context.server.ts +22 -5
- package/src/server/harness/worker/__tests__/worker-http.test.ts +205 -0
- package/src/server/harness/worker/__tests__/worker-runtime.test.ts +433 -0
- package/src/server/harness/worker/internal-observe.server.ts +138 -0
- package/src/server/harness/worker/internal-signature.server.ts +20 -0
- package/src/server/harness/worker/worker-health.server.ts +21 -0
- package/src/server/harness/worker/worker-http.server.ts +167 -0
- package/src/server/harness/worker/worker-runtime.server.ts +284 -0
- package/src/server/serverFns/chat/__tests__/conversations-sandbox-default.test.ts +6 -0
- package/src/server/serverFns/chat/conversations.ts +4 -0
- package/src/server/serverFns/harness/__tests__/agents.test.ts +275 -0
- package/src/server/serverFns/harness/__tests__/deliverables.test.ts +203 -0
- package/src/server/serverFns/harness/__tests__/fork-thread.test.ts +14 -1
- package/src/server/serverFns/harness/__tests__/sandbox-policy.test.ts +26 -2
- package/src/server/serverFns/harness/__tests__/settings.test.ts +315 -0
- package/src/server/serverFns/harness/__tests__/team.test.ts +203 -0
- package/src/server/serverFns/harness/agents.ts +116 -0
- package/src/server/serverFns/harness/deliverables.ts +121 -0
- package/src/server/serverFns/harness/feedback.ts +34 -0
- package/src/server/serverFns/harness/fork-thread.ts +2 -0
- package/src/server/serverFns/harness/mcp.ts +84 -0
- package/src/server/serverFns/harness/observe-session.ts +38 -0
- package/src/server/serverFns/harness/sandbox-policy.ts +7 -31
- package/src/server/serverFns/harness/schedule.ts +111 -0
- package/src/server/serverFns/harness/search.ts +50 -0
- package/src/server/serverFns/harness/settings.ts +21 -0
- package/src/server/serverFns/harness/stream-ticket.ts +36 -0
- package/src/server/serverFns/harness/team.ts +68 -0
- package/src/shared/harness/question.ts +6 -0
- package/src/vite-env.d.ts +11 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
|
|
5
|
+
import { definePlugin, type HarnessPlugin } from '@tanstack/ai-harness'
|
|
6
|
+
import { toolDefinition, type AnyTool } from '@tanstack/ai'
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
|
|
9
|
+
import type { AppContext } from '@/server/ai-gateway/types'
|
|
10
|
+
import { BASH_TIMEOUT_SETTING } from '../capabilities/manifests/jobs'
|
|
11
|
+
import { resolveToolIdentity, type TrustedIdentityContext } from '../tool-identity.server'
|
|
12
|
+
import {
|
|
13
|
+
createBashTimeoutNoteMiddleware,
|
|
14
|
+
killCurrentThreadJob,
|
|
15
|
+
listCurrentThreadJobs,
|
|
16
|
+
readCurrentThreadJobOutput,
|
|
17
|
+
type JobsServiceDeps,
|
|
18
|
+
} from './jobs.server'
|
|
19
|
+
|
|
20
|
+
export const jobsToolNames = ['job_list', 'job_output', 'job_kill'] as const
|
|
21
|
+
|
|
22
|
+
const emptyInput = z.object({}).strict()
|
|
23
|
+
const jobIdInput = z.object({ jobId: z.string().min(1).max(200) }).strict()
|
|
24
|
+
const jobSummarySchema = z.object({
|
|
25
|
+
jobId: z.string(),
|
|
26
|
+
threadId: z.string(),
|
|
27
|
+
label: z.string().optional(),
|
|
28
|
+
startedAt: z.number().optional(),
|
|
29
|
+
running: z.boolean(),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
function currentThread(context: TrustedIdentityContext): { userId: string; threadId: string } {
|
|
33
|
+
const userId = resolveToolIdentity(context)
|
|
34
|
+
const threadId = context.run?.threadId
|
|
35
|
+
if (!threadId) throw new Error('缺少当前运行线程上下文')
|
|
36
|
+
return { userId, threadId }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createJobsPlugin(deps: JobsServiceDeps = {}): HarnessPlugin {
|
|
40
|
+
const jobList = toolDefinition({
|
|
41
|
+
name: 'job_list',
|
|
42
|
+
description: '列出当前运行线程的后台作业;不返回子线程或其他用户的作业',
|
|
43
|
+
inputSchema: emptyInput,
|
|
44
|
+
outputSchema: z.object({ jobs: z.array(jobSummarySchema) }),
|
|
45
|
+
}).server<AppContext>(async (_input, ctx) => {
|
|
46
|
+
const { userId, threadId } = currentThread(ctx.context)
|
|
47
|
+
const jobs = await listCurrentThreadJobs(threadId, userId, deps)
|
|
48
|
+
return {
|
|
49
|
+
jobs: jobs.map((job) => ({
|
|
50
|
+
jobId: job.jobId,
|
|
51
|
+
threadId: job.threadId,
|
|
52
|
+
...(job.label !== undefined ? { label: job.label } : {}),
|
|
53
|
+
...(job.startedAt !== undefined ? { startedAt: job.startedAt } : {}),
|
|
54
|
+
running: job.running,
|
|
55
|
+
})),
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const jobOutput = toolDefinition({
|
|
60
|
+
name: 'job_output',
|
|
61
|
+
description: '读取当前线程指定作业的官方 JobOutput 事件,单次最多返回 64 KiB',
|
|
62
|
+
inputSchema: jobIdInput,
|
|
63
|
+
outputSchema: z.object({
|
|
64
|
+
jobId: z.string(),
|
|
65
|
+
output: z.string(),
|
|
66
|
+
truncated: z.boolean(),
|
|
67
|
+
}),
|
|
68
|
+
}).server<AppContext>(async ({ jobId }, ctx) => {
|
|
69
|
+
const { userId, threadId } = currentThread(ctx.context)
|
|
70
|
+
return readCurrentThreadJobOutput(threadId, userId, jobId, deps)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const jobKill = toolDefinition({
|
|
74
|
+
name: 'job_kill',
|
|
75
|
+
description: '终止当前线程指定后台作业;执行世界不支持 killJob 时返回 CAPABILITY_ABSENT',
|
|
76
|
+
inputSchema: jobIdInput,
|
|
77
|
+
outputSchema: z.object({ jobId: z.string(), killed: z.boolean() }),
|
|
78
|
+
}).server<AppContext>(async ({ jobId }, ctx) => {
|
|
79
|
+
const { userId, threadId } = currentThread(ctx.context)
|
|
80
|
+
return killCurrentThreadJob(threadId, userId, jobId, deps)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const tools: AnyTool[] = [jobList, jobOutput, jobKill]
|
|
84
|
+
return definePlugin({
|
|
85
|
+
name: 'allblue/jobs',
|
|
86
|
+
description: '当前线程后台作业列表、官方输出读取与终止',
|
|
87
|
+
lifetime: 'session',
|
|
88
|
+
setup: (context) => ({
|
|
89
|
+
tools,
|
|
90
|
+
config: {
|
|
91
|
+
bashTimeoutMs: {
|
|
92
|
+
type: BASH_TIMEOUT_SETTING.type,
|
|
93
|
+
default: BASH_TIMEOUT_SETTING.default,
|
|
94
|
+
...(BASH_TIMEOUT_SETTING.min !== undefined ? { min: BASH_TIMEOUT_SETTING.min } : {}),
|
|
95
|
+
...(BASH_TIMEOUT_SETTING.max !== undefined ? { max: BASH_TIMEOUT_SETTING.max } : {}),
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
middleware: [createBashTimeoutNoteMiddleware(() => context.config.get('bashTimeoutMs'))],
|
|
99
|
+
}),
|
|
100
|
+
})
|
|
101
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
|
|
5
|
+
import { chmod, mkdir } from 'node:fs/promises'
|
|
6
|
+
import { tmpdir } from 'node:os'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import type { AnyChatMiddleware, AnyTool, ToolExecutionContext } from '@tanstack/ai'
|
|
9
|
+
import type {
|
|
10
|
+
HarnessPlugin,
|
|
11
|
+
JobInfo,
|
|
12
|
+
PluginContributions,
|
|
13
|
+
PluginSetupContext,
|
|
14
|
+
SessionEvent,
|
|
15
|
+
} from '@tanstack/ai-harness'
|
|
16
|
+
import {
|
|
17
|
+
JobEnded,
|
|
18
|
+
JobOutput,
|
|
19
|
+
JobStarted,
|
|
20
|
+
workspaceTools,
|
|
21
|
+
type WorkspaceToolsOptions,
|
|
22
|
+
} from '@tanstack/ai-harness/plugins/coding'
|
|
23
|
+
import { boundToolOutput } from '@tanstack/ai-harness/plugins/node'
|
|
24
|
+
|
|
25
|
+
import { DEFAULT_BASH_TIMEOUT_MS } from '../capabilities/manifests/jobs'
|
|
26
|
+
import {
|
|
27
|
+
readOfficialJobEvent,
|
|
28
|
+
type OfficialJobEvent,
|
|
29
|
+
} from '@/lib/harness/jobs-events'
|
|
30
|
+
import { getProviderSupervisor } from '../providers/supervisor.server'
|
|
31
|
+
import { rememberExecutionWorldJob } from '../providers/execution-world.server'
|
|
32
|
+
import { ProviderError, type HarnessProvider } from '../providers/contracts'
|
|
33
|
+
import { requireOwnedThread } from '../require-owned-thread.server'
|
|
34
|
+
|
|
35
|
+
export const JOB_OUTPUT_MAX_BYTES = 64 * 1024
|
|
36
|
+
export const HARNESS_MAX_JOBS = 8
|
|
37
|
+
|
|
38
|
+
export interface JobsObserve {
|
|
39
|
+
snapshot: () => Promise<{ cursor: string }>
|
|
40
|
+
jobs: () => Promise<Array<JobInfo>>
|
|
41
|
+
events: (options: { from?: string; signal?: AbortSignal }) => AsyncIterable<SessionEvent>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface JobsServiceDeps {
|
|
45
|
+
observe?: (threadId: string, userId: string) => Promise<JobsObserve>
|
|
46
|
+
requireOwned?: typeof requireOwnedThread
|
|
47
|
+
getExecutionWorld?: () => HarnessProvider | null | undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function spillRoot(): string {
|
|
52
|
+
return process.env.DESKTOP_USER_DATA_DIR
|
|
53
|
+
? join(process.env.DESKTOP_USER_DATA_DIR, 'harness-spill')
|
|
54
|
+
: join(tmpdir(), 'allblue-harness-spill')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function harnessSpillDirForThread(threadId: string): string {
|
|
58
|
+
if (!threadId || threadId === '.' || threadId === '..') {
|
|
59
|
+
throw new Error('Invalid harness spill thread id')
|
|
60
|
+
}
|
|
61
|
+
return join(spillRoot(), encodeURIComponent(threadId))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function resolveHarnessSpillDir(threadId: string): Promise<string> {
|
|
65
|
+
const root = spillRoot()
|
|
66
|
+
const dir = harnessSpillDirForThread(threadId)
|
|
67
|
+
await mkdir(root, { recursive: true, mode: 0o700 })
|
|
68
|
+
await mkdir(dir, { recursive: true, mode: 0o700 })
|
|
69
|
+
await chmod(root, 0o700)
|
|
70
|
+
await chmod(dir, 0o700)
|
|
71
|
+
return dir
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function harnessWorkspaceToolOptions(threadId: string): {
|
|
75
|
+
spillDir: string
|
|
76
|
+
maxJobs: number
|
|
77
|
+
bashTimeoutMs: number
|
|
78
|
+
} {
|
|
79
|
+
return {
|
|
80
|
+
spillDir: harnessSpillDirForThread(threadId),
|
|
81
|
+
maxJobs: HARNESS_MAX_JOBS,
|
|
82
|
+
bashTimeoutMs: DEFAULT_BASH_TIMEOUT_MS,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function boundToolOutputOptionsForThread(threadId: string): {
|
|
87
|
+
dir: string
|
|
88
|
+
retentionDays: number
|
|
89
|
+
} {
|
|
90
|
+
return { dir: harnessSpillDirForThread(threadId), retentionDays: 7 }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function commandOf(args: unknown): string {
|
|
94
|
+
if (args && typeof args === 'object' && 'command' in args) {
|
|
95
|
+
const command = (args as { command?: unknown }).command
|
|
96
|
+
if (typeof command === 'string') return command
|
|
97
|
+
}
|
|
98
|
+
return 'bash'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function exitCodeOf(result: unknown): number {
|
|
102
|
+
if (typeof result !== 'string') return 0
|
|
103
|
+
const match = /exit code:\s*(-?\d+)/.exec(result)
|
|
104
|
+
return match ? Number(match[1]) : 0
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Delegate to the official workspaceTools plugin with a per-session spill
|
|
109
|
+
* folder. The official 0.4 API accepts a static spillDir, so the plugin is
|
|
110
|
+
* instantiated inside session setup where threadId is known.
|
|
111
|
+
*/
|
|
112
|
+
export function createThreadScopedWorkspaceTools(
|
|
113
|
+
options: WorkspaceToolsOptions,
|
|
114
|
+
): HarnessPlugin {
|
|
115
|
+
const template = workspaceTools({ ...options, spillDir: '' })
|
|
116
|
+
return {
|
|
117
|
+
...template,
|
|
118
|
+
setup: async (context: PluginSetupContext) => {
|
|
119
|
+
const spillDir = await resolveHarnessSpillDir(context.session.threadId)
|
|
120
|
+
const plugin = workspaceTools({
|
|
121
|
+
...options,
|
|
122
|
+
...harnessWorkspaceToolOptions(context.session.threadId),
|
|
123
|
+
spillDir,
|
|
124
|
+
})
|
|
125
|
+
const setup = plugin.setup as (
|
|
126
|
+
context: PluginSetupContext,
|
|
127
|
+
) => Promise<PluginContributions>
|
|
128
|
+
const contributions = await setup(context)
|
|
129
|
+
const tools = contributions.tools?.map((tool) =>
|
|
130
|
+
wrapBashJobEvents(tool, context),
|
|
131
|
+
)
|
|
132
|
+
return { ...contributions, ...(tools ? { tools } : {}) }
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Add official Job* events to a foreground bash call only after it is moved. */
|
|
138
|
+
export function wrapBashJobEvents(tool: AnyTool, context: PluginSetupContext): AnyTool {
|
|
139
|
+
if (tool.name !== 'bash' || !tool.execute) return tool
|
|
140
|
+
const execute = tool.execute
|
|
141
|
+
return {
|
|
142
|
+
...tool,
|
|
143
|
+
execute: async (args: unknown, executionContext?: ToolExecutionContext) => {
|
|
144
|
+
const detach = executionContext?.detach
|
|
145
|
+
const jobId = executionContext?.toolCallId
|
|
146
|
+
const configuredTimeout = context.config?.get?.('bashTimeoutMs')
|
|
147
|
+
const effectiveArgs = args && typeof args === 'object' && !Array.isArray(args)
|
|
148
|
+
&& !('timeoutMs' in args)
|
|
149
|
+
&& typeof configuredTimeout === 'number'
|
|
150
|
+
&& configuredTimeout > 0
|
|
151
|
+
? { ...args, timeoutMs: configuredTimeout }
|
|
152
|
+
: args
|
|
153
|
+
if (!detach || !jobId) return execute(effectiveArgs, executionContext)
|
|
154
|
+
const wrappedContext: ToolExecutionContext = {
|
|
155
|
+
...executionContext,
|
|
156
|
+
detach: (work: Promise<unknown>) => {
|
|
157
|
+
const moved = detach(work)
|
|
158
|
+
void moved.then(() => {
|
|
159
|
+
context.emit(JobStarted, { jobId, command: commandOf(args) })
|
|
160
|
+
void work.then(
|
|
161
|
+
(result) => {
|
|
162
|
+
const output = typeof result === 'string' ? result : JSON.stringify(result)
|
|
163
|
+
if (output) context.emit(JobOutput, { jobId, output })
|
|
164
|
+
context.emit(JobEnded, { jobId, exitCode: exitCodeOf(result) })
|
|
165
|
+
},
|
|
166
|
+
() => context.emit(JobEnded, { jobId, exitCode: 1 }),
|
|
167
|
+
)
|
|
168
|
+
}).catch(() => undefined)
|
|
169
|
+
return moved
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
return execute(effectiveArgs, wrappedContext)
|
|
173
|
+
},
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Delegate to official boundToolOutput with the same per-thread spill folder. */
|
|
178
|
+
export function createThreadScopedBoundToolOutput(): HarnessPlugin {
|
|
179
|
+
const template = boundToolOutput({ retentionDays: 7 })
|
|
180
|
+
return {
|
|
181
|
+
...template,
|
|
182
|
+
setup: async (context: PluginSetupContext) => {
|
|
183
|
+
const { dir, retentionDays } = boundToolOutputOptionsForThread(context.session.threadId)
|
|
184
|
+
await resolveHarnessSpillDir(context.session.threadId)
|
|
185
|
+
const plugin = boundToolOutput({ dir, retentionDays })
|
|
186
|
+
const contributions = await plugin.setup?.()
|
|
187
|
+
return contributions ?? {}
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Turn exit code 124 into a readable hard-timeout note without detaching it. */
|
|
193
|
+
export function createBashTimeoutNoteMiddleware(getConfiguredTimeout?: () => unknown): AnyChatMiddleware {
|
|
194
|
+
const timeouts = new Map<string, number>()
|
|
195
|
+
return {
|
|
196
|
+
name: 'allblue:bash-timeout-note',
|
|
197
|
+
onBeforeToolCall(_context, call) {
|
|
198
|
+
if (call.toolName !== 'bash' || !call.toolCallId) return
|
|
199
|
+
const requested = call.args && typeof call.args === 'object' && 'timeoutMs' in call.args
|
|
200
|
+
? (call.args as { timeoutMs?: unknown }).timeoutMs
|
|
201
|
+
: undefined
|
|
202
|
+
const configured = getConfiguredTimeout?.()
|
|
203
|
+
const fallback = typeof configured === 'number' && configured > 0 ? configured : DEFAULT_BASH_TIMEOUT_MS
|
|
204
|
+
const timeout = typeof requested === 'number' && requested > 0
|
|
205
|
+
? Math.min(requested, 600_000)
|
|
206
|
+
: fallback
|
|
207
|
+
timeouts.set(call.toolCallId, timeout)
|
|
208
|
+
},
|
|
209
|
+
onAfterToolCall(_context, info) {
|
|
210
|
+
const timeout = timeouts.get(info.toolCallId)
|
|
211
|
+
timeouts.delete(info.toolCallId)
|
|
212
|
+
if (
|
|
213
|
+
info.toolName !== 'bash'
|
|
214
|
+
|| !info.ok
|
|
215
|
+
|| typeof info.result !== 'string'
|
|
216
|
+
|| !/^exit code:\s*124(?:\n|$)/m.test(info.result)
|
|
217
|
+
|| timeout === undefined
|
|
218
|
+
|| info.duration < Math.max(0, timeout - 250)
|
|
219
|
+
) {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
type: 'replaceResult',
|
|
224
|
+
result: `${info.result}\n[Command timed out after ${timeout} ms. The process was terminated and was not moved to the background.]`,
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function defaultObserve(threadId: string, userId: string): Promise<JobsObserve> {
|
|
231
|
+
const { getHarnessRuntime } = await import('../host.server')
|
|
232
|
+
const { host, harness } = await getHarnessRuntime()
|
|
233
|
+
return host.observe(harness, { threadId, user: { id: userId } })
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
async function readThreadEvents(
|
|
238
|
+
observe: JobsObserve,
|
|
239
|
+
threadId: string,
|
|
240
|
+
): Promise<SessionEvent[]> {
|
|
241
|
+
const snapshot = await observe.snapshot()
|
|
242
|
+
const head = Number(snapshot.cursor)
|
|
243
|
+
if (!Number.isFinite(head) || head <= 0) return []
|
|
244
|
+
const events: SessionEvent[] = []
|
|
245
|
+
for await (const entry of observe.events({ from: '0' })) {
|
|
246
|
+
if (entry.threadId !== threadId) continue
|
|
247
|
+
events.push(entry)
|
|
248
|
+
if (Number(entry.cursor) >= head) break
|
|
249
|
+
}
|
|
250
|
+
return events
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export async function listCurrentThreadJobs(
|
|
254
|
+
threadId: string,
|
|
255
|
+
userId: string,
|
|
256
|
+
deps: JobsServiceDeps = {},
|
|
257
|
+
): Promise<JobInfo[]> {
|
|
258
|
+
const owned = deps.requireOwned ?? requireOwnedThread
|
|
259
|
+
const observe = deps.observe ?? defaultObserve
|
|
260
|
+
await owned(threadId, userId)
|
|
261
|
+
const view = await observe(threadId, userId)
|
|
262
|
+
const jobs = (await view.jobs()).filter((job) => job.threadId === threadId)
|
|
263
|
+
for (const job of jobs) {
|
|
264
|
+
if (job.backendId) rememberExecutionWorldJob(threadId, job.jobId, job.backendId)
|
|
265
|
+
}
|
|
266
|
+
return jobs
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function truncateJobOutput(output: string): { output: string; truncated: boolean } {
|
|
270
|
+
const bytes = Buffer.from(output, 'utf8')
|
|
271
|
+
if (bytes.length <= JOB_OUTPUT_MAX_BYTES) return { output, truncated: false }
|
|
272
|
+
const note = '[Output cut to the newest 65536 bytes.]\n'
|
|
273
|
+
const available = JOB_OUTPUT_MAX_BYTES - Buffer.byteLength(note, 'utf8')
|
|
274
|
+
let start = Math.max(0, bytes.length - available)
|
|
275
|
+
while (start < bytes.length && (bytes[start]! & 0xc0) === 0x80) start += 1
|
|
276
|
+
return { output: note + bytes.subarray(start).toString('utf8'), truncated: true }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export async function readCurrentThreadJobOutput(
|
|
280
|
+
threadId: string,
|
|
281
|
+
userId: string,
|
|
282
|
+
jobId: string,
|
|
283
|
+
deps: JobsServiceDeps = {},
|
|
284
|
+
): Promise<{ jobId: string; output: string; truncated: boolean }> {
|
|
285
|
+
const owned = deps.requireOwned ?? requireOwnedThread
|
|
286
|
+
const observe = deps.observe ?? defaultObserve
|
|
287
|
+
await owned(threadId, userId)
|
|
288
|
+
const view = await observe(threadId, userId)
|
|
289
|
+
const events = await readThreadEvents(view, threadId)
|
|
290
|
+
let seen = false
|
|
291
|
+
const chunks: string[] = []
|
|
292
|
+
for (const entry of events) {
|
|
293
|
+
const event: OfficialJobEvent | null = readOfficialJobEvent(entry.event)
|
|
294
|
+
if (!event || event.jobId !== jobId) continue
|
|
295
|
+
seen = true
|
|
296
|
+
if (event.kind === 'output') chunks.push(event.output)
|
|
297
|
+
}
|
|
298
|
+
if (!seen) throw new Error('Job not found')
|
|
299
|
+
const bounded = truncateJobOutput(chunks.join(''))
|
|
300
|
+
return { jobId, ...bounded }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export async function killCurrentThreadJob(
|
|
304
|
+
threadId: string,
|
|
305
|
+
userId: string,
|
|
306
|
+
jobId: string,
|
|
307
|
+
deps: JobsServiceDeps = {},
|
|
308
|
+
): Promise<{ jobId: string; killed: boolean }> {
|
|
309
|
+
const jobs = await listCurrentThreadJobs(threadId, userId, deps)
|
|
310
|
+
const job = jobs.find((candidate) => candidate.jobId === jobId)
|
|
311
|
+
if (!job) throw new Error('Job not found')
|
|
312
|
+
if (!job.backendId) {
|
|
313
|
+
throw new ProviderError('CAPABILITY_ABSENT', '当前作业没有可终止的后端进程。', {
|
|
314
|
+
providerId: 'executionWorld',
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
const provider = deps.getExecutionWorld
|
|
318
|
+
? deps.getExecutionWorld()
|
|
319
|
+
: getProviderSupervisor().get('executionWorld')
|
|
320
|
+
if (!provider || provider.available === false || !provider.killJob) {
|
|
321
|
+
throw new ProviderError('CAPABILITY_ABSENT', '当前执行世界不支持终止作业。', {
|
|
322
|
+
providerId: 'executionWorld',
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
const killed = await provider.killJob(threadId, jobId)
|
|
326
|
+
return { jobId, killed }
|
|
327
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
McpConfigError,
|
|
9
|
+
assertSafeHeaders,
|
|
10
|
+
assertTransportAllowed,
|
|
11
|
+
createMcpServer,
|
|
12
|
+
deleteMcpServer,
|
|
13
|
+
isStdioMcpAllowed,
|
|
14
|
+
loadRuntimeMcpServers,
|
|
15
|
+
updateMcpServer,
|
|
16
|
+
type McpServerRow,
|
|
17
|
+
type McpServerInput,
|
|
18
|
+
type McpStore,
|
|
19
|
+
} from '../mcp-config.server'
|
|
20
|
+
|
|
21
|
+
type StoredRow = McpServerRow & { userId: string }
|
|
22
|
+
|
|
23
|
+
interface MemoryStore extends McpStore {
|
|
24
|
+
rows: Map<string, StoredRow>
|
|
25
|
+
secrets: Map<string, string>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function memoryStore(): MemoryStore {
|
|
29
|
+
const rows = new Map<string, StoredRow>()
|
|
30
|
+
const secrets = new Map<string, string>()
|
|
31
|
+
let seq = 0
|
|
32
|
+
return {
|
|
33
|
+
rows,
|
|
34
|
+
secrets,
|
|
35
|
+
async list(userId) {
|
|
36
|
+
return [...rows.values()].filter((row) => row.userId === userId)
|
|
37
|
+
},
|
|
38
|
+
async find(userId, id) {
|
|
39
|
+
const row = rows.get(id)
|
|
40
|
+
return row && row.userId === userId ? row : null
|
|
41
|
+
},
|
|
42
|
+
async create(userId, input, credentialId) {
|
|
43
|
+
for (const row of rows.values()) {
|
|
44
|
+
if (row.userId === userId && row.name === input.name) {
|
|
45
|
+
throw new McpConfigError('mcp_duplicate_name', 'name already exists')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const row: StoredRow = {
|
|
49
|
+
id: `srv-${++seq}`,
|
|
50
|
+
userId,
|
|
51
|
+
name: input.name,
|
|
52
|
+
transport: input.transport,
|
|
53
|
+
url: input.url ?? null,
|
|
54
|
+
command: input.command ?? null,
|
|
55
|
+
args: input.args ?? null,
|
|
56
|
+
headers: input.headers ?? null,
|
|
57
|
+
envNames: input.envNames ?? null,
|
|
58
|
+
credentialId,
|
|
59
|
+
enabled: input.enabled ?? true,
|
|
60
|
+
lastProbeAt: null,
|
|
61
|
+
lastProbeOk: null,
|
|
62
|
+
lastProbeError: null,
|
|
63
|
+
}
|
|
64
|
+
rows.set(row.id, row)
|
|
65
|
+
return row
|
|
66
|
+
},
|
|
67
|
+
async update(userId, id, input, credentialId) {
|
|
68
|
+
const row = rows.get(id)
|
|
69
|
+
if (!row) throw new McpConfigError('mcp_not_found', 'not found')
|
|
70
|
+
const next: StoredRow = {
|
|
71
|
+
...row,
|
|
72
|
+
name: input.name,
|
|
73
|
+
transport: input.transport,
|
|
74
|
+
url: input.url ?? null,
|
|
75
|
+
command: input.command ?? null,
|
|
76
|
+
args: input.args ?? null,
|
|
77
|
+
headers: input.headers ?? null,
|
|
78
|
+
envNames: input.envNames ?? null,
|
|
79
|
+
credentialId: credentialId ?? null,
|
|
80
|
+
enabled: input.enabled ?? row.enabled,
|
|
81
|
+
}
|
|
82
|
+
rows.set(id, next)
|
|
83
|
+
return next
|
|
84
|
+
},
|
|
85
|
+
async remove(userId, id) {
|
|
86
|
+
const row = rows.get(id)
|
|
87
|
+
if (!row) throw new McpConfigError('mcp_not_found', 'not found')
|
|
88
|
+
rows.delete(id)
|
|
89
|
+
secrets.delete(`${userId}:${row.name}`)
|
|
90
|
+
},
|
|
91
|
+
async readSecret(userId, name) {
|
|
92
|
+
return secrets.get(`${userId}:${name}`) ?? null
|
|
93
|
+
},
|
|
94
|
+
async writeSecret(userId, name, secret) {
|
|
95
|
+
secrets.set(`${userId}:${name}`, secret)
|
|
96
|
+
},
|
|
97
|
+
async deleteSecret(userId, name) {
|
|
98
|
+
secrets.delete(`${userId}:${name}`)
|
|
99
|
+
},
|
|
100
|
+
async recordProbe(userId, id, result) {
|
|
101
|
+
const row = rows.get(id)
|
|
102
|
+
if (!row) return
|
|
103
|
+
rows.set(id, {
|
|
104
|
+
...row,
|
|
105
|
+
lastProbeAt: result.at ?? new Date(),
|
|
106
|
+
lastProbeOk: result.ok,
|
|
107
|
+
lastProbeError: result.error ?? null,
|
|
108
|
+
})
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const httpInput: McpServerInput = {
|
|
114
|
+
name: 'github',
|
|
115
|
+
transport: 'http',
|
|
116
|
+
url: 'https://mcp.example.com/mcp',
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
describe('MCP 配置服务', () => {
|
|
120
|
+
it('同用户 name 唯一,跨用户可重名', async () => {
|
|
121
|
+
const store = memoryStore()
|
|
122
|
+
await createMcpServer('user-1', httpInput, { store })
|
|
123
|
+
await expect(createMcpServer('user-1', httpInput, { store })).rejects.toMatchObject({
|
|
124
|
+
code: 'mcp_duplicate_name',
|
|
125
|
+
})
|
|
126
|
+
await expect(createMcpServer('user-2', httpInput, { store })).resolves.toMatchObject({
|
|
127
|
+
name: 'github',
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('headers 拒绝 authorization / cookie / x-api-key(大小写不敏感)', () => {
|
|
132
|
+
expect(() => assertSafeHeaders({ Authorization: 'Bearer x' })).toThrowError(McpConfigError)
|
|
133
|
+
expect(() => assertSafeHeaders({ Cookie: 'a=b' })).toThrowError(McpConfigError)
|
|
134
|
+
expect(() => assertSafeHeaders({ 'X-Api-Key': 'k' })).toThrowError(McpConfigError)
|
|
135
|
+
expect(assertSafeHeaders({ 'x-trace-id': 'ok' })).toEqual({ 'x-trace-id': 'ok' })
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('stdio 默认拒绝:HARNESS_DEPLOYMENT 缺失按 saas 处理', () => {
|
|
139
|
+
expect(isStdioMcpAllowed({}, false)).toBe(false)
|
|
140
|
+
expect(isStdioMcpAllowed({ HARNESS_DEPLOYMENT: 'saas' }, false)).toBe(false)
|
|
141
|
+
expect(isStdioMcpAllowed({ HARNESS_DEPLOYMENT: 'self-hosted' }, false)).toBe(true)
|
|
142
|
+
expect(isStdioMcpAllowed({ HARNESS_DEPLOYMENT: 'desktop' }, false)).toBe(true)
|
|
143
|
+
expect(isStdioMcpAllowed({ DATABASE_PROVIDER: 'pglite' }, false)).toBe(true)
|
|
144
|
+
expect(() => assertTransportAllowed('stdio', {}, false)).toThrowError(/disabled/)
|
|
145
|
+
expect(() => assertTransportAllowed('stdio', { HARNESS_DEPLOYMENT: 'desktop' }, false)).not.toThrow()
|
|
146
|
+
expect(() => assertTransportAllowed('http', {}, false)).not.toThrow()
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('创建 stdio 服务器在 saas 被拒绝,桌面放行', async () => {
|
|
150
|
+
const store = memoryStore()
|
|
151
|
+
await expect(createMcpServer(
|
|
152
|
+
'user-1',
|
|
153
|
+
{ name: 'files', transport: 'stdio', command: 'npx' },
|
|
154
|
+
{ store, env: {}, desktopRuntime: false },
|
|
155
|
+
)).rejects.toMatchObject({ code: 'mcp_stdio_denied' })
|
|
156
|
+
await expect(createMcpServer(
|
|
157
|
+
'user-1',
|
|
158
|
+
{ name: 'files', transport: 'stdio', command: 'npx' },
|
|
159
|
+
{ store, env: {}, desktopRuntime: true },
|
|
160
|
+
)).resolves.toMatchObject({ name: 'files' })
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('凭据只进密文列:配置行不含 secret,运行时解密为 Authorization', async () => {
|
|
164
|
+
const store = memoryStore()
|
|
165
|
+
const created = await createMcpServer(
|
|
166
|
+
'user-1',
|
|
167
|
+
{ ...httpInput, secret: 'sk-live-123' },
|
|
168
|
+
{ store },
|
|
169
|
+
)
|
|
170
|
+
expect(JSON.stringify(created)).not.toContain('sk-live-123')
|
|
171
|
+
expect(created.credentialId).not.toBeNull()
|
|
172
|
+
expect(store.secrets.get('user-1:github')).toBe('sk-live-123')
|
|
173
|
+
|
|
174
|
+
const runtime = await loadRuntimeMcpServers('user-1', store)
|
|
175
|
+
expect(runtime).toHaveLength(1)
|
|
176
|
+
expect(runtime[0]).toMatchObject({ name: 'github', status: 'ready' })
|
|
177
|
+
expect(runtime[0]?.headers?.authorization).toBe('Bearer sk-live-123')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('凭据缺失时状态为 CREDENTIAL_UNAVAILABLE,不静默用空凭据', async () => {
|
|
181
|
+
const store = memoryStore()
|
|
182
|
+
const created = await createMcpServer(
|
|
183
|
+
'user-1',
|
|
184
|
+
{ ...httpInput, secret: 'sk-live-123' },
|
|
185
|
+
{ store },
|
|
186
|
+
)
|
|
187
|
+
await store.deleteSecret('user-1', 'github')
|
|
188
|
+
const runtime = await loadRuntimeMcpServers('user-1', store)
|
|
189
|
+
expect(runtime[0]).toMatchObject({ id: created.id, status: 'CREDENTIAL_UNAVAILABLE' })
|
|
190
|
+
expect(runtime[0]?.headers?.authorization).toBeUndefined()
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('更新可换名并保留/清除凭据;删除同时清凭据', async () => {
|
|
194
|
+
const store = memoryStore()
|
|
195
|
+
const created = await createMcpServer(
|
|
196
|
+
'user-1',
|
|
197
|
+
{ ...httpInput, secret: 'token' },
|
|
198
|
+
{ store },
|
|
199
|
+
)
|
|
200
|
+
const renamed = await updateMcpServer('user-1', created.id, { ...httpInput, name: 'gh' }, { store })
|
|
201
|
+
expect(renamed.name).toBe('gh')
|
|
202
|
+
expect(renamed.credentialId).toBeNull()
|
|
203
|
+
|
|
204
|
+
await deleteMcpServer('user-1', created.id, store)
|
|
205
|
+
expect(store.rows.size).toBe(0)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('非法输入被 schema 拦下(http 缺 url / stdio 带 url)', async () => {
|
|
209
|
+
const store = memoryStore()
|
|
210
|
+
await expect(createMcpServer('user-1', { name: 'x', transport: 'http' }, { store }))
|
|
211
|
+
.rejects.toMatchObject({ code: 'mcp_invalid_input' })
|
|
212
|
+
await expect(createMcpServer(
|
|
213
|
+
'user-1',
|
|
214
|
+
{ name: 'x', transport: 'stdio', command: 'npx', url: 'https://x' },
|
|
215
|
+
{ store, desktopRuntime: true },
|
|
216
|
+
)).rejects.toMatchObject({ code: 'mcp_invalid_input' })
|
|
217
|
+
})
|
|
218
|
+
})
|