vessel-agent 0.0.0-stage → 2.3.0-beta.2
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/LICENSE +21 -0
- package/README.md +466 -2
- package/README.zh-CN.md +476 -0
- package/apps/web/dist/Vela.png +0 -0
- package/apps/web/dist/Vessel.svg +24 -0
- package/apps/web/dist/apple-touch-icon.png +0 -0
- package/apps/web/dist/assets/ConfigView-BKdxb1s5.js +1 -0
- package/apps/web/dist/assets/DesignLabContent-CY5HfVn_.js +4 -0
- package/apps/web/dist/assets/DesignLabView-DTBWv5-E.js +1 -0
- package/apps/web/dist/assets/action-menu.preview-CpIL3tay.js +1 -0
- package/apps/web/dist/assets/agent-message.preview-CSYnJxgr.js +1 -0
- package/apps/web/dist/assets/assistant-text.preview-Bc2Is6sW.js +2 -0
- package/apps/web/dist/assets/badges.preview-DP0oPcs5.js +1 -0
- package/apps/web/dist/assets/buttons.preview-Y84aT4k3.js +1 -0
- package/apps/web/dist/assets/card-shell.preview-mwRwhVb8.js +1 -0
- package/apps/web/dist/assets/chip-tones.preview-dQ_6pwft.js +1 -0
- package/apps/web/dist/assets/composer-controls.preview-CBtJVrMo.js +1 -0
- package/apps/web/dist/assets/confirm-dialog.preview-BkNEtLld.js +1 -0
- package/apps/web/dist/assets/data-table.preview-DPZ7Pnn8.js +1 -0
- package/apps/web/dist/assets/depth-color.preview-CtCbAgCH.js +1 -0
- package/apps/web/dist/assets/entity-header.preview-BxPLNUSH.js +1 -0
- package/apps/web/dist/assets/env-card.preview-Bv4UlMjr.js +1 -0
- package/apps/web/dist/assets/failure-card.preview-DD3-RMju.js +1 -0
- package/apps/web/dist/assets/filter-popover.preview-D7Q7Kws8.js +1 -0
- package/apps/web/dist/assets/form.preview-D_Qltx-j.js +1 -0
- package/apps/web/dist/assets/index-ee36IO2F.js +600 -0
- package/apps/web/dist/assets/index-uU9N5oTa.css +1 -0
- package/apps/web/dist/assets/key-value.preview-B0gzxwtK.js +1 -0
- package/apps/web/dist/assets/mention-popover.preview-Duza1RgL.js +1 -0
- package/apps/web/dist/assets/message-fold.preview-Cx-CD3Y4.js +1 -0
- package/apps/web/dist/assets/modal-shell.preview-DYKwUk2S.js +1 -0
- package/apps/web/dist/assets/nav-item.preview-FTbsBQ2g.js +1 -0
- package/apps/web/dist/assets/nav-status-legend.preview-bS4LDFbd.js +1 -0
- package/apps/web/dist/assets/page-scaffold.preview-bzBFkjZ6.js +1 -0
- package/apps/web/dist/assets/plugin-ui-BxTydP3l.js +1 -0
- package/apps/web/dist/assets/projection-card.preview-BV0P-y8e.js +6 -0
- package/apps/web/dist/assets/queued.preview-zQqFe4Zr.js +1 -0
- package/apps/web/dist/assets/react-vendor-CUu194FT.js +9 -0
- package/apps/web/dist/assets/reasoning.preview-DtHXgW_8.js +2 -0
- package/apps/web/dist/assets/section.preview-A-PRm-rh.js +1 -0
- package/apps/web/dist/assets/sidebar-shell.preview-DFKMwNoo.js +1 -0
- package/apps/web/dist/assets/stat.preview-BzChSFLL.js +1 -0
- package/apps/web/dist/assets/states.preview-CyXZWnZ-.js +1 -0
- package/apps/web/dist/assets/status-icons.preview-DHdWwUis.js +1 -0
- package/apps/web/dist/assets/tabs.preview-CHbK1Two.js +1 -0
- package/apps/web/dist/assets/tool-card.preview-Z48fekTD.js +2 -0
- package/apps/web/dist/assets/toolbar.preview-Bl6hLYXX.js +1 -0
- package/apps/web/dist/assets/tooltip.preview-GKGTGfMP.js +1 -0
- package/apps/web/dist/assets/user-bubble.preview-CHYvio9z.js +1 -0
- package/apps/web/dist/assets/vendor/jsx-runtime.mjs +7 -0
- package/apps/web/dist/assets/vendor/plugin-sdk.mjs +12 -0
- package/apps/web/dist/assets/vendor/react-dom-client.mjs +6 -0
- package/apps/web/dist/assets/vendor/react-dom.mjs +11 -0
- package/apps/web/dist/assets/vendor/react.mjs +39 -0
- package/apps/web/dist/build.json +5 -0
- package/apps/web/dist/favicon.ico +0 -0
- package/apps/web/dist/index.html +24 -0
- package/package.json +70 -4
- package/packages/agent/package.json +32 -0
- package/packages/agent/src/address-display.ts +141 -0
- package/packages/agent/src/conversation-budget.ts +651 -0
- package/packages/agent/src/conversation-store.ts +351 -0
- package/packages/agent/src/distress.ts +161 -0
- package/packages/agent/src/env-info-scope.ts +153 -0
- package/packages/agent/src/error-text.ts +28 -0
- package/packages/agent/src/inbox-source.ts +73 -0
- package/packages/agent/src/inbox.ts +2335 -0
- package/packages/agent/src/index.ts +273 -0
- package/packages/agent/src/member-cwd.ts +128 -0
- package/packages/agent/src/member-ports.ts +162 -0
- package/packages/agent/src/refs.ts +51 -0
- package/packages/agent/src/registry.ts +741 -0
- package/packages/agent/src/runtime.ts +2501 -0
- package/packages/agent/src/self-card-delta.ts +428 -0
- package/packages/agent/src/service.ts +9212 -0
- package/packages/agent/src/snapshot.ts +614 -0
- package/packages/agent/src/team-address.ts +96 -0
- package/packages/agent/src/team-log.ts +487 -0
- package/packages/agent/src/team-service.ts +1966 -0
- package/packages/agent/src/team-slug.ts +167 -0
- package/packages/agent/src/team-store.ts +619 -0
- package/packages/agent/src/tool.ts +1306 -0
- package/packages/agent/src/types/budget.ts +168 -0
- package/packages/agent/src/types/constants.ts +17 -0
- package/packages/agent/src/types/dispatch.ts +133 -0
- package/packages/agent/src/types/events.ts +132 -0
- package/packages/agent/src/types/execution.ts +289 -0
- package/packages/agent/src/types/lifecycle.ts +372 -0
- package/packages/agent/src/types/member.ts +221 -0
- package/packages/agent/src/types/message.ts +113 -0
- package/packages/agent/src/types/results.ts +64 -0
- package/packages/agent/src/types/roster.ts +137 -0
- package/packages/agent/src/types/service.ts +702 -0
- package/packages/agent/src/types/session.ts +102 -0
- package/packages/agent/src/types/team.ts +558 -0
- package/packages/agent/src/types.ts +22 -0
- package/packages/agent/tsconfig.json +8 -0
- package/packages/config/package.json +32 -0
- package/packages/config/src/auth-origins.ts +85 -0
- package/packages/config/src/auth-strategies/avatar-ref.ts +40 -0
- package/packages/config/src/auth-strategies/gitee.ts +72 -0
- package/packages/config/src/auth-strategies/github.ts +64 -0
- package/packages/config/src/auth-strategies/index.ts +47 -0
- package/packages/config/src/auth-strategies/match.ts +82 -0
- package/packages/config/src/auth-strategies/microsoft.ts +100 -0
- package/packages/config/src/auth-strategies/oauth-exchange.ts +192 -0
- package/packages/config/src/auth-strategies/password.ts +34 -0
- package/packages/config/src/auth-strategies/registry.ts +105 -0
- package/packages/config/src/auth-strategies/shapes.ts +138 -0
- package/packages/config/src/auth-strategies/types.ts +190 -0
- package/packages/config/src/auth.ts +305 -0
- package/packages/config/src/config-lock.ts +328 -0
- package/packages/config/src/defaults.ts +271 -0
- package/packages/config/src/env-file.ts +175 -0
- package/packages/config/src/env-injection.ts +117 -0
- package/packages/config/src/explain.ts +283 -0
- package/packages/config/src/gateway.ts +107 -0
- package/packages/config/src/index.ts +253 -0
- package/packages/config/src/loader.ts +871 -0
- package/packages/config/src/model-migration.ts +534 -0
- package/packages/config/src/model-registry.ts +374 -0
- package/packages/config/src/models-disk.ts +72 -0
- package/packages/config/src/models-validation.ts +467 -0
- package/packages/config/src/node-registration.ts +583 -0
- package/packages/config/src/root-secret.ts +402 -0
- package/packages/config/src/secrets.ts +452 -0
- package/packages/config/src/sources.ts +82 -0
- package/packages/config/src/team-policy.ts +422 -0
- package/packages/config/src/types/agent.ts +263 -0
- package/packages/config/src/types/attention.ts +28 -0
- package/packages/config/src/types/auth.ts +126 -0
- package/packages/config/src/types/connect.ts +21 -0
- package/packages/config/src/types/hub.ts +59 -0
- package/packages/config/src/types/models.ts +153 -0
- package/packages/config/src/types/node.ts +202 -0
- package/packages/config/src/types/observability.ts +84 -0
- package/packages/config/src/types/root.ts +240 -0
- package/packages/config/src/types/runtime.ts +123 -0
- package/packages/config/src/types/security.ts +43 -0
- package/packages/config/src/types/serve.ts +34 -0
- package/packages/config/src/types/snapshot.ts +28 -0
- package/packages/config/src/types/team.ts +112 -0
- package/packages/config/src/types/ui.ts +179 -0
- package/packages/config/src/types.ts +22 -0
- package/packages/config/src/user-config.ts +175 -0
- package/packages/config/src/utils.ts +55 -0
- package/packages/config/src/validator/auth.ts +302 -0
- package/packages/config/src/validator/hub.ts +329 -0
- package/packages/config/src/validator/models.ts +1304 -0
- package/packages/config/src/validator/serve.ts +784 -0
- package/packages/config/src/validator/settings.ts +244 -0
- package/packages/config/src/validator/shared.ts +304 -0
- package/packages/config/src/validator/tenant-keys.ts +91 -0
- package/packages/config/src/validator/unknown-keys.ts +452 -0
- package/packages/config/src/validator.ts +1146 -0
- package/packages/config/tsconfig.json +8 -0
- package/packages/core/package.json +38 -0
- package/packages/core/src/context/anchor.ts +57 -0
- package/packages/core/src/context/archive-notice.ts +283 -0
- package/packages/core/src/context/cleared-tool-result.ts +262 -0
- package/packages/core/src/context/compaction-index.ts +381 -0
- package/packages/core/src/context/composition.ts +251 -0
- package/packages/core/src/context/context-manager.ts +1585 -0
- package/packages/core/src/context/context-notice.ts +218 -0
- package/packages/core/src/context/index.ts +220 -0
- package/packages/core/src/context/model-change-notice.ts +81 -0
- package/packages/core/src/context/projection-policy.ts +719 -0
- package/packages/core/src/context/prompt-context.ts +66 -0
- package/packages/core/src/context/read-side-mask.ts +63 -0
- package/packages/core/src/context/request-sequence.ts +423 -0
- package/packages/core/src/context/request-view.ts +256 -0
- package/packages/core/src/context/session-breaker.ts +100 -0
- package/packages/core/src/context/tool-result-whitelist.ts +135 -0
- package/packages/core/src/events/event-stream.ts +271 -0
- package/packages/core/src/events/file-event-store.ts +119 -0
- package/packages/core/src/events/index.ts +15 -0
- package/packages/core/src/events/replay.ts +82 -0
- package/packages/core/src/events/summarize-event.ts +135 -0
- package/packages/core/src/index.ts +475 -0
- package/packages/core/src/kernel/cancellation.ts +54 -0
- package/packages/core/src/kernel/event-bus.ts +65 -0
- package/packages/core/src/kernel/index.ts +32 -0
- package/packages/core/src/kernel/internal.ts +32 -0
- package/packages/core/src/kernel/scheduler.ts +406 -0
- package/packages/core/src/kernel/types.ts +269 -0
- package/packages/core/src/limits/index.ts +23 -0
- package/packages/core/src/limits/limit-checker.ts +270 -0
- package/packages/core/src/limits/limit-error.ts +29 -0
- package/packages/core/src/log-format.ts +722 -0
- package/packages/core/src/log-hub.ts +278 -0
- package/packages/core/src/logging.ts +64 -0
- package/packages/core/src/observability/index.ts +24 -0
- package/packages/core/src/observability/metrics.ts +279 -0
- package/packages/core/src/observability/read-trace.ts +163 -0
- package/packages/core/src/observability/rebuild-metrics.ts +37 -0
- package/packages/core/src/observability/trace-prune.ts +248 -0
- package/packages/core/src/observability/trace-recorder.ts +484 -0
- package/packages/core/src/observability/trace-redactor.ts +93 -0
- package/packages/core/src/pii/index.ts +88 -0
- package/packages/core/src/pii/notice.ts +156 -0
- package/packages/core/src/pii/reveal.ts +198 -0
- package/packages/core/src/pii/rules.ts +545 -0
- package/packages/core/src/pii/types.ts +140 -0
- package/packages/core/src/pii/vault.ts +764 -0
- package/packages/core/src/provider/errors.ts +41 -0
- package/packages/core/src/provider/index.ts +19 -0
- package/packages/core/src/provider/providers.ts +1011 -0
- package/packages/core/src/provider/request-extras.ts +285 -0
- package/packages/core/src/provider/stream-accumulator.ts +168 -0
- package/packages/core/src/provider/usage.ts +112 -0
- package/packages/core/src/runtime/error-envelope.ts +451 -0
- package/packages/core/src/runtime/error-summary.ts +174 -0
- package/packages/core/src/runtime/execution-unit.ts +6675 -0
- package/packages/core/src/runtime/guardrail-runner.ts +86 -0
- package/packages/core/src/runtime/hook-runner.ts +137 -0
- package/packages/core/src/runtime/index.ts +123 -0
- package/packages/core/src/runtime/permission-policy.ts +267 -0
- package/packages/core/src/runtime/plugin-host.ts +489 -0
- package/packages/core/src/runtime/plugin-install.ts +144 -0
- package/packages/core/src/runtime/policy/index.ts +21 -0
- package/packages/core/src/runtime/prompt-prefix-guard.ts +166 -0
- package/packages/core/src/runtime/provider-retry.ts +220 -0
- package/packages/core/src/runtime/resume-markers.ts +114 -0
- package/packages/core/src/runtime/resume-recovery.ts +164 -0
- package/packages/core/src/runtime/run-journal.ts +382 -0
- package/packages/core/src/runtime/run-timing.ts +217 -0
- package/packages/core/src/runtime/runtime.ts +349 -0
- package/packages/core/src/runtime/safepoint-pause.ts +29 -0
- package/packages/core/src/runtime/tool-attachment.ts +170 -0
- package/packages/core/src/runtime/tool-calling-loop.ts +1219 -0
- package/packages/core/src/runtime/tool-name.ts +215 -0
- package/packages/core/src/runtime/tool-pipeline.ts +459 -0
- package/packages/core/src/runtime/tool-provenance.ts +48 -0
- package/packages/core/src/runtime/tool-result-gate.ts +329 -0
- package/packages/core/src/session/atomic-write.ts +335 -0
- package/packages/core/src/session/compaction-index-derive.ts +173 -0
- package/packages/core/src/session/compaction-index-store.ts +161 -0
- package/packages/core/src/session/compaction-recall.ts +375 -0
- package/packages/core/src/session/delete-session.ts +198 -0
- package/packages/core/src/session/file-backend.ts +1311 -0
- package/packages/core/src/session/index.ts +118 -0
- package/packages/core/src/session/message-identity.ts +272 -0
- package/packages/core/src/session/project-messages.ts +908 -0
- package/packages/core/src/session/projection-cache.ts +254 -0
- package/packages/core/src/session/prune.ts +153 -0
- package/packages/core/src/session/run-record-store.ts +307 -0
- package/packages/core/src/session/session-index.ts +158 -0
- package/packages/core/src/session/session-log-dir.ts +39 -0
- package/packages/core/src/session/session-store.ts +266 -0
- package/packages/core/src/session/sqlite-backend.ts +391 -0
- package/packages/core/src/socket-inherit-guard.ts +188 -0
- package/packages/core/src/storage/metadata-sidecar.ts +124 -0
- package/packages/core/src/tenant/index.ts +13 -0
- package/packages/core/src/tenant/resolve-tenant.ts +19 -0
- package/packages/core/src/tenant/tenant-paths.ts +83 -0
- package/packages/core/src/timeline/archive-audit.ts +316 -0
- package/packages/core/src/timeline/archive-lock.ts +124 -0
- package/packages/core/src/timeline/blocks.ts +1639 -0
- package/packages/core/src/timeline/enum-stats.ts +34 -0
- package/packages/core/src/timeline/holes.ts +431 -0
- package/packages/core/src/timeline/index.ts +387 -0
- package/packages/core/src/timeline/legacy-format.ts +97 -0
- package/packages/core/src/timeline/read-port.ts +582 -0
- package/packages/core/src/timeline/types.ts +371 -0
- package/packages/core/src/timeline/wal.ts +2485 -0
- package/packages/core/src/timeline/writer.ts +2079 -0
- package/packages/core/src/timeout.ts +93 -0
- package/packages/core/src/transport/in-process.ts +86 -0
- package/packages/core/src/transport/index.ts +6 -0
- package/packages/core/src/types/context.ts +229 -0
- package/packages/core/src/types/env-cadence.ts +35 -0
- package/packages/core/src/types/error-registry.ts +343 -0
- package/packages/core/src/types/error.ts +107 -0
- package/packages/core/src/types/event.ts +496 -0
- package/packages/core/src/types/guardrail.ts +35 -0
- package/packages/core/src/types/hook.ts +122 -0
- package/packages/core/src/types/index.ts +28 -0
- package/packages/core/src/types/lease.ts +91 -0
- package/packages/core/src/types/limits.ts +112 -0
- package/packages/core/src/types/logging.ts +54 -0
- package/packages/core/src/types/member-port.ts +194 -0
- package/packages/core/src/types/plugin.ts +392 -0
- package/packages/core/src/types/projection-cache.ts +80 -0
- package/packages/core/src/types/projection.ts +100 -0
- package/packages/core/src/types/provider.ts +319 -0
- package/packages/core/src/types/run-journal.ts +178 -0
- package/packages/core/src/types/run-record-store.ts +128 -0
- package/packages/core/src/types/run.ts +140 -0
- package/packages/core/src/types/session.ts +328 -0
- package/packages/core/src/types/source-module.ts +68 -0
- package/packages/core/src/types/tenant.ts +41 -0
- package/packages/core/src/types/tool-name.ts +57 -0
- package/packages/core/src/types/tool.ts +122 -0
- package/packages/core/src/types/trace.ts +38 -0
- package/packages/core/src/types/vision.ts +219 -0
- package/packages/core/src/vision/blobs.ts +328 -0
- package/packages/core/src/vision/index.ts +73 -0
- package/packages/core/src/vision/ingest.ts +126 -0
- package/packages/core/src/vision/notice.ts +58 -0
- package/packages/core/src/vision/plan.ts +358 -0
- package/packages/core/src/vision/staging.ts +81 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/permission/package.json +31 -0
- package/packages/permission/src/index.ts +60 -0
- package/packages/plugin-sdk/package.json +21 -0
- package/packages/plugin-sdk/src/index.ts +478 -0
- package/packages/plugin-sdk/src/semver.ts +154 -0
- package/packages/plugin-ui/package.json +33 -0
- package/packages/plugin-ui/src/Badge.tsx +41 -0
- package/packages/plugin-ui/src/Button.tsx +84 -0
- package/packages/plugin-ui/src/ComposerAttachments.tsx +87 -0
- package/packages/plugin-ui/src/ComposerContextMeter.tsx +209 -0
- package/packages/plugin-ui/src/ComposerToolbar.tsx +233 -0
- package/packages/plugin-ui/src/CountBadge.tsx +57 -0
- package/packages/plugin-ui/src/DataTable.tsx +168 -0
- package/packages/plugin-ui/src/Field.tsx +543 -0
- package/packages/plugin-ui/src/KeyValueList.tsx +32 -0
- package/packages/plugin-ui/src/Page.tsx +39 -0
- package/packages/plugin-ui/src/Pager.tsx +63 -0
- package/packages/plugin-ui/src/SearchInput.tsx +33 -0
- package/packages/plugin-ui/src/Section.tsx +47 -0
- package/packages/plugin-ui/src/Stat.tsx +25 -0
- package/packages/plugin-ui/src/TableToolbar.tsx +27 -0
- package/packages/plugin-ui/src/Tabs.tsx +77 -0
- package/packages/plugin-ui/src/card-surface.ts +11 -0
- package/packages/plugin-ui/src/cn.ts +7 -0
- package/packages/plugin-ui/src/dom-globals.d.ts +124 -0
- package/packages/plugin-ui/src/host.ts +270 -0
- package/packages/plugin-ui/src/index.ts +26 -0
- package/packages/plugin-ui/src/styles.css +386 -0
- package/packages/plugin-ui/src/useStaleWhileRevalidate.ts +211 -0
- package/packages/serve/package.json +32 -0
- package/packages/serve/src/agent-control.ts +595 -0
- package/packages/serve/src/agents-registry.ts +409 -0
- package/packages/serve/src/auth/avatar.ts +352 -0
- package/packages/serve/src/auth/bootstrap.ts +184 -0
- package/packages/serve/src/auth/credentials.ts +275 -0
- package/packages/serve/src/auth/github-oauth.ts +33 -0
- package/packages/serve/src/auth/index.ts +121 -0
- package/packages/serve/src/auth/oauth.ts +394 -0
- package/packages/serve/src/auth/origins.ts +145 -0
- package/packages/serve/src/auth/password.ts +187 -0
- package/packages/serve/src/auth/ratelimit.ts +249 -0
- package/packages/serve/src/auth/routes.ts +1757 -0
- package/packages/serve/src/auth/session.ts +407 -0
- package/packages/serve/src/auth/totp.ts +183 -0
- package/packages/serve/src/backpressure.ts +91 -0
- package/packages/serve/src/durable.ts +216 -0
- package/packages/serve/src/evals.ts +140 -0
- package/packages/serve/src/event-buffer.ts +92 -0
- package/packages/serve/src/event-summary.ts +11 -0
- package/packages/serve/src/federation.ts +1100 -0
- package/packages/serve/src/feishu.ts +51 -0
- package/packages/serve/src/gateway/auth.ts +773 -0
- package/packages/serve/src/gateway/errors.ts +21 -0
- package/packages/serve/src/gateway/frames.ts +195 -0
- package/packages/serve/src/gateway/methods/admin.ts +530 -0
- package/packages/serve/src/gateway/methods/agents.ts +1727 -0
- package/packages/serve/src/gateway/methods/attachments.ts +354 -0
- package/packages/serve/src/gateway/methods/common.ts +50 -0
- package/packages/serve/src/gateway/methods/config.ts +883 -0
- package/packages/serve/src/gateway/methods/evals.ts +87 -0
- package/packages/serve/src/gateway/methods/feishu.ts +52 -0
- package/packages/serve/src/gateway/methods/fleet.ts +225 -0
- package/packages/serve/src/gateway/methods/images.ts +196 -0
- package/packages/serve/src/gateway/methods/interactions.ts +721 -0
- package/packages/serve/src/gateway/methods/jobs.ts +148 -0
- package/packages/serve/src/gateway/methods/kanban.ts +637 -0
- package/packages/serve/src/gateway/methods/mcp.ts +82 -0
- package/packages/serve/src/gateway/methods/observability.ts +264 -0
- package/packages/serve/src/gateway/methods/permissions.ts +397 -0
- package/packages/serve/src/gateway/methods/rpc-namespaces.ts +80 -0
- package/packages/serve/src/gateway/methods/runs.ts +434 -0
- package/packages/serve/src/gateway/methods/schemas.ts +1196 -0
- package/packages/serve/src/gateway/methods/sessions.ts +2568 -0
- package/packages/serve/src/gateway/methods/subscription.ts +515 -0
- package/packages/serve/src/gateway/methods/teams.ts +638 -0
- package/packages/serve/src/gateway/sse.ts +130 -0
- package/packages/serve/src/gateway/static.ts +66 -0
- package/packages/serve/src/gateway/timeline-protocol.ts +532 -0
- package/packages/serve/src/gateway.ts +4974 -0
- package/packages/serve/src/hub-control.ts +86 -0
- package/packages/serve/src/hub-frames.ts +435 -0
- package/packages/serve/src/hub-protocol.ts +182 -0
- package/packages/serve/src/index.ts +511 -0
- package/packages/serve/src/interactions-registry.ts +1362 -0
- package/packages/serve/src/interactions-store.ts +360 -0
- package/packages/serve/src/local.ts +48 -0
- package/packages/serve/src/log-event.ts +57 -0
- package/packages/serve/src/mcp.ts +73 -0
- package/packages/serve/src/metrics.ts +137 -0
- package/packages/serve/src/platform/auth.ts +146 -0
- package/packages/serve/src/platform/index.ts +54 -0
- package/packages/serve/src/platform/listen-guard.ts +68 -0
- package/packages/serve/src/platform/metrics.ts +123 -0
- package/packages/serve/src/platform/proxy-config.ts +368 -0
- package/packages/serve/src/platform/proxy-ws.ts +737 -0
- package/packages/serve/src/platform/proxy.ts +909 -0
- package/packages/serve/src/platform/registry.ts +130 -0
- package/packages/serve/src/platform/rpc.ts +445 -0
- package/packages/serve/src/platform/server.ts +1148 -0
- package/packages/serve/src/platform/types.ts +276 -0
- package/packages/serve/src/plugin-host/catalog.ts +212 -0
- package/packages/serve/src/plugin-host/child.ts +767 -0
- package/packages/serve/src/plugin-host/dto.ts +191 -0
- package/packages/serve/src/plugin-host/errors.ts +50 -0
- package/packages/serve/src/plugin-host/events.ts +114 -0
- package/packages/serve/src/plugin-host/expose.ts +142 -0
- package/packages/serve/src/plugin-host/http.ts +823 -0
- package/packages/serve/src/plugin-host/index.ts +170 -0
- package/packages/serve/src/plugin-host/manager.ts +2027 -0
- package/packages/serve/src/plugin-host/ndjson.ts +136 -0
- package/packages/serve/src/plugin-host/proxy.ts +358 -0
- package/packages/serve/src/plugin-host/registry.ts +208 -0
- package/packages/serve/src/plugin-host/static.ts +162 -0
- package/packages/serve/src/plugin-host/types.ts +529 -0
- package/packages/serve/src/plugin-host/ws-proxy.ts +431 -0
- package/packages/serve/src/prometheus.ts +98 -0
- package/packages/serve/src/protocol.ts +332 -0
- package/packages/serve/src/replay-budget.ts +481 -0
- package/packages/serve/src/rpc.ts +614 -0
- package/packages/serve/src/run-control.ts +106 -0
- package/packages/serve/src/session-search.ts +142 -0
- package/packages/serve/src/shutdown-step.ts +128 -0
- package/packages/serve/src/team-control.ts +282 -0
- package/packages/serve/src/tenant-event-hub.ts +194 -0
- package/packages/serve/src/tenant.ts +169 -0
- package/packages/serve/src/tool-events.ts +244 -0
- package/packages/tui/package.json +40 -0
- package/packages/tui/src/commands/agents-command.ts +402 -0
- package/packages/tui/src/commands/capabilities-command.ts +356 -0
- package/packages/tui/src/commands/commands.ts +1361 -0
- package/packages/tui/src/commands/config-command.ts +541 -0
- package/packages/tui/src/commands/context-command.ts +348 -0
- package/packages/tui/src/commands/cost-command.ts +66 -0
- package/packages/tui/src/commands/details-command.ts +47 -0
- package/packages/tui/src/commands/errors-command.ts +205 -0
- package/packages/tui/src/commands/export-command.ts +193 -0
- package/packages/tui/src/commands/feishu-command.ts +101 -0
- package/packages/tui/src/commands/mcp-command.ts +319 -0
- package/packages/tui/src/commands/metrics-command.ts +314 -0
- package/packages/tui/src/commands/permissions-command.ts +117 -0
- package/packages/tui/src/commands/runs-command.ts +421 -0
- package/packages/tui/src/commands/sessions-command.ts +367 -0
- package/packages/tui/src/commands/settings-command.ts +180 -0
- package/packages/tui/src/commands/status-command.ts +30 -0
- package/packages/tui/src/commands/trace-command.ts +382 -0
- package/packages/tui/src/components/AskUserDialog.tsx +663 -0
- package/packages/tui/src/components/BottomBar.tsx +44 -0
- package/packages/tui/src/components/ConfirmDialog.tsx +175 -0
- package/packages/tui/src/components/DataTable.tsx +99 -0
- package/packages/tui/src/components/DetailPanel.tsx +80 -0
- package/packages/tui/src/components/EmptyState.tsx +27 -0
- package/packages/tui/src/components/InlineAutocomplete.tsx +319 -0
- package/packages/tui/src/components/InteractiveViewHost.tsx +652 -0
- package/packages/tui/src/components/KeyHints.tsx +41 -0
- package/packages/tui/src/components/Markdown.tsx +489 -0
- package/packages/tui/src/components/PanelFrame.tsx +113 -0
- package/packages/tui/src/components/QueuePreview.tsx +113 -0
- package/packages/tui/src/components/QuickHelp.tsx +91 -0
- package/packages/tui/src/components/ReasoningBlock.tsx +42 -0
- package/packages/tui/src/components/SessionTable.tsx +523 -0
- package/packages/tui/src/components/SpinnerWithVerb.tsx +116 -0
- package/packages/tui/src/components/StateTracker.ts +102 -0
- package/packages/tui/src/components/StatusBar.tsx +315 -0
- package/packages/tui/src/components/StreamOutput.tsx +302 -0
- package/packages/tui/src/components/SubagentActivity.tsx +57 -0
- package/packages/tui/src/components/TextViewer.tsx +100 -0
- package/packages/tui/src/components/ToolDisplay.tsx +248 -0
- package/packages/tui/src/components/ToolTrail.tsx +104 -0
- package/packages/tui/src/components/UiItemView.tsx +460 -0
- package/packages/tui/src/components/UpdateBanner.tsx +48 -0
- package/packages/tui/src/components/indicator.ts +61 -0
- package/packages/tui/src/error-classifier.ts +255 -0
- package/packages/tui/src/i18n/index.ts +67 -0
- package/packages/tui/src/i18n/messages/en.ts +543 -0
- package/packages/tui/src/i18n/messages/zh-CN.ts +528 -0
- package/packages/tui/src/index.ts +335 -0
- package/packages/tui/src/renderer/ask-user.ts +431 -0
- package/packages/tui/src/renderer/notify-user.ts +184 -0
- package/packages/tui/src/renderer/stream-renderer.ts +149 -0
- package/packages/tui/src/renderer/tool-confirm.ts +47 -0
- package/packages/tui/src/repl/agent-registry.ts +747 -0
- package/packages/tui/src/repl/cache-metrics.ts +241 -0
- package/packages/tui/src/repl/clear-on-start.ts +28 -0
- package/packages/tui/src/repl/error-archive.ts +95 -0
- package/packages/tui/src/repl/error-log.ts +212 -0
- package/packages/tui/src/repl/ink-repl.tsx +1735 -0
- package/packages/tui/src/repl/layout.ts +303 -0
- package/packages/tui/src/repl/limit-info.ts +630 -0
- package/packages/tui/src/repl/permission-pending.ts +49 -0
- package/packages/tui/src/repl/project/ui-item.ts +1307 -0
- package/packages/tui/src/repl/queue-info.ts +109 -0
- package/packages/tui/src/repl/resume-picker.ts +24 -0
- package/packages/tui/src/repl/run-turn.ts +60 -0
- package/packages/tui/src/repl/runtime-counters.ts +91 -0
- package/packages/tui/src/repl/startup-header.ts +144 -0
- package/packages/tui/src/repl/startup-notice.ts +100 -0
- package/packages/tui/src/repl/status-format.ts +513 -0
- package/packages/tui/src/repl/status-metrics.ts +88 -0
- package/packages/tui/src/repl/status-snapshot.ts +454 -0
- package/packages/tui/src/repl/use-repl-state.ts +548 -0
- package/packages/tui/src/repl-context.ts +349 -0
- package/packages/tui/src/rich-renderer.ts +63 -0
- package/packages/tui/src/rpc-events.ts +161 -0
- package/packages/tui/src/rpc.ts +149 -0
- package/packages/tui/src/theme.ts +180 -0
- package/packages/tui/src/types/events.ts +284 -0
- package/packages/tui/src/utils/dialog.ts +35 -0
- package/packages/tui/src/utils/diff.ts +124 -0
- package/packages/tui/src/utils/display-labels.ts +56 -0
- package/packages/tui/src/utils/file-reference.ts +180 -0
- package/packages/tui/src/utils/git.ts +24 -0
- package/packages/tui/src/utils/sanitize-terminal-text.ts +109 -0
- package/packages/tui/src/utils/text-layout.ts +127 -0
- package/packages/tui/src/utils/time.ts +25 -0
- package/packages/tui/src/utils/tool-input-summary.ts +70 -0
- package/packages/tui/src/views/keys.ts +344 -0
- package/packages/tui/src/views/layout.ts +224 -0
- package/packages/tui/src/views/render-text.ts +154 -0
- package/packages/tui/src/views/selection.ts +57 -0
- package/packages/tui/src/views/session-picker.ts +215 -0
- package/packages/tui/src/views/tones.ts +24 -0
- package/packages/tui/src/views/types.ts +200 -0
- package/packages/tui/src/wizard/setup-wizard.ts +439 -0
- package/packages/tui/tsconfig.json +10 -0
- package/plugins/context/doc-subscription/package.json +32 -0
- package/plugins/context/doc-subscription/src/agent.ts +151 -0
- package/plugins/context/doc-subscription/src/auto-sub.ts +80 -0
- package/plugins/context/doc-subscription/src/config.ts +358 -0
- package/plugins/context/doc-subscription/src/diff.ts +107 -0
- package/plugins/context/doc-subscription/src/friend-edges.ts +118 -0
- package/plugins/context/doc-subscription/src/health.ts +163 -0
- package/plugins/context/doc-subscription/src/hook.ts +1222 -0
- package/plugins/context/doc-subscription/src/implicit.ts +84 -0
- package/plugins/context/doc-subscription/src/index.ts +288 -0
- package/plugins/context/doc-subscription/src/lifecycle-listener.ts +58 -0
- package/plugins/context/doc-subscription/src/lifecycle.ts +186 -0
- package/plugins/context/doc-subscription/src/mute.ts +39 -0
- package/plugins/context/doc-subscription/src/notice.ts +347 -0
- package/plugins/context/doc-subscription/src/script.ts +288 -0
- package/plugins/context/doc-subscription/src/sources.ts +187 -0
- package/plugins/context/doc-subscription/src/store.ts +748 -0
- package/plugins/context/doc-subscription/src/team-log.ts +155 -0
- package/plugins/context/doc-subscription/src/tool.ts +2132 -0
- package/plugins/context/skills/package.json +182 -0
- package/plugins/context/skills/src/config.ts +178 -0
- package/plugins/context/skills/src/frontmatter.ts +166 -0
- package/plugins/context/skills/src/index.ts +144 -0
- package/plugins/context/skills/src/rpc.ts +274 -0
- package/plugins/context/skills/src/scanner.ts +262 -0
- package/plugins/context/skills/src/service.ts +277 -0
- package/plugins/context/skills/src/store.ts +333 -0
- package/plugins/context/skills/src/tool.ts +354 -0
- package/plugins/context/skills/src/trust.ts +71 -0
- package/plugins/context/skills/src/types.ts +130 -0
- package/plugins/context/skills/src/watch.ts +83 -0
- package/plugins/context/skills/tsconfig.web.json +29 -0
- package/plugins/context/skills/vite.config.embed.ts +107 -0
- package/plugins/context/skills/vite.config.ts +121 -0
- package/plugins/context/skills/web/assets/skills-8su2cNqF.css +2 -0
- package/plugins/context/skills/web/assets/skills-BhiDTAac.js +10 -0
- package/plugins/context/skills/web/embed/index.css +3 -0
- package/plugins/context/skills/web/embed/index.mjs +4251 -0
- package/plugins/context/skills/web/skills.html +13 -0
- package/plugins/context/skills/web-src/App.tsx +47 -0
- package/plugins/context/skills/web-src/SkillsView.tsx +649 -0
- package/plugins/context/skills/web-src/embed.css +153 -0
- package/plugins/context/skills/web-src/embed.tsx +36 -0
- package/plugins/context/skills/web-src/env.d.ts +2 -0
- package/plugins/context/skills/web-src/i18n.ts +195 -0
- package/plugins/context/skills/web-src/main.tsx +14 -0
- package/plugins/context/skills/web-src/shared.tsx +226 -0
- package/plugins/context/skills/web-src/skills.html +12 -0
- package/plugins/context/skills/web-src/styles.css +62 -0
- package/plugins/context/skills/web-src/types.ts +85 -0
- package/plugins/context/thinking-intensity/package.json +201 -0
- package/plugins/context/thinking-intensity/src/index.ts +285 -0
- package/plugins/context/thinking-intensity/src/mapping.ts +175 -0
- package/plugins/context/thinking-intensity/src/state.ts +134 -0
- package/plugins/evals/harness/package.json +32 -0
- package/plugins/evals/harness/src/assertions.ts +99 -0
- package/plugins/evals/harness/src/errors.ts +23 -0
- package/plugins/evals/harness/src/index.ts +48 -0
- package/plugins/evals/harness/src/mock-provider.ts +64 -0
- package/plugins/evals/harness/src/plugin.ts +48 -0
- package/plugins/evals/harness/src/report.ts +66 -0
- package/plugins/evals/harness/src/runner.ts +417 -0
- package/plugins/evals/harness/src/suite.ts +352 -0
- package/plugins/evals/harness/src/types.ts +154 -0
- package/plugins/fleet/compose/README.md +40 -0
- package/plugins/fleet/compose/package.json +172 -0
- package/plugins/fleet/compose/src/cli.ts +347 -0
- package/plugins/fleet/compose/src/i18n.ts +99 -0
- package/plugins/fleet/compose/src/index.ts +3 -0
- package/plugins/fleet/compose/src/manifest.ts +194 -0
- package/plugins/im/feishu/FEISHU.md +142 -0
- package/plugins/im/feishu/package.json +33 -0
- package/plugins/im/feishu/src/channel.ts +360 -0
- package/plugins/im/feishu/src/config.ts +133 -0
- package/plugins/im/feishu/src/dedupe.ts +30 -0
- package/plugins/im/feishu/src/errors.ts +21 -0
- package/plugins/im/feishu/src/index.ts +47 -0
- package/plugins/im/feishu/src/messages.ts +41 -0
- package/plugins/im/feishu/src/queue.ts +71 -0
- package/plugins/im/feishu/src/runner.ts +356 -0
- package/plugins/im/feishu/src/sdk-transport.ts +220 -0
- package/plugins/im/feishu/src/text.ts +56 -0
- package/plugins/im/feishu/src/types.ts +150 -0
- package/plugins/marketplace/marketplace/package.json +166 -0
- package/plugins/marketplace/marketplace/registry-template/README.md +105 -0
- package/plugins/marketplace/marketplace/registry-template/index.sample.json +71 -0
- package/plugins/marketplace/marketplace/registry-template/validate.mjs +272 -0
- package/plugins/marketplace/marketplace/registry-template/validate.yml +35 -0
- package/plugins/marketplace/marketplace/src/config-lock.ts +325 -0
- package/plugins/marketplace/marketplace/src/config.ts +432 -0
- package/plugins/marketplace/marketplace/src/errors.ts +79 -0
- package/plugins/marketplace/marketplace/src/index.ts +364 -0
- package/plugins/marketplace/marketplace/src/install.ts +930 -0
- package/plugins/marketplace/marketplace/src/jobs.ts +155 -0
- package/plugins/marketplace/marketplace/src/registry.ts +508 -0
- package/plugins/marketplace/marketplace/src/semver.ts +162 -0
- package/plugins/marketplace/marketplace/src/settings.ts +108 -0
- package/plugins/marketplace/marketplace/src/tar.ts +269 -0
- package/plugins/marketplace/marketplace/tsconfig.ui.json +26 -0
- package/plugins/marketplace/marketplace/vite.config.ts +107 -0
- package/plugins/marketplace/marketplace/web/assets/index-B2V7bx73.css +2 -0
- package/plugins/marketplace/marketplace/web/assets/index-B4NAz59m.js +13 -0
- package/plugins/marketplace/marketplace/web/index.html +13 -0
- package/plugins/marketplace/marketplace/web-src/App.tsx +193 -0
- package/plugins/marketplace/marketplace/web-src/api.ts +153 -0
- package/plugins/marketplace/marketplace/web-src/catalog.ts +27 -0
- package/plugins/marketplace/marketplace/web-src/components/ConfirmDialog.tsx +96 -0
- package/plugins/marketplace/marketplace/web-src/components/InstalledTable.tsx +152 -0
- package/plugins/marketplace/marketplace/web-src/components/JobStatus.tsx +70 -0
- package/plugins/marketplace/marketplace/web-src/components/Permissions.tsx +116 -0
- package/plugins/marketplace/marketplace/web-src/components/RegistryBanners.tsx +22 -0
- package/plugins/marketplace/marketplace/web-src/components/RegistrySetup.tsx +69 -0
- package/plugins/marketplace/marketplace/web-src/components/States.tsx +97 -0
- package/plugins/marketplace/marketplace/web-src/i18n.ts +337 -0
- package/plugins/marketplace/marketplace/web-src/index.html +12 -0
- package/plugins/marketplace/marketplace/web-src/main.tsx +17 -0
- package/plugins/marketplace/marketplace/web-src/styles.css +37 -0
- package/plugins/marketplace/marketplace/web-src/types.ts +175 -0
- package/plugins/marketplace/marketplace/web-src/views/InstalledView.tsx +150 -0
- package/plugins/marketplace/marketplace/web-src/views/MarketplaceView.tsx +479 -0
- package/plugins/marketplace/marketplace/web-src/views/UpdatesView.tsx +207 -0
- package/plugins/marketplace/marketplace/web-src/vite-env.d.ts +1 -0
- package/plugins/mcp/client/package.json +31 -0
- package/plugins/mcp/client/src/config-validate.ts +37 -0
- package/plugins/mcp/client/src/http-transport.ts +369 -0
- package/plugins/mcp/client/src/index.ts +35 -0
- package/plugins/mcp/client/src/json-rpc.ts +104 -0
- package/plugins/mcp/client/src/logging.ts +51 -0
- package/plugins/mcp/client/src/naming.ts +36 -0
- package/plugins/mcp/client/src/plugin.ts +310 -0
- package/plugins/mcp/client/src/registration.ts +143 -0
- package/plugins/mcp/client/src/server-connection.ts +556 -0
- package/plugins/mcp/client/src/stdio-transport.ts +377 -0
- package/plugins/mcp/client/src/transport.ts +11 -0
- package/plugins/mcp/client/src/types.ts +147 -0
- package/plugins/media/media/package.json +33 -0
- package/plugins/media/media/src/binaries.ts +88 -0
- package/plugins/media/media/src/config.ts +184 -0
- package/plugins/media/media/src/exec.ts +172 -0
- package/plugins/media/media/src/index.ts +125 -0
- package/plugins/media/media/src/tool.ts +640 -0
- package/plugins/observability/hook-logging/package.json +31 -0
- package/plugins/observability/hook-logging/src/index.ts +286 -0
- package/plugins/observability/usage/package.json +163 -0
- package/plugins/observability/usage/src/aggregate.ts +919 -0
- package/plugins/observability/usage/src/index.ts +362 -0
- package/plugins/observability/usage/src/query.ts +322 -0
- package/plugins/observability/usage/src/store.ts +1455 -0
- package/plugins/observability/usage/src/worker-client.ts +263 -0
- package/plugins/observability/usage/src/worker.ts +87 -0
- package/plugins/observability/usage/tsconfig.web.json +29 -0
- package/plugins/observability/usage/vite.config.embed.ts +105 -0
- package/plugins/observability/usage/vite.config.ts +121 -0
- package/plugins/observability/usage/web/assets/main-DD4g5VDL.css +2 -0
- package/plugins/observability/usage/web/assets/main-DVmWaf73.js +10 -0
- package/plugins/observability/usage/web/embed/index.css +3 -0
- package/plugins/observability/usage/web/embed/index.mjs +4560 -0
- package/plugins/observability/usage/web/logs.html +13 -0
- package/plugins/observability/usage/web/usage.html +13 -0
- package/plugins/observability/usage/web-src/App.tsx +54 -0
- package/plugins/observability/usage/web-src/LogsView.tsx +505 -0
- package/plugins/observability/usage/web-src/ModelTable.tsx +102 -0
- package/plugins/observability/usage/web-src/UsageView.tsx +210 -0
- package/plugins/observability/usage/web-src/embed.css +96 -0
- package/plugins/observability/usage/web-src/embed.tsx +75 -0
- package/plugins/observability/usage/web-src/env.d.ts +2 -0
- package/plugins/observability/usage/web-src/format.ts +88 -0
- package/plugins/observability/usage/web-src/i18n.ts +261 -0
- package/plugins/observability/usage/web-src/logs.html +12 -0
- package/plugins/observability/usage/web-src/main.tsx +19 -0
- package/plugins/observability/usage/web-src/shared.tsx +187 -0
- package/plugins/observability/usage/web-src/styles.css +22 -0
- package/plugins/observability/usage/web-src/usage.html +12 -0
- package/plugins/provider/anthropic/package.json +31 -0
- package/plugins/provider/anthropic/src/index.ts +75 -0
- package/plugins/provider/anthropic/src/retry.ts +266 -0
- package/plugins/provider/anthropic/src/timeout.ts +84 -0
- package/plugins/provider/model-registry/package.json +167 -0
- package/plugins/provider/model-registry/src/connectivity.ts +123 -0
- package/plugins/provider/model-registry/src/credential-store.ts +219 -0
- package/plugins/provider/model-registry/src/index.ts +453 -0
- package/plugins/provider/model-registry/src/registry-store.ts +223 -0
- package/plugins/provider/model-registry/tsconfig.web.json +29 -0
- package/plugins/provider/model-registry/vite.config.embed.ts +105 -0
- package/plugins/provider/model-registry/vite.config.ts +122 -0
- package/plugins/provider/model-registry/web/assets/main-BofPzD0n.js +10 -0
- package/plugins/provider/model-registry/web/assets/main-DkpGgdsZ.css +2 -0
- package/plugins/provider/model-registry/web/credentials.html +13 -0
- package/plugins/provider/model-registry/web/embed/index.css +3 -0
- package/plugins/provider/model-registry/web/embed/index.mjs +4887 -0
- package/plugins/provider/model-registry/web/models.html +13 -0
- package/plugins/provider/model-registry/web-src/App.tsx +54 -0
- package/plugins/provider/model-registry/web-src/CredentialsView.tsx +357 -0
- package/plugins/provider/model-registry/web-src/ModelForm.tsx +489 -0
- package/plugins/provider/model-registry/web-src/ModelsView.tsx +383 -0
- package/plugins/provider/model-registry/web-src/credentials.html +12 -0
- package/plugins/provider/model-registry/web-src/embed.css +96 -0
- package/plugins/provider/model-registry/web-src/embed.tsx +43 -0
- package/plugins/provider/model-registry/web-src/env.d.ts +2 -0
- package/plugins/provider/model-registry/web-src/i18n.ts +323 -0
- package/plugins/provider/model-registry/web-src/main.tsx +21 -0
- package/plugins/provider/model-registry/web-src/models.html +12 -0
- package/plugins/provider/model-registry/web-src/shared.tsx +147 -0
- package/plugins/provider/model-registry/web-src/styles.css +22 -0
- package/plugins/provider/model-registry/web-src/types.ts +120 -0
- package/plugins/provider/openai/package.json +31 -0
- package/plugins/provider/openai/src/index.ts +104 -0
- package/plugins/provider/openai/src/retry.ts +266 -0
- package/plugins/provider/openai/src/timeout.ts +84 -0
- package/plugins/provider/openai/src/vision.ts +121 -0
- package/plugins/security/guardrail-pii/package.json +31 -0
- package/plugins/security/guardrail-pii/src/index.ts +285 -0
- package/plugins/security/guardrail-pii/src/rules.ts +197 -0
- package/plugins/security/redact-secrets/package.json +31 -0
- package/plugins/security/redact-secrets/src/index.ts +145 -0
- package/plugins/security/redact-secrets/src/redactor.ts +83 -0
- package/plugins/security/redact-secrets/src/rules.ts +137 -0
- package/plugins/security/tool-policy/package.json +31 -0
- package/plugins/security/tool-policy/src/index.ts +184 -0
- package/plugins/tools/basic-tools/package.json +32 -0
- package/plugins/tools/basic-tools/src/background-jobs.ts +356 -0
- package/plugins/tools/basic-tools/src/bash-source.ts +58 -0
- package/plugins/tools/basic-tools/src/call-scope.ts +80 -0
- package/plugins/tools/basic-tools/src/config.ts +130 -0
- package/plugins/tools/basic-tools/src/index.ts +202 -0
- package/plugins/tools/basic-tools/src/path-boundary.ts +258 -0
- package/plugins/tools/basic-tools/src/shared.ts +221 -0
- package/plugins/tools/basic-tools/src/text.ts +49 -0
- package/plugins/tools/basic-tools/src/tools/bash-async.ts +1830 -0
- package/plugins/tools/basic-tools/src/tools/bash-exec.ts +567 -0
- package/plugins/tools/basic-tools/src/tools/bash.ts +300 -0
- package/plugins/tools/basic-tools/src/tools/edit.ts +160 -0
- package/plugins/tools/basic-tools/src/tools/grep.ts +601 -0
- package/plugins/tools/basic-tools/src/tools/read.ts +151 -0
- package/plugins/tools/basic-tools/src/tools/write.ts +494 -0
- package/plugins/tools/basic-tools/src/write-coord.ts +291 -0
- package/plugins/tools/basic-tools/src/write-lock.ts +353 -0
- package/plugins/tools/engine-client/package.json +34 -0
- package/plugins/tools/engine-client/src/client.ts +276 -0
- package/plugins/tools/engine-client/src/forward.ts +164 -0
- package/plugins/tools/engine-client/src/index.ts +18 -0
- package/plugins/tools/engine-client/src/pending.ts +101 -0
- package/plugins/tools/engine-client/src/pool.ts +1173 -0
- package/plugins/tools/engine-client/src/protocol.ts +249 -0
- package/plugins/tools/engine-client/src/registry.ts +138 -0
- package/plugins/tools/file-refs/README.md +68 -0
- package/plugins/tools/file-refs/package.json +135 -0
- package/plugins/tools/file-refs/src/index.ts +24 -0
- package/plugins/tools/file-refs/tsconfig.web.json +27 -0
- package/plugins/tools/file-refs/vite.config.embed.ts +88 -0
- package/plugins/tools/file-refs/web/embed/index.css +3 -0
- package/plugins/tools/file-refs/web/embed/index.mjs +879 -0
- package/plugins/tools/file-refs/web-src/AttachSheet.tsx +613 -0
- package/plugins/tools/file-refs/web-src/FileRefCard.tsx +206 -0
- package/plugins/tools/file-refs/web-src/FileRefLinkCard.tsx +90 -0
- package/plugins/tools/file-refs/web-src/attach-handler.tsx +116 -0
- package/plugins/tools/file-refs/web-src/attach-paths.ts +69 -0
- package/plugins/tools/file-refs/web-src/drop-handler.ts +15 -0
- package/plugins/tools/file-refs/web-src/embed.css +518 -0
- package/plugins/tools/file-refs/web-src/embed.tsx +18 -0
- package/plugins/tools/file-refs/web-src/env.d.ts +2 -0
- package/plugins/tools/file-refs/web-src/i18n.ts +137 -0
- package/plugins/tools/file-refs/web-src/icons.tsx +122 -0
- package/plugins/tools/file-refs/web-src/staging.ts +120 -0
- package/plugins/tools/file-refs/web-src/thumbnail.tsx +36 -0
- package/plugins/tools/recall/package.json +31 -0
- package/plugins/tools/recall/src/config.ts +74 -0
- package/plugins/tools/recall/src/index.ts +151 -0
- package/plugins/tools/recall/src/tool.ts +307 -0
- package/plugins/tools/web-tools/README.md +330 -0
- package/plugins/tools/web-tools/package.json +184 -0
- package/plugins/tools/web-tools/src/backends.ts +61 -0
- package/plugins/tools/web-tools/src/budget.ts +80 -0
- package/plugins/tools/web-tools/src/cache.ts +94 -0
- package/plugins/tools/web-tools/src/config.ts +412 -0
- package/plugins/tools/web-tools/src/deepseek-client.ts +406 -0
- package/plugins/tools/web-tools/src/deepseek-fetch.ts +168 -0
- package/plugins/tools/web-tools/src/extract.ts +373 -0
- package/plugins/tools/web-tools/src/fetch/local.ts +36 -0
- package/plugins/tools/web-tools/src/fetch/provider.ts +56 -0
- package/plugins/tools/web-tools/src/http.ts +415 -0
- package/plugins/tools/web-tools/src/index.ts +649 -0
- package/plugins/tools/web-tools/src/limits.ts +388 -0
- package/plugins/tools/web-tools/src/provider-http.ts +102 -0
- package/plugins/tools/web-tools/src/render.ts +248 -0
- package/plugins/tools/web-tools/src/robots.ts +187 -0
- package/plugins/tools/web-tools/src/search/custom.ts +595 -0
- package/plugins/tools/web-tools/src/search/deepseek.ts +111 -0
- package/plugins/tools/web-tools/src/search/index.ts +725 -0
- package/plugins/tools/web-tools/src/search/provider.ts +200 -0
- package/plugins/tools/web-tools/src/search/serper.ts +157 -0
- package/plugins/tools/web-tools/src/search/tavily.ts +146 -0
- package/plugins/tools/web-tools/src/secrets.ts +87 -0
- package/plugins/tools/web-tools/src/ssrf.ts +287 -0
- package/plugins/tools/web-tools/src/types.ts +137 -0
- package/skills/code-writing.md +33 -0
- package/src/agent/agent-control.ts +409 -0
- package/src/agent/agent-owner-client.ts +150 -0
- package/src/agent/agent-owner-server.ts +689 -0
- package/src/agent/agent-service-wiring.ts +675 -0
- package/src/agent/agent-wiring.ts +48 -0
- package/src/agent/ask-answer-delivery.ts +215 -0
- package/src/agent/local-run-adapter.ts +335 -0
- package/src/agent/peer-notices.ts +459 -0
- package/src/agent/peer-source.ts +63 -0
- package/src/agent/self-card.ts +52 -0
- package/src/agent/team-human-delivery.ts +144 -0
- package/src/assembly/collect.ts +161 -0
- package/src/assembly/feature.ts +133 -0
- package/src/assembly/features/attachments.ts +38 -0
- package/src/assembly/features/fleet.ts +31 -0
- package/src/assembly/features/jobs.ts +32 -0
- package/src/assembly/features/kanban.ts +56 -0
- package/src/assembly/features/restart.ts +35 -0
- package/src/assembly/features/subscription.ts +32 -0
- package/src/assembly/features.ts +30 -0
- package/src/cli/agent-call.ts +107 -0
- package/src/cli/args.ts +551 -0
- package/src/cli/ask-channel.ts +447 -0
- package/src/cli/command-spec/agent.ts +306 -0
- package/src/cli/command-spec/config.ts +179 -0
- package/src/cli/command-spec/define.ts +86 -0
- package/src/cli/command-spec/federation.ts +333 -0
- package/src/cli/command-spec/flags.ts +668 -0
- package/src/cli/command-spec/gateway.ts +350 -0
- package/src/cli/command-spec/hub.ts +290 -0
- package/src/cli/command-spec/kanban.ts +134 -0
- package/src/cli/command-spec/misc.ts +1032 -0
- package/src/cli/command-spec/model.ts +338 -0
- package/src/cli/command-spec/node.ts +160 -0
- package/src/cli/command-spec/plugin.ts +148 -0
- package/src/cli/command-spec/shared.ts +86 -0
- package/src/cli/command-spec/team.ts +582 -0
- package/src/cli/command-spec/token.ts +111 -0
- package/src/cli/command-spec.ts +270 -0
- package/src/cli/command-support.ts +53 -0
- package/src/cli/commands/agent/agent-command.ts +279 -0
- package/src/cli/commands/agent/agent-inbox-command.ts +141 -0
- package/src/cli/commands/agent/agents-command.ts +145 -0
- package/src/cli/commands/attention.ts +896 -0
- package/src/cli/commands/cli-update.ts +283 -0
- package/src/cli/commands/completion-command.ts +29 -0
- package/src/cli/commands/config-command.ts +545 -0
- package/src/cli/commands/dev-command.ts +429 -0
- package/src/cli/commands/doctor-command.ts +873 -0
- package/src/cli/commands/doctor-fleet.ts +410 -0
- package/src/cli/commands/errors-command.ts +469 -0
- package/src/cli/commands/eval-command.ts +168 -0
- package/src/cli/commands/federation-pair.ts +426 -0
- package/src/cli/commands/federation-peer.ts +445 -0
- package/src/cli/commands/federation.ts +527 -0
- package/src/cli/commands/fleet/fleet-inventory.ts +222 -0
- package/src/cli/commands/fleet/fleet-status-command.ts +433 -0
- package/src/cli/commands/fleet/ps-command.ts +387 -0
- package/src/cli/commands/fleet/restart-command.ts +745 -0
- package/src/cli/commands/fleet/start-command.ts +176 -0
- package/src/cli/commands/fleet/status-command.ts +318 -0
- package/src/cli/commands/fleet/stop-command.ts +548 -0
- package/src/cli/commands/gateway/gateway-command.ts +4204 -0
- package/src/cli/commands/gateway/gateway-nodes-command.ts +401 -0
- package/src/cli/commands/hub-command.ts +1007 -0
- package/src/cli/commands/kanban-command.ts +204 -0
- package/src/cli/commands/logs-command.ts +148 -0
- package/src/cli/commands/migrate-command.ts +131 -0
- package/src/cli/commands/model.ts +427 -0
- package/src/cli/commands/node-command.ts +805 -0
- package/src/cli/commands/permission/permission-show-command.ts +189 -0
- package/src/cli/commands/plugin/plugin-cli-command.ts +831 -0
- package/src/cli/commands/plugin/plugin-cli-local.ts +267 -0
- package/src/cli/commands/plugin/plugin-command.ts +407 -0
- package/src/cli/commands/prune-command.ts +233 -0
- package/src/cli/commands/resume-command.ts +100 -0
- package/src/cli/commands/rpc-command.ts +226 -0
- package/src/cli/commands/session/session-status-command.ts +352 -0
- package/src/cli/commands/team-command.ts +722 -0
- package/src/cli/commands/token-command.ts +494 -0
- package/src/cli/commands/trace-command.ts +133 -0
- package/src/cli/completion-script.ts +627 -0
- package/src/cli/completion-spec.ts +101 -0
- package/src/cli/control-plane-target.ts +295 -0
- package/src/cli/control-plane-types.ts +189 -0
- package/src/cli/feishu-command.ts +45 -0
- package/src/cli/headless-runner.ts +354 -0
- package/src/cli/help-search.ts +320 -0
- package/src/cli/help.ts +489 -0
- package/src/cli/output.ts +141 -0
- package/src/cli/parse-engine.ts +701 -0
- package/src/cli/parse-validators.ts +155 -0
- package/src/cli/project.ts +355 -0
- package/src/cli/registry.ts +25 -0
- package/src/cli.ts +2272 -0
- package/src/config/cli-overrides.ts +74 -0
- package/src/config/config-error-format.ts +44 -0
- package/src/config/config-snapshot.ts +15 -0
- package/src/config/config-watch.ts +436 -0
- package/src/config/config-write-apply.ts +98 -0
- package/src/config/empty-response-settings.ts +49 -0
- package/src/config/hot-apply-appliers.ts +527 -0
- package/src/config/hot-apply-assembly.ts +317 -0
- package/src/config/legacy-tool-names.ts +48 -0
- package/src/config/permission-defaults.ts +26 -0
- package/src/config/ui-settings.ts +568 -0
- package/src/config/vision-settings.ts +98 -0
- package/src/data/attachment-ingest.ts +101 -0
- package/src/data/attachment-staging.ts +377 -0
- package/src/data/attachments-list.ts +240 -0
- package/src/data/auto-prune.ts +342 -0
- package/src/data/data-lock.ts +580 -0
- package/src/data/data-paths.ts +265 -0
- package/src/data/image-blob-gc.ts +341 -0
- package/src/data/migrate.ts +480 -0
- package/src/data/path-resolution.ts +172 -0
- package/src/data/permission-store.ts +322 -0
- package/src/data/prune-wiring.ts +1037 -0
- package/src/data/refs-notice-hook.ts +417 -0
- package/src/federation/attention-client.ts +196 -0
- package/src/federation/attention-nodes.ts +142 -0
- package/src/federation/federation-address.ts +276 -0
- package/src/federation/federation-client.ts +620 -0
- package/src/federation/federation-config.ts +222 -0
- package/src/federation/federation-outbox.ts +374 -0
- package/src/federation/federation-pair-store.ts +236 -0
- package/src/federation/federation-pairing.ts +176 -0
- package/src/federation/federation-peer-store.ts +145 -0
- package/src/federation/federation-secrets.ts +140 -0
- package/src/federation/federation-send-port.ts +436 -0
- package/src/gateway/clean-spawn.ts +260 -0
- package/src/gateway/daemon.ts +336 -0
- package/src/gateway/fleet-index.ts +262 -0
- package/src/gateway/gateway-banner.ts +199 -0
- package/src/gateway/gateway-config-control.ts +53 -0
- package/src/gateway/gateway-reload-wiring.ts +512 -0
- package/src/gateway/gateway-wiring.ts +113 -0
- package/src/gateway/handoff.ts +131 -0
- package/src/gateway/instance-lock.ts +244 -0
- package/src/gateway/interactions-dir.ts +27 -0
- package/src/gateway/node-listen.ts +123 -0
- package/src/gateway/node-registry.ts +401 -0
- package/src/gateway/node-supervisor.ts +2226 -0
- package/src/gateway/pid.ts +827 -0
- package/src/gateway/pool-supervisor.ts +1150 -0
- package/src/gateway/reload.ts +238 -0
- package/src/gateway/restart-stop-exemption.ts +43 -0
- package/src/gateway/self-restart.ts +147 -0
- package/src/gateway/serve-auth.ts +184 -0
- package/src/gateway/serve-config.ts +135 -0
- package/src/gateway/service.ts +361 -0
- package/src/gateway/shutdown-report.ts +47 -0
- package/src/gateway/shutdown-sequence.ts +70 -0
- package/src/gateway/stop-drain.ts +299 -0
- package/src/gateway/stop-nodes-marker.ts +151 -0
- package/src/gateway/transport-factory.ts +53 -0
- package/src/gateway/watchdog.ts +622 -0
- package/src/gateway/web-dist.ts +1155 -0
- package/src/hub/client-protocol.ts +43 -0
- package/src/hub/derive-origins.ts +193 -0
- package/src/hub/hub-wiring.ts +310 -0
- package/src/hub/inbound-control.ts +432 -0
- package/src/hub/join-policy.ts +75 -0
- package/src/hub/join-store.ts +243 -0
- package/src/hub/node-credential-store.ts +295 -0
- package/src/hub/node-state.ts +279 -0
- package/src/hub/node-url.ts +33 -0
- package/src/hub/outbound-client.ts +509 -0
- package/src/hub/outbound-wiring.ts +168 -0
- package/src/hub/pairing-code.ts +27 -0
- package/src/hub/registry.ts +575 -0
- package/src/hub/runtime.ts +599 -0
- package/src/hub/secret-store.ts +571 -0
- package/src/hub/server.ts +1032 -0
- package/src/hub/snapshot-policy.ts +67 -0
- package/src/hub/types.ts +258 -0
- package/src/i18n/index.ts +94 -0
- package/src/i18n/messages/en.ts +1462 -0
- package/src/i18n/messages/zh-CN.ts +1323 -0
- package/src/mock/scenarios.ts +165 -0
- package/src/node/node-auto-resume.ts +264 -0
- package/src/node/node-drain.ts +520 -0
- package/src/node/node-identity.ts +240 -0
- package/src/node/node-resume.ts +511 -0
- package/src/node/resume-scan.ts +97 -0
- package/src/node/token-derive.ts +504 -0
- package/src/observability/logging.ts +72 -0
- package/src/observability/observability-wiring.ts +82 -0
- package/src/observability/startup-timing.ts +151 -0
- package/src/observability/trace-wiring.ts +250 -0
- package/src/observability/usage-pricing.ts +80 -0
- package/src/plugin/eval-wiring.ts +175 -0
- package/src/plugin/feishu-wiring.ts +250 -0
- package/src/plugin/mcp-wiring.ts +200 -0
- package/src/plugin/plugin-config.ts +491 -0
- package/src/plugin/plugin-host-assembly.ts +448 -0
- package/src/plugin/plugin-lifecycle.ts +130 -0
- package/src/plugin/plugin-loader.ts +788 -0
- package/src/plugin/plugin-manifest.ts +1936 -0
- package/src/plugin/plugin-selection.ts +200 -0
- package/src/plugin/plugin-surface.ts +207 -0
- package/src/plugin/plugin-watch.ts +114 -0
- package/src/rpc/http-client.ts +579 -0
- package/src/rpc/index.ts +34 -0
- package/src/rpc/local-client.ts +55 -0
- package/src/rpc/types.ts +125 -0
- package/src/run/connect-run-wait.ts +544 -0
- package/src/run/durable-wiring.ts +133 -0
- package/src/run/lease-service.ts +510 -0
- package/src/run/run-control.ts +160 -0
- package/src/run/run-record-store-factory.ts +89 -0
- package/src/runtime/agent-activity-watch.ts +335 -0
- package/src/runtime/agent-assembly.ts +818 -0
- package/src/runtime/agent-events-bridge.ts +86 -0
- package/src/runtime/bash-job-delivery.ts +291 -0
- package/src/runtime/bootstrap-connect.ts +644 -0
- package/src/runtime/bootstrap-types.ts +303 -0
- package/src/runtime/bootstrap.ts +1020 -0
- package/src/runtime/bus-source.ts +62 -0
- package/src/runtime/gc-assembly.ts +214 -0
- package/src/runtime/local-rpc-surface.ts +301 -0
- package/src/runtime/model-registry-wiring.ts +653 -0
- package/src/runtime/node-health-watch.ts +484 -0
- package/src/runtime/node-restart.ts +444 -0
- package/src/runtime/process-handlers.ts +164 -0
- package/src/runtime/provider-factory.ts +86 -0
- package/src/runtime/reasoning.ts +47 -0
- package/src/runtime/repl-context.ts +234 -0
- package/src/runtime/runtime-notice-hook.ts +357 -0
- package/src/runtime/runtime-notice.ts +273 -0
- package/src/runtime/session-id.ts +15 -0
- package/src/runtime/shutdown-sequence.ts +429 -0
- package/src/runtime/subscription-mute-bridge.ts +99 -0
- package/src/runtime/subscription-rpc-port.ts +597 -0
- package/src/runtime/team-log-bridge.ts +46 -0
- package/src/runtime/tenant-runtime-factory.ts +1838 -0
- package/src/runtime/thinking-agent-bridge.ts +57 -0
- package/src/runtime/tool-output-env.ts +80 -0
- package/src/runtime/vessel-meta.ts +338 -0
- package/src/session/context-composition.ts +147 -0
- package/src/session/context-ratio-source.ts +165 -0
- package/src/session/context-usage.ts +346 -0
- package/src/session/image-delivery.ts +297 -0
- package/src/session/session-control.ts +135 -0
- package/src/session/session-events.ts +144 -0
- package/src/session/session-factory.ts +73 -0
- package/src/session/session-liveness.ts +405 -0
- package/src/session/session-lock-runtime.ts +64 -0
- package/src/session/session-lock.ts +399 -0
- package/src/session/session-resume.ts +282 -0
- package/src/session/system-context.ts +235 -0
- package/src/session/timeline-dual-write.ts +2129 -0
- package/src/session/timeline-session-log.ts +140 -0
- package/src/shared/port-in-use.ts +27 -0
- package/src/shared/socket-inherit-guard.ts +13 -0
- package/src/shared/version.ts +38 -0
- package/src/tools-engine/engine.ts +286 -0
- package/src/tools-engine/entry.ts +757 -0
- package/src/tools-engine/mcp-engine-wiring.ts +354 -0
- package/src/tools-engine/mcp.ts +324 -0
- package/src/tools-engine/supervisor.ts +234 -0
- package/src/tools-engine/tools-list.ts +148 -0
- package/src/tools-engine/validate.ts +395 -0
- package/src/tools-engine/wiring.ts +88 -0
- package/src/tools-engine/worker.ts +110 -0
- package/src/update/background.ts +64 -0
- package/src/update/cache.ts +70 -0
- package/src/update/check.ts +138 -0
- package/src/update/gateway-check.ts +231 -0
- package/src/update/install-detect.ts +125 -0
- package/src/update/manifest.ts +132 -0
- package/src/update/semver.ts +70 -0
- package/src/update/stage.ts +219 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vessel-agent/media - 单个 `media` 工具
|
|
3
|
+
* @module @vessel-agent/media/tool
|
|
4
|
+
*
|
|
5
|
+
* action = read | view | ocr | describe,path 必填,page / frames 可选。
|
|
6
|
+
* action 可缺省:按 path 扩展名派生(图片→view,PDF/文本→read);ocr / describe 仍须显式。
|
|
7
|
+
* - read:文本直读;PDF 走 pdftotext(按页取,缺 CLI 时明确报错);
|
|
8
|
+
* - view:图片入 blob 池 + 登记附件回执,loop 以带 refs 的 user 消息 surfaced,
|
|
9
|
+
* 多模态主模型**直接看图**(复用 0.56 视觉基座;无需任何外部 CLI);
|
|
10
|
+
* - ocr:图片 OCR 走 tesseract(缺 CLI 时明确报错);
|
|
11
|
+
* - describe:交多模态 bridge(未配置时明确报错,不静默降级)。
|
|
12
|
+
*
|
|
13
|
+
* 约束:路径边界复用 basic-tools 的 evaluatePath / allowed_roots;单文件 20 MiB;
|
|
14
|
+
* 单次输出 32 KiB(超出截断并标注 truncated);page / frames 有上限;
|
|
15
|
+
* 尊重 ctx.signal;所有失败都返回错误字符串,不抛异常(run 不失败)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
19
|
+
import * as os from 'node:os';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import { canonicalPath, evaluatePath, type PathBoundary } from '@vessel-agent/basic-tools';
|
|
22
|
+
import {
|
|
23
|
+
attachToolImages,
|
|
24
|
+
IMAGE_INGEST_MAX_BYTES,
|
|
25
|
+
ingestImageRefs,
|
|
26
|
+
sha8Of,
|
|
27
|
+
type ToolContext,
|
|
28
|
+
type ToolDefinition,
|
|
29
|
+
} from '@vessel-agent/core';
|
|
30
|
+
import type { MediaBackends } from './binaries.js';
|
|
31
|
+
import type { MediaConfig } from './config.js';
|
|
32
|
+
import { runCli } from './exec.js';
|
|
33
|
+
|
|
34
|
+
/** 取消文案(与 basic-tools 同口径) */
|
|
35
|
+
export const CANCELLED_TEXT = '错误:操作已取消(cancelled)。';
|
|
36
|
+
/**
|
|
37
|
+
* 取消判定:单独成函数,避免 TS 因前面的早退把 signal.aborted 窄化成 false 而报
|
|
38
|
+
* 「比较永不成立」。await 之间随时可能 abort,所以调用点仍需复检。
|
|
39
|
+
*/
|
|
40
|
+
function isAborted(signal: AbortSignal | undefined): boolean {
|
|
41
|
+
return signal?.aborted === true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 图片后缀(OCR / describe 支持面) */
|
|
45
|
+
const IMAGE_EXTS: ReadonlySet<string> = new Set([
|
|
46
|
+
'.png',
|
|
47
|
+
'.jpg',
|
|
48
|
+
'.jpeg',
|
|
49
|
+
'.webp',
|
|
50
|
+
'.tif',
|
|
51
|
+
'.tiff',
|
|
52
|
+
'.bmp',
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
/** 后缀到 MIME(describe 传给多模态 bridge) */
|
|
56
|
+
const MIME_BY_EXT: Readonly<Record<string, string>> = {
|
|
57
|
+
'.png': 'image/png',
|
|
58
|
+
'.jpg': 'image/jpeg',
|
|
59
|
+
'.jpeg': 'image/jpeg',
|
|
60
|
+
'.webp': 'image/webp',
|
|
61
|
+
'.tif': 'image/tiff',
|
|
62
|
+
'.tiff': 'image/tiff',
|
|
63
|
+
'.bmp': 'image/bmp',
|
|
64
|
+
'.gif': 'image/gif',
|
|
65
|
+
'.pdf': 'application/pdf',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** 多模态描述请求 */
|
|
69
|
+
export interface DescribeRequest {
|
|
70
|
+
/** 绝对路径 */
|
|
71
|
+
path: string;
|
|
72
|
+
/** 由后缀推断的 MIME(不可信,仅供 bridge 选择处理方式) */
|
|
73
|
+
mime: string;
|
|
74
|
+
/** 文件字节 */
|
|
75
|
+
data: Buffer;
|
|
76
|
+
/** 字节数(= data.byteLength) */
|
|
77
|
+
bytes: number;
|
|
78
|
+
/** 当前 run 的取消信号 */
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 多模态描述桥:由装配层注入(provider 多模态接口)。
|
|
84
|
+
* 缺省不存在 = 未配置多模态模型,describe 明确报错,不降级。
|
|
85
|
+
*/
|
|
86
|
+
export type DescribeBridge = (request: DescribeRequest) => Promise<string>;
|
|
87
|
+
|
|
88
|
+
/** 工具依赖(构造期固定) */
|
|
89
|
+
export interface MediaToolDeps {
|
|
90
|
+
config: MediaConfig;
|
|
91
|
+
boundary: PathBoundary;
|
|
92
|
+
backends: MediaBackends;
|
|
93
|
+
/** 多模态桥;缺省 = 未配置 */
|
|
94
|
+
describe?: DescribeBridge;
|
|
95
|
+
/** CLI 执行器(测试可替换) */
|
|
96
|
+
run?: typeof runCli;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 支持的动作 */
|
|
100
|
+
export type MediaAction = 'read' | 'view' | 'ocr' | 'describe';
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* view 支持的图片后缀(IMAGE_EXTS + gif)。能否真内联取决于主模型视觉后端的
|
|
104
|
+
* formats 闭集(如 openai-compat 收 png/jpeg/gif/webp);不收的格式请求期明确记
|
|
105
|
+
* `unsupported_format`,不静默 —— 这里不替后端猜能力。
|
|
106
|
+
*/
|
|
107
|
+
const VIEW_EXTS: ReadonlySet<string> = new Set([...IMAGE_EXTS, '.gif']);
|
|
108
|
+
|
|
109
|
+
/** 类型守卫:值是否为对象记录 */
|
|
110
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
111
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 只展开开头的 home 前缀标记 */
|
|
115
|
+
function expandHomePrefix(entry: string): string {
|
|
116
|
+
if (entry === '~') return os.homedir();
|
|
117
|
+
if (entry.startsWith('~/') || entry.startsWith(`~${String.fromCharCode(92)}`)) {
|
|
118
|
+
return path.join(os.homedir(), entry.slice(2));
|
|
119
|
+
}
|
|
120
|
+
return entry;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 按配置 cwd 解析输入为绝对路径 */
|
|
124
|
+
function resolveInput(config: MediaConfig, input: string): string {
|
|
125
|
+
return path.resolve(config.cwd, expandHomePrefix(input));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 人类可读的 MiB 文案 */
|
|
129
|
+
function formatMiB(bytes: number): string {
|
|
130
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 按字节上限截断(UTF-8 安全:只切在码点边界之外的部分会被丢弃) */
|
|
134
|
+
export function capOutput(
|
|
135
|
+
text: string,
|
|
136
|
+
maxBytes: number,
|
|
137
|
+
): { text: string; totalBytes: number; truncated: boolean } {
|
|
138
|
+
const buffer = Buffer.from(text, 'utf-8');
|
|
139
|
+
const totalBytes = buffer.byteLength;
|
|
140
|
+
if (totalBytes <= maxBytes) return { text, totalBytes, truncated: false };
|
|
141
|
+
let sliced = buffer.subarray(0, maxBytes).toString('utf-8');
|
|
142
|
+
// 截断可能切在多字节字符中间,尾部替换字符丢掉
|
|
143
|
+
if (sliced.endsWith('\uFFFD')) sliced = sliced.slice(0, -1);
|
|
144
|
+
return { text: sliced, totalBytes, truncated: true };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 截断标注(契约:超出截断并标 truncated) */
|
|
148
|
+
function truncationNote(totalBytes: number, maxBytes: number): string {
|
|
149
|
+
return (
|
|
150
|
+
'\n\n…(输出超过 ' +
|
|
151
|
+
maxBytes +
|
|
152
|
+
' 字节上限,truncated;原始 ' +
|
|
153
|
+
totalBytes +
|
|
154
|
+
' 字节。可用 page / frames 分段读取)'
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 结果统一收口:拼装 + 字节上限 + 截断标注(标注本身也占用预算,总量不超上限) */
|
|
159
|
+
function finalize(parts: readonly string[], config: MediaConfig): string {
|
|
160
|
+
const raw = parts.filter((part) => part !== '').join('\n');
|
|
161
|
+
const budget = config.maxOutputBytes;
|
|
162
|
+
const capped = capOutput(raw, budget);
|
|
163
|
+
if (!capped.truncated) return capped.text;
|
|
164
|
+
|
|
165
|
+
const note = truncationNote(capped.totalBytes, budget);
|
|
166
|
+
const noteBytes = Buffer.byteLength(note, 'utf-8');
|
|
167
|
+
if (budget <= noteBytes) return capped.text;
|
|
168
|
+
const body = capOutput(raw, budget - noteBytes);
|
|
169
|
+
return body.text + note;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 读取数字参数(非有限数返回 undefined,由调用方决定报错还是回落默认) */
|
|
173
|
+
function readIntArg(args: Record<string, unknown>, key: string): number | undefined {
|
|
174
|
+
const value = args[key];
|
|
175
|
+
if (typeof value === 'number' && Number.isFinite(value)) return Math.floor(value);
|
|
176
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
177
|
+
const parsed = Number(value);
|
|
178
|
+
if (Number.isFinite(parsed)) return Math.floor(parsed);
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 解析 page / frames(越界返回错误文案) */
|
|
184
|
+
function parseRange(
|
|
185
|
+
args: Record<string, unknown>,
|
|
186
|
+
config: MediaConfig,
|
|
187
|
+
defaults: { page: number; frames: number },
|
|
188
|
+
): { page: number; frames: number } | { error: string } {
|
|
189
|
+
const page = readIntArg(args, 'page') ?? defaults.page;
|
|
190
|
+
if (!Number.isInteger(page) || page < 1) {
|
|
191
|
+
return { error: '错误:page 必须是不小于 1 的整数(1-based)。' };
|
|
192
|
+
}
|
|
193
|
+
if (page > config.maxPage) {
|
|
194
|
+
return { error: `错误:page 超过上限(${config.maxPage})。` };
|
|
195
|
+
}
|
|
196
|
+
const frames = readIntArg(args, 'frames') ?? defaults.frames;
|
|
197
|
+
if (!Number.isInteger(frames) || frames < 1) {
|
|
198
|
+
return { error: '错误:frames 必须是不小于 1 的整数。' };
|
|
199
|
+
}
|
|
200
|
+
if (frames > config.maxFrames) {
|
|
201
|
+
return { error: `错误:frames 超过上限(${config.maxFrames})。` };
|
|
202
|
+
}
|
|
203
|
+
return { page, frames };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** 路径校验 + stat 的统一结果 */
|
|
207
|
+
type PathCheck =
|
|
208
|
+
| { ok: true; target: string; bytes: number; ext: string }
|
|
209
|
+
| { ok: false; message: string };
|
|
210
|
+
|
|
211
|
+
/** 解析路径并做边界 / 存在性 / 类型 / 体积检查 */
|
|
212
|
+
async function checkPath(rawPath: string, deps: MediaToolDeps): Promise<PathCheck> {
|
|
213
|
+
const input = rawPath.trim();
|
|
214
|
+
if (input === '') return { ok: false, message: '错误:path 不能为空。' };
|
|
215
|
+
|
|
216
|
+
const absolute = resolveInput(deps.config, input);
|
|
217
|
+
const target = canonicalPath(absolute);
|
|
218
|
+
|
|
219
|
+
// 纵深防御:即使调用方绕过 checkPermission,deny 目录仍然拒绝
|
|
220
|
+
const decision = evaluatePath(target, deps.boundary);
|
|
221
|
+
if (decision === 'deny') {
|
|
222
|
+
// 权限可追溯:这是路径策略的拒绝,不是文件不存在;不复述完整路径(入参里已有)。
|
|
223
|
+
return {
|
|
224
|
+
ok: false,
|
|
225
|
+
message:
|
|
226
|
+
'错误:该路径被路径策略拒绝(deny 目录 / denylist),不是文件不存在。改用允许范围内的路径,或由用户调整 deny_paths。',
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let info: Awaited<ReturnType<typeof stat>>;
|
|
231
|
+
try {
|
|
232
|
+
info = await stat(target);
|
|
233
|
+
} catch {
|
|
234
|
+
return { ok: false, message: `错误:文件不存在或无法访问:${input}` };
|
|
235
|
+
}
|
|
236
|
+
if (info.isDirectory()) {
|
|
237
|
+
return { ok: false, message: `错误:${input} 是目录,不是文件。` };
|
|
238
|
+
}
|
|
239
|
+
if (!info.isFile()) {
|
|
240
|
+
return { ok: false, message: `错误:${input} 不是普通文件。` };
|
|
241
|
+
}
|
|
242
|
+
if (info.size > deps.config.maxFileBytes) {
|
|
243
|
+
return {
|
|
244
|
+
ok: false,
|
|
245
|
+
message:
|
|
246
|
+
'错误:文件过大(' +
|
|
247
|
+
formatMiB(info.size) +
|
|
248
|
+
',上限 ' +
|
|
249
|
+
formatMiB(deps.config.maxFileBytes) +
|
|
250
|
+
'):' +
|
|
251
|
+
input +
|
|
252
|
+
'。请先在外部切分 / 压缩,或用 bash 分块处理。',
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return { ok: true, target, bytes: info.size, ext: path.extname(target).toLowerCase() };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** 把 CLI 的失败折成人读错误文案 */
|
|
259
|
+
function cliFailureText(
|
|
260
|
+
label: string,
|
|
261
|
+
result: Awaited<ReturnType<typeof runCli>>,
|
|
262
|
+
config: MediaConfig,
|
|
263
|
+
): string | undefined {
|
|
264
|
+
if (result.aborted) return CANCELLED_TEXT;
|
|
265
|
+
if (result.spawnError !== undefined) {
|
|
266
|
+
return `错误:无法执行 ${label}:${result.spawnError}。`;
|
|
267
|
+
}
|
|
268
|
+
if (result.timedOut) {
|
|
269
|
+
return `错误:${label} 超时(${config.timeoutMs}ms)。`;
|
|
270
|
+
}
|
|
271
|
+
if (result.code !== 0) {
|
|
272
|
+
const detail = result.stderr.trim();
|
|
273
|
+
return `错误:${label} 退出码 ${String(result.code)}${detail === '' ? '。' : `:${detail}`}`;
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** PDF 抽文本(pdftotext) */
|
|
279
|
+
async function readPdf(
|
|
280
|
+
target: string,
|
|
281
|
+
args: Record<string, unknown>,
|
|
282
|
+
deps: MediaToolDeps,
|
|
283
|
+
signal: AbortSignal | undefined,
|
|
284
|
+
): Promise<string> {
|
|
285
|
+
const cli = deps.backends.pdftotext;
|
|
286
|
+
if (cli === undefined) {
|
|
287
|
+
return (
|
|
288
|
+
'错误:read 无法解析 PDF:未找到 pdftotext。' +
|
|
289
|
+
'请安装 poppler-utils(或配置 plugins[].config.pdftotext 指向可执行文件);' +
|
|
290
|
+
'未安装时该插件不注册 media 工具。'
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
const range = parseRange(args, deps.config, { page: 1, frames: 1 });
|
|
294
|
+
if ('error' in range) return range.error;
|
|
295
|
+
|
|
296
|
+
const lastPage = range.page + range.frames - 1;
|
|
297
|
+
const run = deps.run ?? runCli;
|
|
298
|
+
const result = await run(
|
|
299
|
+
cli,
|
|
300
|
+
['-f', String(range.page), '-l', String(lastPage), '-enc', 'UTF-8', '-layout', target, '-'],
|
|
301
|
+
{ signal, timeoutMs: deps.config.timeoutMs, maxBytes: deps.config.maxOutputBytes },
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const failure = cliFailureText('pdftotext', result, deps.config);
|
|
305
|
+
if (failure !== undefined) return failure;
|
|
306
|
+
|
|
307
|
+
// pdftotext 用换页符分隔页;去掉尾部换页符避免看起来像多一页
|
|
308
|
+
const body = result.stdout.replace(/\f+$/u, '').trimEnd();
|
|
309
|
+
const pages = result.stdout.split('\f').filter((page) => page.trim() !== '').length;
|
|
310
|
+
const header =
|
|
311
|
+
target +
|
|
312
|
+
'(PDF 第 ' +
|
|
313
|
+
String(range.page) +
|
|
314
|
+
(range.frames > 1 ? `-${String(lastPage)}` : '') +
|
|
315
|
+
' 页,本次有文本 ' +
|
|
316
|
+
String(pages) +
|
|
317
|
+
' 页)';
|
|
318
|
+
|
|
319
|
+
if (body.trim() === '') {
|
|
320
|
+
return (
|
|
321
|
+
'(' +
|
|
322
|
+
target +
|
|
323
|
+
':第 ' +
|
|
324
|
+
String(range.page) +
|
|
325
|
+
(range.frames > 1 ? `-${String(lastPage)}` : '') +
|
|
326
|
+
' 页没有可抽取的文本,可能是扫描件或超出页数。可试 action=ocr 或调整 page。)'
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
return finalize([header, '----', body], deps.config);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** 文本直读 */
|
|
333
|
+
async function readText(target: string, bytes: number, deps: MediaToolDeps): Promise<string> {
|
|
334
|
+
let buffer: Buffer;
|
|
335
|
+
try {
|
|
336
|
+
buffer = await readFile(target);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
return `错误:读取失败:${String(error)}`;
|
|
339
|
+
}
|
|
340
|
+
const head = buffer.subarray(0, Math.min(buffer.byteLength, 8192));
|
|
341
|
+
if (head.includes(0)) {
|
|
342
|
+
return (
|
|
343
|
+
'错误:' +
|
|
344
|
+
target +
|
|
345
|
+
' 看起来是二进制文件(含 NUL 字节),read 只处理文本;' +
|
|
346
|
+
'图片请用 action=view(直接给模型看)/ ocr / describe,PDF 会自动走 pdftotext。'
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
const text = buffer.toString('utf-8');
|
|
350
|
+
return finalize([`${target}(文本,${String(bytes)} 字节)`, '----', text], deps.config);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 图片 surfaced(view):入 blob 池 + 登记附件回执,模型原生看图。
|
|
355
|
+
*
|
|
356
|
+
* 字节经 core `ingestImageRefs` 落内容寻址 blob(上传即落,请求期只读冻结副本),
|
|
357
|
+
* 回执经 `attachToolImages` 登记 → 管道认领 → loop 在本批工具结果后追加一条带 refs
|
|
358
|
+
* 的 user 消息 → 视觉基座请求期内联。**全程只有引用进上下文,字节不进 Message。**
|
|
359
|
+
*
|
|
360
|
+
* 是否真内联取决于主模型视觉能力 / kill switch / 预算(事实由 image.sent /
|
|
361
|
+
* context.image_dropped 事件表达);这里不声称「模型一定看到了」。
|
|
362
|
+
*/
|
|
363
|
+
async function runView(
|
|
364
|
+
target: string,
|
|
365
|
+
ext: string,
|
|
366
|
+
deps: MediaToolDeps,
|
|
367
|
+
ctx: ToolContext,
|
|
368
|
+
): Promise<string> {
|
|
369
|
+
if (!VIEW_EXTS.has(ext)) {
|
|
370
|
+
return (
|
|
371
|
+
'错误:action=view 只处理图片(' +
|
|
372
|
+
[...VIEW_EXTS].join(' / ') +
|
|
373
|
+
'):' +
|
|
374
|
+
target +
|
|
375
|
+
'。PDF 请用 action=read,文本直读也是 action=read。'
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
if (isAborted(ctx.signal)) return CANCELLED_TEXT;
|
|
379
|
+
|
|
380
|
+
const mime = MIME_BY_EXT[ext] ?? 'application/octet-stream';
|
|
381
|
+
// 边界判定与 checkPath 同一套(纵深防御);入池上限 8 MiB 与视觉后端单图上限同档。
|
|
382
|
+
const ingest = await ingestImageRefs(
|
|
383
|
+
[{ kind: 'image', path: target, mime, name: path.basename(target) }],
|
|
384
|
+
{ allowPath: (entry) => evaluatePath(entry, deps.boundary) },
|
|
385
|
+
);
|
|
386
|
+
if (isAborted(ctx.signal)) return CANCELLED_TEXT;
|
|
387
|
+
|
|
388
|
+
const ref = ingest.refs[0];
|
|
389
|
+
if (ref === undefined || ref.sha256 === undefined) {
|
|
390
|
+
const detail = ingest.notes.join(';');
|
|
391
|
+
return (
|
|
392
|
+
'错误:图片未能入池,无法作为附件加入上下文' +
|
|
393
|
+
(detail === '' ? '。' : `:${detail}。`) +
|
|
394
|
+
`单图入池上限 ${formatMiB(IMAGE_INGEST_MAX_BYTES)};超限请先压缩。` +
|
|
395
|
+
'也可改用 action=ocr / action=describe(按本机后端可用性)。'
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
attachToolImages(ctx, [ref]);
|
|
400
|
+
const header = `${target}(view,${mime},${String(ref.bytes ?? 0)} 字节,sha256 ${sha8Of(ref.sha256)})`;
|
|
401
|
+
const note =
|
|
402
|
+
'图片已作为附件加入上下文(随下一条 user 消息 surfaced):主模型具备视觉能力时即可直接看到本图,' +
|
|
403
|
+
'无需再读。是否内联以 image.sent / context.image_dropped 事件为准;' +
|
|
404
|
+
'未内联(无视觉 / 超预算 / 格式不收)时可改用 action=ocr / action=describe。';
|
|
405
|
+
return finalize([header, '----', note], deps.config);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** 图片 OCR(tesseract) */
|
|
409
|
+
async function runOcr(
|
|
410
|
+
target: string,
|
|
411
|
+
ext: string,
|
|
412
|
+
args: Record<string, unknown>,
|
|
413
|
+
deps: MediaToolDeps,
|
|
414
|
+
signal: AbortSignal | undefined,
|
|
415
|
+
): Promise<string> {
|
|
416
|
+
const cli = deps.backends.tesseract;
|
|
417
|
+
if (cli === undefined) {
|
|
418
|
+
return (
|
|
419
|
+
'错误:action=ocr 需要 tesseract,但未在 PATH 中找到。' +
|
|
420
|
+
'请安装 tesseract-ocr(或配置 plugins[].config.tesseract 指向可执行文件);' +
|
|
421
|
+
'未安装时该插件不注册 media 工具。'
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
if (!IMAGE_EXTS.has(ext)) {
|
|
425
|
+
return (
|
|
426
|
+
'错误:action=ocr 只处理图片(' +
|
|
427
|
+
[...IMAGE_EXTS].join(' / ') +
|
|
428
|
+
'):' +
|
|
429
|
+
target +
|
|
430
|
+
'。PDF 请用 action=read,其他格式请用 action=describe。'
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
const range = parseRange(args, deps.config, { page: 1, frames: deps.config.maxFrames });
|
|
434
|
+
if ('error' in range) return range.error;
|
|
435
|
+
|
|
436
|
+
const cliArgs = [target, 'stdout'];
|
|
437
|
+
if (deps.config.ocrLanguage !== undefined) cliArgs.push('-l', deps.config.ocrLanguage);
|
|
438
|
+
|
|
439
|
+
const run = deps.run ?? runCli;
|
|
440
|
+
const result = await run(cli, cliArgs, {
|
|
441
|
+
signal,
|
|
442
|
+
timeoutMs: deps.config.timeoutMs,
|
|
443
|
+
maxBytes: deps.config.maxOutputBytes,
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
const failure = cliFailureText('tesseract', result, deps.config);
|
|
447
|
+
if (failure !== undefined) return failure;
|
|
448
|
+
|
|
449
|
+
// 多页 TIFF:按换页符切页,frames 限制取前 N 页
|
|
450
|
+
const pages = result.stdout.split('\f');
|
|
451
|
+
const sliced = pages.slice(0, range.frames).join('\f').trim();
|
|
452
|
+
const header =
|
|
453
|
+
target +
|
|
454
|
+
'(OCR' +
|
|
455
|
+
(deps.config.ocrLanguage !== undefined ? `,语言 ${deps.config.ocrLanguage}` : '') +
|
|
456
|
+
')';
|
|
457
|
+
if (sliced === '') {
|
|
458
|
+
return `(${target}:tesseract 未识别到文本(图片可能是纯色 / 无文字,或语言包缺失)。)`;
|
|
459
|
+
}
|
|
460
|
+
return finalize([header, '----', sliced], deps.config);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** 多模态描述 */
|
|
464
|
+
async function runDescribe(
|
|
465
|
+
target: string,
|
|
466
|
+
ext: string,
|
|
467
|
+
bytes: number,
|
|
468
|
+
deps: MediaToolDeps,
|
|
469
|
+
signal: AbortSignal | undefined,
|
|
470
|
+
): Promise<string> {
|
|
471
|
+
const bridge = deps.describe;
|
|
472
|
+
if (bridge === undefined || !deps.backends.describe) {
|
|
473
|
+
return (
|
|
474
|
+
'错误:action=describe 需要多模态 provider,当前未配置(不会降级为 OCR / 纯文本)。' +
|
|
475
|
+
'请先配置多模态模型,或改用 action=ocr / action=read。'
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (!IMAGE_EXTS.has(ext)) {
|
|
479
|
+
return (
|
|
480
|
+
'错误:action=describe 当前只支持图片(' +
|
|
481
|
+
[...IMAGE_EXTS].join(' / ') +
|
|
482
|
+
'):' +
|
|
483
|
+
target +
|
|
484
|
+
'。PDF 请用 action=read。'
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
if (isAborted(signal)) return CANCELLED_TEXT;
|
|
488
|
+
|
|
489
|
+
let data: Buffer;
|
|
490
|
+
try {
|
|
491
|
+
data = await readFile(target);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
return `错误:读取失败:${String(error)}`;
|
|
494
|
+
}
|
|
495
|
+
const mime = MIME_BY_EXT[ext] ?? 'application/octet-stream';
|
|
496
|
+
try {
|
|
497
|
+
const described = await bridge({ path: target, mime, data, bytes, signal });
|
|
498
|
+
const header = `${target}(describe,${mime},${String(bytes)} 字节)`;
|
|
499
|
+
return finalize([header, '----', described], deps.config);
|
|
500
|
+
} catch (error) {
|
|
501
|
+
if (isAborted(signal)) return CANCELLED_TEXT;
|
|
502
|
+
return `错误:describe 调用失败:${String(error)}`;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** 当前后端支持的动作集合(未支持的动作不进 schema) */
|
|
507
|
+
export function supportedActions(deps: MediaToolDeps): MediaAction[] {
|
|
508
|
+
// view 不需要任何外部后端(入池 + refs surfaced,模型原生视觉),恒可用。
|
|
509
|
+
const actions: MediaAction[] = ['read', 'view'];
|
|
510
|
+
if (deps.backends.tesseract !== undefined) actions.push('ocr');
|
|
511
|
+
if (deps.describe !== undefined && deps.backends.describe) actions.push('describe');
|
|
512
|
+
return actions;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** 动作描述(把已探测到的后端如实写进 schema) */
|
|
516
|
+
function describeActions(actions: readonly MediaAction[], deps: MediaToolDeps): string {
|
|
517
|
+
const notes: string[] = [];
|
|
518
|
+
if (actions.includes('read')) {
|
|
519
|
+
notes.push(
|
|
520
|
+
deps.backends.pdftotext !== undefined
|
|
521
|
+
? 'read=text files and PDF (pdftotext detected)'
|
|
522
|
+
: 'read=text files; PDF is unavailable on this host (pdftotext not detected)',
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
if (actions.includes('view')) {
|
|
526
|
+
notes.push('view=attach image to the calling model context (native vision, no CLI needed)');
|
|
527
|
+
}
|
|
528
|
+
if (actions.includes('ocr')) notes.push('ocr=image OCR via tesseract');
|
|
529
|
+
if (actions.includes('describe')) notes.push('describe=multimodal provider');
|
|
530
|
+
return notes.join('; ');
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** 构造 media 工具 */
|
|
534
|
+
export function createMediaTool(deps: MediaToolDeps): ToolDefinition {
|
|
535
|
+
const actions = supportedActions(deps);
|
|
536
|
+
|
|
537
|
+
return {
|
|
538
|
+
name: 'media',
|
|
539
|
+
description:
|
|
540
|
+
'Read one local attachment (image / PDF / text) referenced by the user. ' +
|
|
541
|
+
'Actions: ' +
|
|
542
|
+
describeActions(actions, deps) +
|
|
543
|
+
'. For images prefer action=view: the image is attached to the model context and you see it directly. ' +
|
|
544
|
+
'When action is omitted it defaults to view for images and read for PDF/text; ocr/describe must be explicit. ' +
|
|
545
|
+
'PDF text is paged via page/frames; output is truncated at ' +
|
|
546
|
+
String(deps.config.maxOutputBytes) +
|
|
547
|
+
' bytes (marked truncated). Prefer this over bash cat on binary files.',
|
|
548
|
+
inputSchema: {
|
|
549
|
+
type: 'object',
|
|
550
|
+
properties: {
|
|
551
|
+
action: {
|
|
552
|
+
type: 'string',
|
|
553
|
+
enum: actions,
|
|
554
|
+
description:
|
|
555
|
+
'read | view | ocr | describe (default: derived from path extension — image→view, pdf/text→read; ocr/describe must be explicit)',
|
|
556
|
+
},
|
|
557
|
+
path: {
|
|
558
|
+
type: 'string',
|
|
559
|
+
description: 'Absolute (or cwd-relative) path of the attachment',
|
|
560
|
+
},
|
|
561
|
+
page: {
|
|
562
|
+
type: 'number',
|
|
563
|
+
description: `First page to read (1-based, PDF only; max ${String(deps.config.maxPage)})`,
|
|
564
|
+
},
|
|
565
|
+
frames: {
|
|
566
|
+
type: 'number',
|
|
567
|
+
description:
|
|
568
|
+
'How many pages/frames to take from page (max ' +
|
|
569
|
+
String(deps.config.maxFrames) +
|
|
570
|
+
'; read=PDF pages, ocr=multi-page TIFF pages)',
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
required: ['path'],
|
|
574
|
+
},
|
|
575
|
+
display: { label: 'Media', kind: 'file' },
|
|
576
|
+
// 只读解析;deny 目录硬拒,配置 allowed_roots 后越界 ask
|
|
577
|
+
concurrencySafe: true,
|
|
578
|
+
checkPermission: async (input) => {
|
|
579
|
+
if (!isRecord(input)) return 'allow';
|
|
580
|
+
const raw = input.path;
|
|
581
|
+
if (typeof raw !== 'string' || raw.trim() === '') return 'allow';
|
|
582
|
+
return evaluatePath(resolveInput(deps.config, raw.trim()), deps.boundary);
|
|
583
|
+
},
|
|
584
|
+
handler: async (args: unknown, ctx: ToolContext): Promise<string> => {
|
|
585
|
+
const signal = ctx.signal;
|
|
586
|
+
if (isAborted(signal)) return CANCELLED_TEXT;
|
|
587
|
+
if (!isRecord(args)) return '错误:media 需要 { path }。';
|
|
588
|
+
|
|
589
|
+
// action 可缺省(按扩展名派生,见 checkPath 之后);显式给值时仍按原样校验。
|
|
590
|
+
const action = args.action;
|
|
591
|
+
if (
|
|
592
|
+
action !== undefined &&
|
|
593
|
+
action !== 'read' &&
|
|
594
|
+
action !== 'view' &&
|
|
595
|
+
action !== 'ocr' &&
|
|
596
|
+
action !== 'describe'
|
|
597
|
+
) {
|
|
598
|
+
return '错误:action 必须是 read / view / ocr / describe。';
|
|
599
|
+
}
|
|
600
|
+
if (action !== undefined && !actions.includes(action)) {
|
|
601
|
+
if (action === 'ocr') {
|
|
602
|
+
return (
|
|
603
|
+
'错误:action=ocr 不可用(本机未探测到 tesseract)。' +
|
|
604
|
+
'安装 tesseract-ocr 后重启进程即可启用。'
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
if (action === 'describe') {
|
|
608
|
+
return (
|
|
609
|
+
'错误:action=describe 不可用(未配置多模态 provider,不会降级)。' +
|
|
610
|
+
'请改用 action=ocr / action=read。'
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const rawPath = args.path;
|
|
616
|
+
if (typeof rawPath !== 'string' || rawPath.trim() === '') {
|
|
617
|
+
return '错误:path 必填且不能为空。';
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const checked = await checkPath(rawPath, deps);
|
|
621
|
+
if (!checked.ok) return checked.message;
|
|
622
|
+
if (isAborted(signal)) return CANCELLED_TEXT;
|
|
623
|
+
|
|
624
|
+
// 缺省派生:图片→view(模型直接看图),PDF/文本→read。read/view 恒可用,
|
|
625
|
+
// 派生结果不会落到需要外部后端的 ocr/describe(那两个必须显式给)。
|
|
626
|
+
const resolved: MediaAction = action ?? (VIEW_EXTS.has(checked.ext) ? 'view' : 'read');
|
|
627
|
+
if (resolved === 'read') {
|
|
628
|
+
if (checked.ext === '.pdf') return readPdf(checked.target, args, deps, signal);
|
|
629
|
+
return readText(checked.target, checked.bytes, deps);
|
|
630
|
+
}
|
|
631
|
+
if (resolved === 'view') {
|
|
632
|
+
return runView(checked.target, checked.ext, deps, ctx);
|
|
633
|
+
}
|
|
634
|
+
if (resolved === 'ocr') {
|
|
635
|
+
return runOcr(checked.target, checked.ext, args, deps, signal);
|
|
636
|
+
}
|
|
637
|
+
return runDescribe(checked.target, checked.ext, checked.bytes, deps, signal);
|
|
638
|
+
},
|
|
639
|
+
};
|
|
640
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vessel-agent/hook-logging",
|
|
3
|
+
"version": "2.3.0-beta.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/egg-rolls/Vessel.git",
|
|
17
|
+
"directory": "plugins/observability/hook-logging"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"bun": ">=1.3.9"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@vessel-agent/core": "workspace:*"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^7.0.2"
|
|
30
|
+
}
|
|
31
|
+
}
|