@octopi-agent/engine 0.102.10 → 0.121.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +6 -2
- package/dist/config-admin/index.js +3 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +71 -0
- package/dist/config-admin/onboarding-apply.js +235 -0
- package/dist/config-admin/onboarding.d.ts +154 -0
- package/dist/config-admin/onboarding.js +270 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +5 -1
- package/dist/config-schema/agent.js +20 -2
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +6 -3
- package/dist/config-schema/engine.d.ts +86 -7
- package/dist/config-schema/engine.js +9 -2
- package/dist/config-schema/governance.d.ts +12 -1
- package/dist/config-schema/governance.js +10 -2
- package/dist/config-schema/models.d.ts +12 -8
- package/dist/config-schema/models.js +16 -1
- package/dist/config-schema/run.d.ts +4 -0
- package/dist/config-schema/run.js +10 -0
- package/dist/config-schema/shared.d.ts +1 -0
- package/dist/config-schema/shared.js +4 -2
- package/dist/config-schema/substrate.d.ts +5 -0
- package/dist/config-schema/substrate.js +8 -0
- package/dist/config.d.ts +116 -10
- package/dist/config.js +109 -13
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +4 -0
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +119 -28
- package/dist/harness/activation/types.d.ts +19 -2
- package/dist/harness/agent/builder.d.ts +12 -0
- package/dist/harness/agent/builder.js +78 -22
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +15 -3
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
- package/dist/harness/agent/wire-agent-builder.js +9 -2
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
- package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +34 -2
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +9 -4
- package/dist/harness/collaboration/delegation/service.js +33 -12
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +1 -0
- package/dist/harness/collaboration/delegation/types.d.ts +11 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +1 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
- package/dist/harness/context/capabilities/compact/engine.js +127 -39
- package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
- package/dist/harness/context/capabilities/compact/index.js +1 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
- package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.js +8 -1
- package/dist/harness/context/default-context-engine.d.ts +100 -6
- package/dist/harness/context/default-context-engine.js +382 -89
- package/dist/harness/context/index.d.ts +2 -1
- package/dist/harness/context/index.js +1 -0
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +57 -0
- package/dist/harness/context/layer-types.js +73 -1
- package/dist/harness/context/layers.d.ts +3 -0
- package/dist/harness/context/layers.js +13 -6
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.js +18 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +5 -2
- package/dist/harness/context/tool-result-aging.d.ts +104 -16
- package/dist/harness/context/tool-result-aging.js +211 -57
- package/dist/harness/context/types.d.ts +71 -4
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +5 -3
- package/dist/harness/index.js +2 -2
- package/dist/harness/knowledge/boot-config.d.ts +2 -0
- package/dist/harness/knowledge/boot-config.js +2 -0
- package/dist/harness/knowledge/client.d.ts +53 -7
- package/dist/harness/knowledge/client.js +77 -20
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +107 -41
- package/dist/harness/knowledge/engine-thread.js +5 -7
- package/dist/harness/knowledge/grounding.js +4 -1
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +82 -21
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
- package/dist/harness/knowledge/query-service.d.ts +12 -2
- package/dist/harness/knowledge/query-service.js +75 -41
- package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -1
- package/dist/harness/knowledge/query-worker.js +5 -3
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +9 -2
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +6 -1
- package/dist/harness/knowledge/serve.js +5 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +297 -71
- package/dist/harness/knowledge/start-service-process.d.ts +27 -8
- package/dist/harness/knowledge/start-service-process.js +49 -90
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/writer-service.d.ts +18 -2
- package/dist/harness/knowledge/writer-service.js +80 -16
- package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
- package/dist/harness/knowledge/writer-worker-client.js +20 -3
- package/dist/harness/knowledge/writer-worker.js +11 -4
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/types.d.ts +18 -2
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +95 -2
- package/dist/harness/run/agent/agent.js +3 -2
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/reliability/run-agent.d.ts +22 -0
- package/dist/harness/run/reliability/run-agent.js +79 -10
- package/dist/harness/run/run-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +11 -0
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +149 -22
- package/dist/harness/run/runner.js +352 -35
- package/dist/harness/session/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/types.d.ts +10 -14
- package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
- package/dist/harness/shared/types/agent-definition.d.ts +6 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +27 -2
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +41 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +56 -2
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +14 -2
- package/dist/integration/storage/archive-manager.js +24 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +9 -0
- package/dist/integration/storage/jsonl.js +137 -38
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +5 -3
package/dist/config.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { ToolPolicy } from '@octopi-agent/core/types.js';
|
|
6
6
|
import type { ModelConfig as _ModelConfig } from './harness/shared/types/agent-definition.js';
|
|
7
7
|
import type { ModelProvider } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
8
|
+
import type { BrowserStealthConfig } from './harness/extension/plugin-ecosystem/tools/browser-types.js';
|
|
8
9
|
import { DEFAULT_CONTEXT_WINDOW } from '@octopi-agent/core/types/model-info.js';
|
|
9
10
|
/** 产品默认上下文窗口(与 core/types/model-info 一致,未声明能力时按此预算) */
|
|
10
11
|
export { DEFAULT_CONTEXT_WINDOW };
|
|
@@ -88,6 +89,10 @@ export interface AgentConfig {
|
|
|
88
89
|
export type KnowledgeRecallMode = 'off' | 'hint' | 'hybrid' | 'inject';
|
|
89
90
|
/** Knowledge 全局配置(agents[].knowledge 覆盖 recall 等) */
|
|
90
91
|
export interface KnowledgeRuntimeConfig {
|
|
92
|
+
/** 跨租户共享闸(B-5):allowPublic 缺省 false=禁止创建 visibility='public' 项目 */
|
|
93
|
+
projects?: {
|
|
94
|
+
allowPublic?: boolean;
|
|
95
|
+
};
|
|
91
96
|
/** Knowledge Service 连接(v2:Gateway 不打开 knowledge.db);对齐 KnowledgeConfigSchema */
|
|
92
97
|
service?: {
|
|
93
98
|
baseUrl?: string;
|
|
@@ -232,12 +237,59 @@ export interface WebSearchToolConfig {
|
|
|
232
237
|
/** provider 映射 */
|
|
233
238
|
providers?: Record<string, WebSearchProviderSlot>;
|
|
234
239
|
}
|
|
240
|
+
/** browser_* 工具顶层配置(arch/browser-capability.md §3.8) */
|
|
241
|
+
export interface BrowserToolConfig {
|
|
242
|
+
/** 工具面注册开关(缺省 true = 拍板默认开) */
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
/** 后端引擎(auto = playwright;stealth = 隐身链;rebrowser / camoufox = 单后端直钉) */
|
|
245
|
+
engine?: 'auto' | 'playwright' | 'stealth' | 'rebrowser' | 'camoufox' | 'cdp-attach' | 'cloud';
|
|
246
|
+
/** attach 端点(engine=cdp-attach 用;缺省 http://127.0.0.1:9222) */
|
|
247
|
+
attach?: {
|
|
248
|
+
endpoint?: string;
|
|
249
|
+
};
|
|
250
|
+
/** 持久 profile(P2;storageState 归档于 OCTOPI_HOME/browser-profiles) */
|
|
251
|
+
profiles?: {
|
|
252
|
+
persist?: boolean;
|
|
253
|
+
defaultProfile?: string;
|
|
254
|
+
};
|
|
255
|
+
/** 浏览器来源:chromium(管理版)| chrome(系统 Chrome) */
|
|
256
|
+
channel?: 'chromium' | 'chrome';
|
|
257
|
+
headless?: boolean;
|
|
258
|
+
/** 工具/动作超时(毫秒,默认 30000) */
|
|
259
|
+
timeoutMs?: number;
|
|
260
|
+
/** 快照序列化预算(字符,默认 8000) */
|
|
261
|
+
snapshotMaxChars?: number;
|
|
262
|
+
/** 会话空闲回收(毫秒;<=0 不回收;缺省 1800000 = 30 分钟) */
|
|
263
|
+
sessionIdleTimeoutMs?: number;
|
|
264
|
+
viewport?: {
|
|
265
|
+
width: number;
|
|
266
|
+
height: number;
|
|
267
|
+
};
|
|
268
|
+
locale?: string;
|
|
269
|
+
network?: {
|
|
270
|
+
/** 域名 allow/deny(deny 优先;`*.suffix` 通配;缺省无限制) */
|
|
271
|
+
domains?: {
|
|
272
|
+
allow?: string[];
|
|
273
|
+
deny?: string[];
|
|
274
|
+
};
|
|
275
|
+
/** 私网/环回放行(缺省 false) */
|
|
276
|
+
allowPrivateNetwork?: boolean;
|
|
277
|
+
};
|
|
278
|
+
/** stealth(P3):fallback 链由服务层消费;humanize 透传工具层 */
|
|
279
|
+
stealth?: BrowserStealthConfig;
|
|
280
|
+
/**
|
|
281
|
+
* 敏感动作确认闸门三档(2026-11-20 拍板):
|
|
282
|
+
* `strict` = 所有非 GET 过闸(含页内 fetch/XHR);`standard`(缺省)= 仅文档级
|
|
283
|
+
* (表单提交/密码/上传);`off` = 全放开。
|
|
284
|
+
*/
|
|
285
|
+
confirm?: 'strict' | 'standard' | 'off';
|
|
286
|
+
}
|
|
235
287
|
/**
|
|
236
288
|
* Session 配置(合并了旧的 store + session 节点)
|
|
237
289
|
*/
|
|
238
290
|
export interface SessionConfig {
|
|
239
|
-
/** DM 作用域: main / per-peer / per-channel-peer */
|
|
240
|
-
dmScope?: 'main' | 'per-peer' | 'per-channel-peer';
|
|
291
|
+
/** DM 作用域: main / per-peer / per-channel-peer / per-conversation */
|
|
292
|
+
dmScope?: 'main' | 'per-peer' | 'per-channel-peer' | 'per-conversation';
|
|
241
293
|
/**
|
|
242
294
|
* 上下文租约(毫秒)。**显式配置才生效**;缺省关闭。
|
|
243
295
|
*
|
|
@@ -246,6 +298,13 @@ export interface SessionConfig {
|
|
|
246
298
|
*/
|
|
247
299
|
idleExpiryMs?: number;
|
|
248
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Tenancy 配置 — 多租户渠道锚定策略(arch/multi-tenancy.md §9)
|
|
303
|
+
*/
|
|
304
|
+
export interface TenancyConfig {
|
|
305
|
+
/** 未绑定流量兜底:`fallback`(默认,存量首 agent)| `reject`(拒收,日志明示) */
|
|
306
|
+
unboundChannelPolicy?: 'fallback' | 'reject';
|
|
307
|
+
}
|
|
249
308
|
/**
|
|
250
309
|
* Plugin 配置
|
|
251
310
|
*/
|
|
@@ -270,6 +329,13 @@ export interface PluginConfig {
|
|
|
270
329
|
* - 具体 IP / 主机名:绑定该地址
|
|
271
330
|
*/
|
|
272
331
|
export type NetworkHostConfig = 'local' | 'lan' | (string & {});
|
|
332
|
+
/**
|
|
333
|
+
* 判定 listen 地址是否仅回环可达(B-1:无钥告警分级依据——非回环 = 网络敞开)
|
|
334
|
+
*
|
|
335
|
+
* @param host - `resolveListenHost` 解析后的 listen 地址
|
|
336
|
+
* @returns 是否回环(127/8 · ::1 · localhost)
|
|
337
|
+
*/
|
|
338
|
+
export declare function isLoopbackListenHost(host: string): boolean;
|
|
273
339
|
/**
|
|
274
340
|
* 将 host 配置解析为 HTTP listen 地址
|
|
275
341
|
*
|
|
@@ -295,8 +361,10 @@ export declare function isLanHost(host?: NetworkHostConfig): boolean;
|
|
|
295
361
|
* Channel 配置
|
|
296
362
|
*/
|
|
297
363
|
export interface ChannelConfig {
|
|
298
|
-
/**
|
|
299
|
-
type
|
|
364
|
+
/** 内置通道类型(http);与 plugin 二选一(恰好其一) */
|
|
365
|
+
type?: string;
|
|
366
|
+
/** 插件 Channel 贡献 id(manifest contributes.channels);与 type 二选一 */
|
|
367
|
+
plugin?: string;
|
|
300
368
|
/** 端口(HTTP channel 用) */
|
|
301
369
|
port?: number;
|
|
302
370
|
/**
|
|
@@ -307,10 +375,17 @@ export interface ChannelConfig {
|
|
|
307
375
|
host?: NetworkHostConfig;
|
|
308
376
|
/** 路径(HTTP channel 用) */
|
|
309
377
|
path?: string;
|
|
310
|
-
/** API Key(HTTP channel
|
|
378
|
+
/** API Key(HTTP channel 认证;插件通道的凭证通道,推荐 `${ENV_VAR}` 引用) */
|
|
311
379
|
apiKey?: string;
|
|
380
|
+
/**
|
|
381
|
+
* bot 凭证归属租户(arch/multi-tenancy.md §9 Q11=a 渠道锚定):
|
|
382
|
+
* 消息进入先按此定租户,再查 bindings 表路由。缺省 = DEFAULT_TENANT_ID(存量域)。
|
|
383
|
+
*/
|
|
384
|
+
tenantId?: string;
|
|
312
385
|
/** 允许的 CORS 源 */
|
|
313
386
|
corsOrigins?: string[];
|
|
387
|
+
/** 插件自定义旋钮(非密钥;原样透传) */
|
|
388
|
+
options?: Record<string, unknown>;
|
|
314
389
|
}
|
|
315
390
|
/**
|
|
316
391
|
* BudgetPolicyJsonConfig — octopi.json 中的 budgetPolicy 字段
|
|
@@ -675,12 +750,19 @@ export interface ModelProviderConfig {
|
|
|
675
750
|
baseUrl: string;
|
|
676
751
|
/** API Key(支持 ${ENV_VAR} 语法);省略/空 = 不发鉴权(keyless) */
|
|
677
752
|
apiKey?: string;
|
|
678
|
-
/** API
|
|
679
|
-
api
|
|
753
|
+
/** API 协议类型;与 plugin 二选一(恰好设置其一) */
|
|
754
|
+
api?: 'openai-completions' | 'anthropic-messages';
|
|
755
|
+
/** 插件 Provider 贡献 id(manifest contributes.providers);与 api 二选一 */
|
|
756
|
+
plugin?: string;
|
|
680
757
|
/** 此 provider 下的模型列表 */
|
|
681
758
|
models: ModelCapability[];
|
|
682
759
|
/** 请求超时(秒) */
|
|
683
760
|
timeoutSeconds?: number;
|
|
761
|
+
/**
|
|
762
|
+
* 插件自定义旋钮(按 contributes.providers 契约由插件自行校验)。
|
|
763
|
+
* 仅放非密钥配置;密钥只走 apiKey(credential 通道),出现在此处视为配置错误。
|
|
764
|
+
*/
|
|
765
|
+
options?: Record<string, unknown>;
|
|
684
766
|
}
|
|
685
767
|
/** 模型级别定义(primary + fallback 降级链) */
|
|
686
768
|
export interface LevelConfig {
|
|
@@ -804,6 +886,10 @@ export interface HarnessConfig {
|
|
|
804
886
|
plugins?: PluginConfig;
|
|
805
887
|
/** Run 安全阀 / 策略(budgetPolicy;无默认 token hard) */
|
|
806
888
|
budgetPolicy?: BudgetPolicyJsonConfig;
|
|
889
|
+
/** fleet 期望状态播种(P0c Q3=A;arch/service-topology-p0c.md §4.1) */
|
|
890
|
+
fleet?: {
|
|
891
|
+
replicasPerVersion?: number;
|
|
892
|
+
};
|
|
807
893
|
/** 过程监督配置(行为监督;与 budget 组合) */
|
|
808
894
|
runGuard?: RunGuardJsonConfig;
|
|
809
895
|
/** 模型调用 watchdog 超时(modelCall 段) */
|
|
@@ -878,6 +964,8 @@ export interface HarnessConfig {
|
|
|
878
964
|
identity?: {
|
|
879
965
|
mergeThreshold?: number;
|
|
880
966
|
candidateBandHi?: number;
|
|
967
|
+
semanticSeedMaxDistance?: number;
|
|
968
|
+
semanticSeedEmbedTimeoutMs?: number;
|
|
881
969
|
};
|
|
882
970
|
capacity?: {
|
|
883
971
|
stopNodes?: number;
|
|
@@ -936,6 +1024,8 @@ export interface HarnessConfig {
|
|
|
936
1024
|
channels?: ChannelConfig[];
|
|
937
1025
|
/** Session 配置 */
|
|
938
1026
|
session?: SessionConfig;
|
|
1027
|
+
/** 多租户渠道锚定策略(arch/multi-tenancy.md §9) */
|
|
1028
|
+
tenancy?: TenancyConfig;
|
|
939
1029
|
/**
|
|
940
1030
|
* 工具效应隔离策略(宪法 I5)
|
|
941
1031
|
*
|
|
@@ -1005,6 +1095,8 @@ export interface HarnessConfig {
|
|
|
1005
1095
|
};
|
|
1006
1096
|
/** 网络搜索配置(web_search 工具) */
|
|
1007
1097
|
webSearch?: WebSearchToolConfig;
|
|
1098
|
+
/** 浏览器操作配置(browser_* 工具;缺省默认开) */
|
|
1099
|
+
browser?: BrowserToolConfig;
|
|
1008
1100
|
/** Web UI 运行配置 */
|
|
1009
1101
|
web?: {
|
|
1010
1102
|
/** Web UI 源码目录(含 package.json);未设置时按 CLI 内置顺序探测 */
|
|
@@ -1092,17 +1184,31 @@ export declare function createWireDumpSinkFromConfig(cfg?: import('./integration
|
|
|
1092
1184
|
/**
|
|
1093
1185
|
* 从 ModelProviderConfig 创建 ModelProvider 实例
|
|
1094
1186
|
*
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1187
|
+
* `api` 选择内置适配器(OpenAI / Anthropic);`plugin` 路由到插件 Provider 工厂。
|
|
1188
|
+
* 两者恰好设置其一。使用动态 import 以支持 ESM。
|
|
1097
1189
|
*
|
|
1098
1190
|
* @param name - provider 名称
|
|
1099
1191
|
* @param pc - provider 配置
|
|
1100
|
-
* @param options - 可选:wire dump sink(诊断用,见 `observability.llmRequestDump
|
|
1192
|
+
* @param options - 可选:wire dump sink(诊断用,见 `observability.llmRequestDump`);
|
|
1193
|
+
* `resolvePluginProvider` 解析插件 Provider 工厂(`pc.plugin` 必需)
|
|
1101
1194
|
* @returns provider 实例(wire dump → 原生 provider 的装饰链;LLM 计时已 observability 化进 model.call.*)
|
|
1102
1195
|
*/
|
|
1103
1196
|
export declare function createProviderFromConfig(name: string, pc: ModelProviderConfig, options?: {
|
|
1104
1197
|
wireDump?: import('./integration/providers/wire-dump.js').WireDumpSink;
|
|
1198
|
+
resolvePluginProvider?: (ref: string) => import('./harness/extension/plugin-ecosystem/plugins/contribution-registry.js').PluginProviderRecord | undefined;
|
|
1105
1199
|
}): Promise<ModelProvider>;
|
|
1200
|
+
/**
|
|
1201
|
+
* 从 `channels[]` 配置条目创建插件 Channel Adapter。
|
|
1202
|
+
*
|
|
1203
|
+
* `plugin` 路由到插件 Channel 工厂(`contributes.channels` 命名贡献);
|
|
1204
|
+
* 内置 `type: 'http'` 由 daemon 的 HttpChannelAdapter 装配,不走本函数。
|
|
1205
|
+
* 与 `createProviderFromConfig` 同闸:type | plugin 恰好其一,工厂是第二道闸。
|
|
1206
|
+
*
|
|
1207
|
+
* @param entry - channels[] 配置条目
|
|
1208
|
+
* @param resolvePluginChannel - 解析插件 Channel 工厂(`entry.plugin` 必需)
|
|
1209
|
+
* @returns ChannelAdapter 实例(最小契约校验,name 硬绑定贡献 id)
|
|
1210
|
+
*/
|
|
1211
|
+
export declare function createChannelAdapterFromConfig(entry: ChannelConfig, resolvePluginChannel: (ref: string) => import('./harness/extension/plugin-ecosystem/plugins/contribution-registry.js').PluginChannelRecord | undefined): Promise<import('./harness/extension/plugin-ecosystem/channel-types.js').ChannelAdapter>;
|
|
1106
1212
|
/**
|
|
1107
1213
|
* 按 `observability` 配置构造 RunTelemetry 工厂(F3/D5 接线,组合根)
|
|
1108
1214
|
*
|
package/dist/config.js
CHANGED
|
@@ -2,6 +2,15 @@ import { getRunScope } from './harness/run/run-scope.js';
|
|
|
2
2
|
import { DEFAULT_CONTEXT_WINDOW } from '@octopi-agent/core/types/model-info.js';
|
|
3
3
|
/** 产品默认上下文窗口(与 core/types/model-info 一致,未声明能力时按此预算) */
|
|
4
4
|
export { DEFAULT_CONTEXT_WINDOW };
|
|
5
|
+
/**
|
|
6
|
+
* 判定 listen 地址是否仅回环可达(B-1:无钥告警分级依据——非回环 = 网络敞开)
|
|
7
|
+
*
|
|
8
|
+
* @param host - `resolveListenHost` 解析后的 listen 地址
|
|
9
|
+
* @returns 是否回环(127/8 · ::1 · localhost)
|
|
10
|
+
*/
|
|
11
|
+
export function isLoopbackListenHost(host) {
|
|
12
|
+
return /^(127\.\d{1,3}\.\d{1,3}\.\d{1,3}|::1|localhost)$/i.test(host.trim());
|
|
13
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* 将 host 配置解析为 HTTP listen 地址
|
|
7
16
|
*
|
|
@@ -54,7 +63,8 @@ export function flattenModels(config) {
|
|
|
54
63
|
result.push({
|
|
55
64
|
id: `${providerName}/${mc.id}`,
|
|
56
65
|
provider: providerName,
|
|
57
|
-
|
|
66
|
+
// 请求模型字段 = 目录 id;`name` 是纯展示名,绝不进请求(曾被误当 model 发出 → API 400)
|
|
67
|
+
model: mc.id,
|
|
58
68
|
contextWindow: mc.contextWindow,
|
|
59
69
|
maxTokens: mc.maxTokens,
|
|
60
70
|
});
|
|
@@ -184,24 +194,33 @@ export async function createWireDumpSinkFromConfig(cfg) {
|
|
|
184
194
|
/**
|
|
185
195
|
* 从 ModelProviderConfig 创建 ModelProvider 实例
|
|
186
196
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
197
|
+
* `api` 选择内置适配器(OpenAI / Anthropic);`plugin` 路由到插件 Provider 工厂。
|
|
198
|
+
* 两者恰好设置其一。使用动态 import 以支持 ESM。
|
|
189
199
|
*
|
|
190
200
|
* @param name - provider 名称
|
|
191
201
|
* @param pc - provider 配置
|
|
192
|
-
* @param options - 可选:wire dump sink(诊断用,见 `observability.llmRequestDump
|
|
202
|
+
* @param options - 可选:wire dump sink(诊断用,见 `observability.llmRequestDump`);
|
|
203
|
+
* `resolvePluginProvider` 解析插件 Provider 工厂(`pc.plugin` 必需)
|
|
193
204
|
* @returns provider 实例(wire dump → 原生 provider 的装饰链;LLM 计时已 observability 化进 model.call.*)
|
|
194
205
|
*/
|
|
195
206
|
export async function createProviderFromConfig(name, pc, options) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
207
|
+
if ((pc.api === undefined) === (pc.plugin === undefined)) {
|
|
208
|
+
throw new Error(`Provider "${name}": exactly one of api | plugin must be set`);
|
|
209
|
+
}
|
|
210
|
+
const models = pc.models.map((m) => {
|
|
211
|
+
const entry = { name: m.name ?? m.id };
|
|
212
|
+
if (m.contextWindow !== undefined)
|
|
213
|
+
entry.contextWindow = m.contextWindow;
|
|
214
|
+
if (m.maxTokens !== undefined)
|
|
215
|
+
entry.maxOutputTokens = m.maxTokens;
|
|
216
|
+
if (m.temperature !== undefined)
|
|
217
|
+
entry.temperature = m.temperature;
|
|
218
|
+
if (m.reasoning !== undefined)
|
|
219
|
+
entry.reasoning = m.reasoning;
|
|
220
|
+
if (m.input !== undefined)
|
|
221
|
+
entry.input = m.input;
|
|
222
|
+
return entry;
|
|
223
|
+
});
|
|
205
224
|
const defaultModel = pc.models[0]?.name ?? pc.models[0]?.id;
|
|
206
225
|
let decorate = (inner) => inner;
|
|
207
226
|
if (options?.wireDump) {
|
|
@@ -211,6 +230,39 @@ export async function createProviderFromConfig(name, pc, options) {
|
|
|
211
230
|
const sink = options.wireDump;
|
|
212
231
|
decorate = (inner) => withWireDump(inner, sink);
|
|
213
232
|
}
|
|
233
|
+
if (pc.plugin !== undefined) {
|
|
234
|
+
const record = options?.resolvePluginProvider?.(pc.plugin);
|
|
235
|
+
if (!record) {
|
|
236
|
+
throw new Error(`Provider "${name}": plugin provider "${pc.plugin}" is not registered (plugin disabled, failed, or not discovered)`);
|
|
237
|
+
}
|
|
238
|
+
const built = await record.factory({
|
|
239
|
+
providerName: name,
|
|
240
|
+
baseUrl: pc.baseUrl,
|
|
241
|
+
apiKey: pc.apiKey ?? '',
|
|
242
|
+
models,
|
|
243
|
+
...(defaultModel === undefined ? {} : { defaultModel }),
|
|
244
|
+
...(pc.timeoutSeconds === undefined ? {} : { timeoutMs: pc.timeoutSeconds * 1000 }),
|
|
245
|
+
options: pc.options ?? {},
|
|
246
|
+
});
|
|
247
|
+
// 最小契约校验 + name 绑定:工厂结果必须挂在配置键下,
|
|
248
|
+
// 否则 gateway 按 provider.name 注册会挂到错误的名字上
|
|
249
|
+
for (const method of ['chat', 'stream', 'isAvailable']) {
|
|
250
|
+
if (typeof built?.[method] !== 'function') {
|
|
251
|
+
throw new Error(`Provider "${name}": plugin provider "${pc.plugin}" factory returned an invalid ModelProvider (missing ${method})`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (built.name !== name) {
|
|
255
|
+
throw new Error(`Provider "${name}": plugin provider "${pc.plugin}" factory returned provider.name "${built.name}"; it must equal the config key "${name}"`);
|
|
256
|
+
}
|
|
257
|
+
// 出生 = 宿主验收:校验通过后登记工厂产物本身(先于 decorate——wire-dump
|
|
258
|
+
// 副本的 dispose 转发链要闭合到退役标记上)。查询返回产物,插件私有方法
|
|
259
|
+
// 只存在于产物上;宿主路由可能经装饰副本(仅 SPI 成员)转发到它。
|
|
260
|
+
if (record.acceptInstance && !record.acceptInstance(built, name)) {
|
|
261
|
+
console.warn(`Provider "${name}": plugin provider instance cannot be retirement-tracked (frozen/sealed); contribution lookup will report it as never instantiated`);
|
|
262
|
+
}
|
|
263
|
+
return decorate(built);
|
|
264
|
+
}
|
|
265
|
+
const apiType = pc.api === 'anthropic-messages' ? 'anthropic' : 'openai';
|
|
214
266
|
if (apiType === 'anthropic') {
|
|
215
267
|
const { AnthropicProvider } = await import('./integration/providers/anthropic.js');
|
|
216
268
|
return decorate(new AnthropicProvider({ name, apiKey: pc.apiKey ?? '', baseUrl: pc.baseUrl, models, defaultModel, timeoutMs: pc.timeoutSeconds ? pc.timeoutSeconds * 1000 : undefined }));
|
|
@@ -218,6 +270,50 @@ export async function createProviderFromConfig(name, pc, options) {
|
|
|
218
270
|
const { OpenAIProvider } = await import('./integration/providers/openai.js');
|
|
219
271
|
return decorate(new OpenAIProvider({ name, apiKey: pc.apiKey ?? '', baseUrl: pc.baseUrl, models, defaultModel, timeoutMs: pc.timeoutSeconds ? pc.timeoutSeconds * 1000 : undefined }));
|
|
220
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* 从 `channels[]` 配置条目创建插件 Channel Adapter。
|
|
275
|
+
*
|
|
276
|
+
* `plugin` 路由到插件 Channel 工厂(`contributes.channels` 命名贡献);
|
|
277
|
+
* 内置 `type: 'http'` 由 daemon 的 HttpChannelAdapter 装配,不走本函数。
|
|
278
|
+
* 与 `createProviderFromConfig` 同闸:type | plugin 恰好其一,工厂是第二道闸。
|
|
279
|
+
*
|
|
280
|
+
* @param entry - channels[] 配置条目
|
|
281
|
+
* @param resolvePluginChannel - 解析插件 Channel 工厂(`entry.plugin` 必需)
|
|
282
|
+
* @returns ChannelAdapter 实例(最小契约校验,name 硬绑定贡献 id)
|
|
283
|
+
*/
|
|
284
|
+
export async function createChannelAdapterFromConfig(entry, resolvePluginChannel) {
|
|
285
|
+
if ((entry.type === undefined) === (entry.plugin === undefined)) {
|
|
286
|
+
throw new Error('Channel: exactly one of type | plugin must be set');
|
|
287
|
+
}
|
|
288
|
+
if (entry.plugin === undefined) {
|
|
289
|
+
throw new Error(`Channel type "${entry.type}" has no built-in adapter (built-ins: http); use "plugin" for plugin channels`);
|
|
290
|
+
}
|
|
291
|
+
const ref = entry.plugin;
|
|
292
|
+
const record = resolvePluginChannel(ref);
|
|
293
|
+
if (!record) {
|
|
294
|
+
throw new Error(`Channel "${ref}": plugin channel "${ref}" is not registered (plugin disabled, failed, or not discovered)`);
|
|
295
|
+
}
|
|
296
|
+
const built = await record.factory({
|
|
297
|
+
channelName: ref,
|
|
298
|
+
apiKey: entry.apiKey ?? '',
|
|
299
|
+
options: entry.options ?? {},
|
|
300
|
+
});
|
|
301
|
+
// 最小契约校验 + name 绑定:工厂结果必须挂在贡献 id 下,
|
|
302
|
+
// 否则 gateway 按 adapter.name 注册、回复按 msg.channel 路由都会错位
|
|
303
|
+
for (const member of ['start', 'send', 'stop']) {
|
|
304
|
+
if (typeof built?.[member] !== 'function') {
|
|
305
|
+
throw new Error(`Channel "${ref}": plugin channel factory returned an invalid ChannelAdapter (missing ${member})`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (built.name !== ref) {
|
|
309
|
+
throw new Error(`Channel "${ref}": plugin channel factory returned adapter.name "${built.name}"; it must equal the contribution id "${ref}"`);
|
|
310
|
+
}
|
|
311
|
+
// 出生 = 宿主验收:校验通过后登记实例,与 provider 同语义
|
|
312
|
+
if (record.acceptInstance && !record.acceptInstance(built, ref)) {
|
|
313
|
+
console.warn(`Channel "${ref}": plugin channel instance cannot be retirement-tracked (frozen); contribution lookup will report it as never instantiated`);
|
|
314
|
+
}
|
|
315
|
+
return built;
|
|
316
|
+
}
|
|
221
317
|
/**
|
|
222
318
|
* 按 `observability` 配置构造 RunTelemetry 工厂(F3/D5 接线,组合根)
|
|
223
319
|
*
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 平台能力探测 + 秘密文件的真实权限收紧。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么不能只靠 `mode: 0o600`
|
|
5
|
+
*
|
|
6
|
+
* `statSync(path).mode & 0o777` 在 Windows 上恒报 `0o666` 形态,与 `writeFile` 的
|
|
7
|
+
* `mode`、`chmodSync` 都无关——所以「用 mode 保护秘密文件」在 Windows 上**完全不生效**。
|
|
8
|
+
* 实测:`writeFileSync(f, '{"apiKey":"sk-..."}', {mode:0o600})` 之后,`f` 的 ACL 仍是
|
|
9
|
+
* 从父目录继承来的一串主体(含一个可修改的用户组与多个可读写 SID)。也就是说秘密
|
|
10
|
+
* 文件的保护面完全由**它落在哪个目录**决定。
|
|
11
|
+
*
|
|
12
|
+
* ## 因此这里的契约是「收紧,而不是请求」
|
|
13
|
+
*
|
|
14
|
+
* - POSIX:`chmod` 就是真实生效的收紧。
|
|
15
|
+
* - Windows:改成 ACL——`icacls <target> /inheritance:r /grant:r "<user>:F"`,移除
|
|
16
|
+
* 继承并只授予当前用户。实测收紧后目录为 `user:(OI)(CI)(F)`、其中新建文件自动继承
|
|
17
|
+
* `user:(I)(F)`,不再有其他主体。
|
|
18
|
+
*
|
|
19
|
+
* 收紧失败时**不留文件**:一个已知不安全的秘密文件比没有文件更糟(调用方拿到的是
|
|
20
|
+
* "写成功"的假象)。`writeSecretFileSync` 会删掉已写内容再抛错。
|
|
21
|
+
*
|
|
22
|
+
* ## 平台判断为什么集中在这里
|
|
23
|
+
*
|
|
24
|
+
* 生产侧(`plugin doctor`、boot 文件写入)与测试侧(权限断言)必须同一口径,否则会
|
|
25
|
+
* 各自漂移——`plugin doctor` 曾因在 Windows 上判 `mode & 0o077` 而对每个 state 目录
|
|
26
|
+
* 误报告警。
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* 当前平台是否支持 POSIX 文件权限位(Windows 不支持)。
|
|
30
|
+
*
|
|
31
|
+
* 注意这是**平台能力**而非"平台名":判断放在这里而不是散落 `process.platform === 'win32'`,
|
|
32
|
+
* 是为了让生产侧与测试侧用同一个口径。
|
|
33
|
+
*/
|
|
34
|
+
export declare const POSIX_FILE_MODE: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* 把目标收紧到「仅当前用户可访问」。
|
|
37
|
+
*
|
|
38
|
+
* @param target - 文件或目录路径
|
|
39
|
+
* @param kind - `dir` 用继承形式授权(`(OI)(CI)`),使其中新建的文件自动安全
|
|
40
|
+
* @throws 当无法收紧时抛出(调用方不得把它当作可忽略的告警)
|
|
41
|
+
*/
|
|
42
|
+
export declare function restrictToOwner(target: string, kind: 'file' | 'dir'): void;
|
|
43
|
+
/**
|
|
44
|
+
* 创建仅当前用户可访问的临时目录。
|
|
45
|
+
*
|
|
46
|
+
* 秘密文件应放这里而非直接平铺在共享 tmpdir:目录收紧后,其中新建文件自动继承安全
|
|
47
|
+
* ACL,等于在创建时就消除了暴露窗口。
|
|
48
|
+
*
|
|
49
|
+
* @param prefix - 目录名前缀(便于诊断)
|
|
50
|
+
* @returns 私有临时目录的绝对路径
|
|
51
|
+
*/
|
|
52
|
+
export declare function createPrivateTempDir(prefix: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* 同步写入秘密文件,并把权限真实收紧到仅当前用户。
|
|
55
|
+
*
|
|
56
|
+
* 与 `writeFileSync(..., {mode: 0o600})` 的区别:后者在 Windows 上不生效。
|
|
57
|
+
*
|
|
58
|
+
* 三步走(写 tmp → 收紧 tmp → rename)而不是直接写目标:目标可能已存在且是**有效**的
|
|
59
|
+
* 旧秘密(例如上一轮签发的 setup token)。直接写再收紧的话,一旦收紧失败就得删文件,
|
|
60
|
+
* 等于把旧秘密一起毁掉。这个顺序同时消除了「写完成 → 收紧完成」之间的暴露窗口;
|
|
61
|
+
* 同卷 rename 不会重新继承 ACL(实测 Windows 上收紧后的 ACL 完整保留)。
|
|
62
|
+
*
|
|
63
|
+
* @param filePath - 目标路径(父目录应当已经是私有的,见 {@link createPrivateTempDir})
|
|
64
|
+
* @param data - 文件内容
|
|
65
|
+
* @throws 当权限无法收紧时(此时目标文件保持原状,临时文件已删除)
|
|
66
|
+
*/
|
|
67
|
+
export declare function writeSecretFileSync(filePath: string, data: string): void;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 平台能力探测 + 秘密文件的真实权限收紧。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么不能只靠 `mode: 0o600`
|
|
5
|
+
*
|
|
6
|
+
* `statSync(path).mode & 0o777` 在 Windows 上恒报 `0o666` 形态,与 `writeFile` 的
|
|
7
|
+
* `mode`、`chmodSync` 都无关——所以「用 mode 保护秘密文件」在 Windows 上**完全不生效**。
|
|
8
|
+
* 实测:`writeFileSync(f, '{"apiKey":"sk-..."}', {mode:0o600})` 之后,`f` 的 ACL 仍是
|
|
9
|
+
* 从父目录继承来的一串主体(含一个可修改的用户组与多个可读写 SID)。也就是说秘密
|
|
10
|
+
* 文件的保护面完全由**它落在哪个目录**决定。
|
|
11
|
+
*
|
|
12
|
+
* ## 因此这里的契约是「收紧,而不是请求」
|
|
13
|
+
*
|
|
14
|
+
* - POSIX:`chmod` 就是真实生效的收紧。
|
|
15
|
+
* - Windows:改成 ACL——`icacls <target> /inheritance:r /grant:r "<user>:F"`,移除
|
|
16
|
+
* 继承并只授予当前用户。实测收紧后目录为 `user:(OI)(CI)(F)`、其中新建文件自动继承
|
|
17
|
+
* `user:(I)(F)`,不再有其他主体。
|
|
18
|
+
*
|
|
19
|
+
* 收紧失败时**不留文件**:一个已知不安全的秘密文件比没有文件更糟(调用方拿到的是
|
|
20
|
+
* "写成功"的假象)。`writeSecretFileSync` 会删掉已写内容再抛错。
|
|
21
|
+
*
|
|
22
|
+
* ## 平台判断为什么集中在这里
|
|
23
|
+
*
|
|
24
|
+
* 生产侧(`plugin doctor`、boot 文件写入)与测试侧(权限断言)必须同一口径,否则会
|
|
25
|
+
* 各自漂移——`plugin doctor` 曾因在 Windows 上判 `mode & 0o077` 而对每个 state 目录
|
|
26
|
+
* 误报告警。
|
|
27
|
+
*/
|
|
28
|
+
import { execFileSync } from 'node:child_process';
|
|
29
|
+
import { chmodSync, mkdtempSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
30
|
+
import { tmpdir } from 'node:os';
|
|
31
|
+
import { join } from 'node:path';
|
|
32
|
+
/**
|
|
33
|
+
* 当前平台是否支持 POSIX 文件权限位(Windows 不支持)。
|
|
34
|
+
*
|
|
35
|
+
* 注意这是**平台能力**而非"平台名":判断放在这里而不是散落 `process.platform === 'win32'`,
|
|
36
|
+
* 是为了让生产侧与测试侧用同一个口径。
|
|
37
|
+
*/
|
|
38
|
+
export const POSIX_FILE_MODE = process.platform !== 'win32';
|
|
39
|
+
/** `icacls` 收紧要授予的主体(授权目标)。 */
|
|
40
|
+
let cachedPrincipal;
|
|
41
|
+
/**
|
|
42
|
+
* 取当前进程令牌的 SID 作为授权主体。
|
|
43
|
+
*
|
|
44
|
+
* 为什么不用 `USERDOMAIN\USERNAME`:那两个环境变量不是身份权威,且可被父进程污染。
|
|
45
|
+
* 真实失败面包括——服务/计划任务下常缺失;Azure AD 加入的机器上 `USERDOMAIN` 是计算机名,
|
|
46
|
+
* `MACHINE\user` 无法解析(icacls 报 status 1332);同名/改名账户可能解析到他人主体
|
|
47
|
+
* (不报错,但把秘密授权给了错误账户)。SID 与本机域/工作组/AAD/系统语言全部解耦。
|
|
48
|
+
*
|
|
49
|
+
* `whoami` 必须用绝对路径:Windows 上常见 Git Bash 的 coreutils `whoami` 排在 WINPATH 前面,
|
|
50
|
+
* 它不认识 `/user /fo csv`(实测报 `extra operand '/user'`)。
|
|
51
|
+
*
|
|
52
|
+
* @returns 可交给 icacls 的主体;无法确定时返回 null(由调用方决定降级策略)
|
|
53
|
+
*/
|
|
54
|
+
function currentOwnerPrincipal() {
|
|
55
|
+
// 进程内缓存:一个进程的令牌主体不会变,而每次 restrictToOwner 起一个 whoami.exe
|
|
56
|
+
// 是纯浪费(credentials 打开一次最多 4 次调用)。
|
|
57
|
+
if (cachedPrincipal !== undefined)
|
|
58
|
+
return cachedPrincipal;
|
|
59
|
+
cachedPrincipal = resolveOwnerPrincipal();
|
|
60
|
+
return cachedPrincipal;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 解析当前令牌主体(不做缓存)。
|
|
64
|
+
*
|
|
65
|
+
* @returns 可交给 icacls 的主体;无法确定时返回 null(由调用方决定降级策略)
|
|
66
|
+
*/
|
|
67
|
+
function resolveOwnerPrincipal() {
|
|
68
|
+
const whoami = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'whoami.exe');
|
|
69
|
+
try {
|
|
70
|
+
const raw = execFileSync(whoami, ['/user', '/fo', 'csv', '/nh'], {
|
|
71
|
+
encoding: 'utf8',
|
|
72
|
+
windowsHide: true,
|
|
73
|
+
});
|
|
74
|
+
// 形如 `"machine\user","S-1-5-21-..."`
|
|
75
|
+
const sid = raw.trim().replace(/^"|"$/g, '').split('","').pop();
|
|
76
|
+
if (sid && /^S-\d+(-\d+)+$/.test(sid))
|
|
77
|
+
return { form: 'sid', value: sid };
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
/* whoami 不可用:退到名字形式,仍由 icacls 的 exit code 兜底判定成败 */
|
|
81
|
+
}
|
|
82
|
+
const username = process.env.USERNAME ?? '';
|
|
83
|
+
const domain = process.env.USERDOMAIN ?? '';
|
|
84
|
+
if (!username)
|
|
85
|
+
return null;
|
|
86
|
+
// 名字形式只作兜底:工作组下 USERDOMAIN 是机器名,域下是域名,两种都能解析
|
|
87
|
+
return { form: 'name', value: domain ? `${domain}\\${username}` : username };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 把目标收紧到「仅当前用户可访问」。
|
|
91
|
+
*
|
|
92
|
+
* @param target - 文件或目录路径
|
|
93
|
+
* @param kind - `dir` 用继承形式授权(`(OI)(CI)`),使其中新建的文件自动安全
|
|
94
|
+
* @throws 当无法收紧时抛出(调用方不得把它当作可忽略的告警)
|
|
95
|
+
*/
|
|
96
|
+
export function restrictToOwner(target, kind) {
|
|
97
|
+
if (POSIX_FILE_MODE) {
|
|
98
|
+
chmodSync(target, kind === 'dir' ? 0o700 : 0o600);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const owner = currentOwnerPrincipal();
|
|
102
|
+
if (!owner) {
|
|
103
|
+
throw new Error(`[permissions] cannot restrict ${target}: could not determine the current user (whoami unavailable and USERNAME unset)`);
|
|
104
|
+
}
|
|
105
|
+
// icacls 的输出是本地化的,只可信 exit code(非 0 时 execFileSync 会抛)。
|
|
106
|
+
// windowsHide 不可省:否则在无控制台的宿主里又会长出一个控制台窗口。
|
|
107
|
+
// `/inheritance:r /grant:r` 只处理**继承**来的 ACE 与"同一主体"的显式 ACE:目标上若有
|
|
108
|
+
// 别人显式授予的条目(老版本留下的宽松权限正是如此),它会原地留着。实测对
|
|
109
|
+
// `icacls <dir> /grant *S-1-5-32-545:(OI)(CI)R` 造宽过的目录,直接用本函数收紧后
|
|
110
|
+
// `BUILTIN\Users` 仍留在 DACL 上;先 `/reset`(重置为从父继承)再收紧才彻底。
|
|
111
|
+
try {
|
|
112
|
+
execFileSync('icacls', [target, '/reset'], { stdio: 'ignore', windowsHide: true });
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
/* 无法 reset(非 NTFS / 权限不足)时仍尝试下面的收紧;成败由它决定 */
|
|
116
|
+
}
|
|
117
|
+
// `*S-1-5-…` 是「按 SID 授权」的形式(icacls 语法);名字形式不能带 `*`。
|
|
118
|
+
const grantee = owner.form === 'sid' ? `*${owner.value}` : owner.value;
|
|
119
|
+
execFileSync('icacls', [
|
|
120
|
+
target,
|
|
121
|
+
'/inheritance:r',
|
|
122
|
+
'/grant:r',
|
|
123
|
+
kind === 'dir' ? `${grantee}:(OI)(CI)F` : `${grantee}:F`,
|
|
124
|
+
], { stdio: 'ignore', windowsHide: true });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 创建仅当前用户可访问的临时目录。
|
|
128
|
+
*
|
|
129
|
+
* 秘密文件应放这里而非直接平铺在共享 tmpdir:目录收紧后,其中新建文件自动继承安全
|
|
130
|
+
* ACL,等于在创建时就消除了暴露窗口。
|
|
131
|
+
*
|
|
132
|
+
* @param prefix - 目录名前缀(便于诊断)
|
|
133
|
+
* @returns 私有临时目录的绝对路径
|
|
134
|
+
*/
|
|
135
|
+
export function createPrivateTempDir(prefix) {
|
|
136
|
+
const dir = mkdtempSync(join(tmpdir(), prefix));
|
|
137
|
+
try {
|
|
138
|
+
restrictToOwner(dir, 'dir');
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
// 建得出却收紧不了:该目录不能用来放秘密,清掉再抛(不留隐患目录)
|
|
142
|
+
try {
|
|
143
|
+
rmSync(dir, { recursive: true, force: true });
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
/* 清理失败是次要问题:主错误(无法收紧)才是调用方要看到的 */
|
|
147
|
+
}
|
|
148
|
+
throw err;
|
|
149
|
+
}
|
|
150
|
+
return dir;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 同步写入秘密文件,并把权限真实收紧到仅当前用户。
|
|
154
|
+
*
|
|
155
|
+
* 与 `writeFileSync(..., {mode: 0o600})` 的区别:后者在 Windows 上不生效。
|
|
156
|
+
*
|
|
157
|
+
* 三步走(写 tmp → 收紧 tmp → rename)而不是直接写目标:目标可能已存在且是**有效**的
|
|
158
|
+
* 旧秘密(例如上一轮签发的 setup token)。直接写再收紧的话,一旦收紧失败就得删文件,
|
|
159
|
+
* 等于把旧秘密一起毁掉。这个顺序同时消除了「写完成 → 收紧完成」之间的暴露窗口;
|
|
160
|
+
* 同卷 rename 不会重新继承 ACL(实测 Windows 上收紧后的 ACL 完整保留)。
|
|
161
|
+
*
|
|
162
|
+
* @param filePath - 目标路径(父目录应当已经是私有的,见 {@link createPrivateTempDir})
|
|
163
|
+
* @param data - 文件内容
|
|
164
|
+
* @throws 当权限无法收紧时(此时目标文件保持原状,临时文件已删除)
|
|
165
|
+
*/
|
|
166
|
+
export function writeSecretFileSync(filePath, data) {
|
|
167
|
+
const staging = `${filePath}.staging`;
|
|
168
|
+
writeFileSync(staging, data, { encoding: 'utf8', mode: 0o600 });
|
|
169
|
+
try {
|
|
170
|
+
restrictToOwner(staging, 'file');
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
try {
|
|
174
|
+
rmSync(staging, { force: true });
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
/* 删不掉时仍要抛出收紧失败:调用方至少知道有一份未收紧的副本存在 */
|
|
178
|
+
}
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
renameSync(staging, filePath);
|
|
182
|
+
}
|