evolcore 0.0.48 → 0.0.50
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/CHANGELOG.md +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { isIP } from 'node:net';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
3
4
|
import { normalizeProviderDomain, providerIdentity } from './provider-identity.js';
|
|
4
5
|
/** Tokenize model patterns without interpreting regex or filesystem glob syntax. */
|
|
5
6
|
function modelPatternTokens(pattern) {
|
|
@@ -81,6 +82,95 @@ function assertProviderEnvironmentSyntax(value, field) {
|
|
|
81
82
|
throw new Error(`${field} must use a whole-field environment reference ($VAR or \${VAR})`);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
85
|
+
/** Upper bound for one Provider key pool; a longer pool is a misconfiguration, not a failover plan. */
|
|
86
|
+
export const MAX_PROVIDER_API_KEYS = 16;
|
|
87
|
+
/** Ordered pool view of a stored key field; a plain string is a one-key pool. */
|
|
88
|
+
export function providerApiKeyEntries(value) {
|
|
89
|
+
if (value === undefined)
|
|
90
|
+
return [];
|
|
91
|
+
return Array.isArray(value) ? value : [value];
|
|
92
|
+
}
|
|
93
|
+
/** Store a one-key pool as the plain string so legacy files round-trip byte-identically. */
|
|
94
|
+
export function providerApiKeyStoreShape(keys) {
|
|
95
|
+
if (!keys.length)
|
|
96
|
+
return undefined;
|
|
97
|
+
return keys.length === 1 ? keys[0] : keys;
|
|
98
|
+
}
|
|
99
|
+
/** Validate and normalize a key pool on the write path. */
|
|
100
|
+
function providerApiKeyValue(value, field) {
|
|
101
|
+
if (value === undefined)
|
|
102
|
+
return undefined;
|
|
103
|
+
const list = Array.isArray(value) ? value : [value];
|
|
104
|
+
if (!list.length)
|
|
105
|
+
throw new Error(`${field} must contain at least one API key`);
|
|
106
|
+
if (list.length > MAX_PROVIDER_API_KEYS)
|
|
107
|
+
throw new Error(`${field} accepts at most ${MAX_PROVIDER_API_KEYS} API keys`);
|
|
108
|
+
const keys = [];
|
|
109
|
+
for (const entry of list) {
|
|
110
|
+
if (typeof entry !== 'string')
|
|
111
|
+
throw new Error(`${field} must be a string or an array of strings`);
|
|
112
|
+
assertProviderEnvironmentSyntax(entry, field);
|
|
113
|
+
keys.push(entry);
|
|
114
|
+
}
|
|
115
|
+
const seen = new Set();
|
|
116
|
+
for (const key of keys) {
|
|
117
|
+
const normalized = key.trim();
|
|
118
|
+
if (!normalized)
|
|
119
|
+
continue;
|
|
120
|
+
if (seen.has(normalized))
|
|
121
|
+
throw new Error(`${field} contains a duplicate API key`);
|
|
122
|
+
seen.add(normalized);
|
|
123
|
+
}
|
|
124
|
+
return providerApiKeyStoreShape(keys);
|
|
125
|
+
}
|
|
126
|
+
/** Mask every literal key in a pool; environment references stay readable. */
|
|
127
|
+
export function maskProviderApiKey(value, mask) {
|
|
128
|
+
const keys = providerApiKeyEntries(value);
|
|
129
|
+
if (!keys.length)
|
|
130
|
+
return undefined;
|
|
131
|
+
return providerApiKeyStoreShape(keys.map(key => providerEnvironmentVariable(key) ? key : mask));
|
|
132
|
+
}
|
|
133
|
+
/** Restore masked pool entries position by position; a new position must carry a real key. */
|
|
134
|
+
export function retainProviderApiKey(value, previous, mask) {
|
|
135
|
+
if (value === undefined)
|
|
136
|
+
return undefined;
|
|
137
|
+
const old = providerApiKeyEntries(previous);
|
|
138
|
+
const merged = providerApiKeyEntries(value).map((key, index) => {
|
|
139
|
+
if (key !== mask)
|
|
140
|
+
return key;
|
|
141
|
+
const existing = old[index];
|
|
142
|
+
if (existing === undefined)
|
|
143
|
+
throw new Error(`A replacement API key at position ${index + 1} is required`);
|
|
144
|
+
return existing;
|
|
145
|
+
});
|
|
146
|
+
return providerApiKeyStoreShape(merged);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Resolve the ordered pool. The primary stays strict: an unset environment
|
|
150
|
+
* reference there is a broken connection and must fail loudly. A backup that
|
|
151
|
+
* cannot resolve is dropped with a warning so a stale backup never disables a
|
|
152
|
+
* working primary.
|
|
153
|
+
*/
|
|
154
|
+
export function resolveProviderApiKeys(providerId, value, scope) {
|
|
155
|
+
const resolved = [];
|
|
156
|
+
const dropped = [];
|
|
157
|
+
for (const [index, key] of providerApiKeyEntries(value).entries()) {
|
|
158
|
+
if (index === 0) {
|
|
159
|
+
resolved.push(resolveProviderEnvironmentValue(providerId, 'apiKey', key, scope));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
resolved.push(resolveProviderEnvironmentValue(providerId, 'apiKey', key, scope));
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
dropped.push(index + 1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (dropped.length) {
|
|
170
|
+
logger.warn(`[providers] ${providerId} ${scope}.apiKey ignored unresolvable backup key(s) at position ${dropped.join(', ')}`);
|
|
171
|
+
}
|
|
172
|
+
return resolved;
|
|
173
|
+
}
|
|
84
174
|
function resolveProviderEnvironmentValue(providerId, field, value, scope = 'common') {
|
|
85
175
|
const variable = providerEnvironmentVariable(value);
|
|
86
176
|
if (!variable)
|
|
@@ -102,6 +192,13 @@ function validProviderBaseUrl(value) {
|
|
|
102
192
|
return false;
|
|
103
193
|
}
|
|
104
194
|
}
|
|
195
|
+
export function resolveProviderBaseUrl(providerId, value) {
|
|
196
|
+
const baseUrl = resolveProviderEnvironmentValue(providerId, 'baseUrl', value);
|
|
197
|
+
if (!validProviderBaseUrl(baseUrl)) {
|
|
198
|
+
throw new Error(`Provider ${providerId} common.baseUrl must resolve to a valid http(s) URL`);
|
|
199
|
+
}
|
|
200
|
+
return baseUrl;
|
|
201
|
+
}
|
|
105
202
|
export function providerNameFromBaseUrl(baseUrl) {
|
|
106
203
|
const hostname = new URL(baseUrl).hostname.replace(/\.$/u, '');
|
|
107
204
|
if (isIP(hostname.replace(/^\[|\]$/gu, '')))
|
|
@@ -220,12 +317,9 @@ function serviceConfig(value, field, serviceType) {
|
|
|
220
317
|
throw new Error(`${field} must be an object`);
|
|
221
318
|
assertFields(value, ['path', 'catalogPath', 'style', 'models', 'modelPolicy', 'apiKey', 'headers', 'queryParams'], field);
|
|
222
319
|
const result = {};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
assertProviderEnvironmentSyntax(value.apiKey, `${field}.apiKey`);
|
|
227
|
-
result.apiKey = value.apiKey;
|
|
228
|
-
}
|
|
320
|
+
const apiKey = providerApiKeyValue(value.apiKey, `${field}.apiKey`);
|
|
321
|
+
if (apiKey !== undefined)
|
|
322
|
+
result.apiKey = apiKey;
|
|
229
323
|
for (const name of ['headers', 'queryParams']) {
|
|
230
324
|
const values = stringMap(value[name], `${field}.${name}`);
|
|
231
325
|
if (values !== undefined)
|
|
@@ -297,16 +391,13 @@ function providerConfig(value, field) {
|
|
|
297
391
|
}
|
|
298
392
|
const headers = stringMap(common.headers, `${field}.common.headers`);
|
|
299
393
|
const queryParams = stringMap(common.queryParams, `${field}.common.queryParams`);
|
|
300
|
-
|
|
301
|
-
throw new Error(`${field}.common.apiKey must be a string`);
|
|
302
|
-
if (typeof common.apiKey === 'string')
|
|
303
|
-
assertProviderEnvironmentSyntax(common.apiKey, `${field}.common.apiKey`);
|
|
394
|
+
const apiKey = providerApiKeyValue(common.apiKey, `${field}.common.apiKey`);
|
|
304
395
|
const result = {
|
|
305
396
|
...(value.domain !== undefined ? { domain: normalizeProviderDomain(value.domain) } : {}),
|
|
306
397
|
...(typeof value.name === 'string' && value.name.trim() ? { name: value.name.trim() } : {}),
|
|
307
398
|
common: {
|
|
308
399
|
baseUrl,
|
|
309
|
-
...(
|
|
400
|
+
...(apiKey !== undefined ? { apiKey } : {}),
|
|
310
401
|
...(headers ? { headers } : {}),
|
|
311
402
|
...(queryParams ? { queryParams } : {}),
|
|
312
403
|
},
|
|
@@ -402,10 +493,7 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
402
493
|
if (fixedStyle && service.style && service.style !== fixedStyle) {
|
|
403
494
|
throw new Error(`Provider ${providerId} service ${serviceType} must use style ${fixedStyle}`);
|
|
404
495
|
}
|
|
405
|
-
const resolvedBaseUrl =
|
|
406
|
-
if (!validProviderBaseUrl(resolvedBaseUrl)) {
|
|
407
|
-
throw new Error(`Provider ${providerId} common.baseUrl must resolve to a valid http(s) URL`);
|
|
408
|
-
}
|
|
496
|
+
const resolvedBaseUrl = resolveProviderBaseUrl(providerId, provider.common.baseUrl);
|
|
409
497
|
if (provider.domain !== undefined)
|
|
410
498
|
providerIdentity({ ...provider, common: { ...provider.common, baseUrl: resolvedBaseUrl } });
|
|
411
499
|
const base = resolvedBaseUrl.endsWith('/') ? resolvedBaseUrl : `${resolvedBaseUrl}/`;
|
|
@@ -423,7 +511,7 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
423
511
|
const catalogBaseUrl = catalogParsed.toString().replace(/\/+$/u, '');
|
|
424
512
|
const catalogPath = new URL(catalogBaseUrl).pathname.replace(/\/+$/u, '');
|
|
425
513
|
const credentials = providerServiceCredentials(provider, serviceType);
|
|
426
|
-
if (service.apiKey !== undefined && service.apiKey
|
|
514
|
+
if (service.apiKey !== undefined && !isDeepStrictEqual(providerApiKeyEntries(service.apiKey), providerApiKeyEntries(provider.common.apiKey))) {
|
|
427
515
|
const hasSharedAuthHeader = Object.keys(provider.common.headers ?? {})
|
|
428
516
|
.some(name => ['authorization', 'x-api-key', 'x-goog-api-key', 'api-key'].includes(name.toLowerCase()));
|
|
429
517
|
const hasSharedAuthQuery = Object.keys(provider.common.queryParams ?? {})
|
|
@@ -434,9 +522,7 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
434
522
|
});
|
|
435
523
|
}
|
|
436
524
|
}
|
|
437
|
-
const
|
|
438
|
-
? undefined
|
|
439
|
-
: resolveProviderEnvironmentValue(providerId, 'apiKey', credentials.apiKey, service.apiKey === undefined ? 'common' : `services.${serviceType}`);
|
|
525
|
+
const apiKeys = resolveProviderApiKeys(providerId, credentials.apiKey, service.apiKey === undefined ? 'common' : `services.${serviceType}`);
|
|
440
526
|
return {
|
|
441
527
|
providerId,
|
|
442
528
|
serviceType,
|
|
@@ -444,7 +530,8 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
444
530
|
baseUrl: finalUrl,
|
|
445
531
|
catalogPath,
|
|
446
532
|
catalogBaseUrl,
|
|
447
|
-
apiKey,
|
|
533
|
+
...(apiKeys.length ? { apiKey: apiKeys[0] } : {}),
|
|
534
|
+
apiKeys,
|
|
448
535
|
headers: credentials.headers,
|
|
449
536
|
queryParams: credentials.queryParams,
|
|
450
537
|
modelOverrides: service.models ?? {},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSupportedBaseagent } from '../agents/baseagent.js';
|
|
1
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
4
|
import fs from 'node:fs';
|
|
@@ -7,11 +8,19 @@ import { ConfigTarget, mutateConfig, notifyConfigWrite } from './config-manager.
|
|
|
7
8
|
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
8
9
|
import { readProvidersFile, validateProvidersFile } from './providers.js';
|
|
9
10
|
import { initializationRuntimePlan, providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderId, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
10
|
-
import { providerIdentity } from './provider-identity.js';
|
|
11
|
+
import { providerIdentity as storedProviderIdentity } from './provider-identity.js';
|
|
11
12
|
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
12
13
|
import { isInteractionSendAccepted, sendInteractionPayload } from '../core/message/message-utils.js';
|
|
13
|
-
import { providerServiceCredentials, providerServiceTypeForBaseagent } from './providers-config.js';
|
|
14
|
+
import { maskProviderApiKey, providerApiKeyEntries, providerServiceCredentials, providerServiceTypeForBaseagent, resolveProviderBaseUrl, retainProviderApiKey } from './providers-config.js';
|
|
14
15
|
import { generateProviderTemplate, parseProviderTemplateInput } from './provider-templates.js';
|
|
16
|
+
/** Derive a missing identity during management without changing the stored URL reference. */
|
|
17
|
+
function providerIdentity(provider) {
|
|
18
|
+
if (provider.domain !== undefined || !providerEnvironmentVariable(provider.common.baseUrl)) {
|
|
19
|
+
return storedProviderIdentity(provider);
|
|
20
|
+
}
|
|
21
|
+
const baseUrl = resolveProviderBaseUrl('draft', provider.common.baseUrl);
|
|
22
|
+
return storedProviderIdentity({ ...provider, common: { ...provider.common, baseUrl } });
|
|
23
|
+
}
|
|
15
24
|
/** Shared template preview/merge; raw credentials never belong in a public response. */
|
|
16
25
|
export function prepareProviderTemplate(templateId, value, file = resolvePaths().providersConfig, draft) {
|
|
17
26
|
const input = parseProviderTemplateInput(value);
|
|
@@ -76,7 +85,7 @@ export function previewProviderTemplate(templateId, config, context) {
|
|
|
76
85
|
}
|
|
77
86
|
/** Capture facts before an attempt; never infer a service or protocol from error text. */
|
|
78
87
|
export function providerConnectionContext(baseagent, providerId, nativeBaseUrl, nativeApiKey, nativeMetadata) {
|
|
79
|
-
if (!
|
|
88
|
+
if (!isSupportedBaseagent(baseagent))
|
|
80
89
|
return undefined;
|
|
81
90
|
const registry = readProvidersFile();
|
|
82
91
|
const id = providerId ? resolveProviderId(providerId, registry) : undefined;
|
|
@@ -113,13 +122,20 @@ export function providerConnectionContext(baseagent, providerId, nativeBaseUrl,
|
|
|
113
122
|
/** Raw references can stay unchanged while the effective endpoint or key changes. */
|
|
114
123
|
function providerEnvironmentRevision(provider) {
|
|
115
124
|
const connections = [provider?.common, ...Object.values(provider?.services ?? {})];
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
/** A whole-pool change must invalidate the revision, so every key is expanded. */
|
|
126
|
+
const effectiveKey = (raw) => providerApiKeyEntries(raw)
|
|
127
|
+
.map(key => providerEnvironmentVariable(key) ? process.env[providerEnvironmentVariable(key)] : key);
|
|
128
|
+
return createHash('sha256').update(JSON.stringify(connections.map(connection => {
|
|
129
|
+
const scope = connection;
|
|
130
|
+
const rawBaseUrl = scope?.baseUrl;
|
|
131
|
+
const variable = rawBaseUrl ? providerEnvironmentVariable(rawBaseUrl) : undefined;
|
|
132
|
+
return [variable ? process.env[variable] : rawBaseUrl, effectiveKey(scope?.apiKey)];
|
|
133
|
+
}))).digest('hex');
|
|
121
134
|
}
|
|
122
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Replacing the connection key rewrites the primary (position 0) and keeps any
|
|
137
|
+
* stored backups, so a repair never discards the rest of the pool.
|
|
138
|
+
*/
|
|
123
139
|
function replaceConnectionKey(provider, apiKey, serviceType) {
|
|
124
140
|
const target = serviceType ? provider.services?.[serviceType] : provider.common;
|
|
125
141
|
if (!target)
|
|
@@ -131,7 +147,8 @@ function replaceConnectionKey(provider, apiKey, serviceType) {
|
|
|
131
147
|
if (effective.queryParams)
|
|
132
148
|
target.queryParams = { ...effective.queryParams };
|
|
133
149
|
}
|
|
134
|
-
|
|
150
|
+
const backups = providerApiKeyEntries(target.apiKey).slice(1);
|
|
151
|
+
target.apiKey = backups.length ? [apiKey, ...backups] : apiKey;
|
|
135
152
|
for (const name of Object.keys(target.headers ?? {})) {
|
|
136
153
|
const lower = name.toLowerCase();
|
|
137
154
|
if (lower === 'authorization' && /^Bearer\s/iu.test(target.headers[name])) {
|
|
@@ -175,8 +192,10 @@ export class ProviderConnectionQuestions {
|
|
|
175
192
|
return true;
|
|
176
193
|
const fields = new Set(rule.question.fields);
|
|
177
194
|
const supplied = (field) => {
|
|
195
|
+
// Repair collects the primary key; stored backups are restored by replaceConnectionKey.
|
|
178
196
|
const raw = field === 'baseUrl' ? context.baseUrl : context.provider
|
|
179
|
-
? providerServiceCredentials(context.provider, context.serviceType).apiKey
|
|
197
|
+
? providerApiKeyEntries(providerServiceCredentials(context.provider, context.serviceType).apiKey)[0]
|
|
198
|
+
: context.nativeApiKey;
|
|
180
199
|
const variable = raw ? providerEnvironmentVariable(raw) : undefined;
|
|
181
200
|
return variable ? process.env[variable] : raw;
|
|
182
201
|
};
|
|
@@ -533,8 +552,9 @@ function providersSnapshot(value) {
|
|
|
533
552
|
const providers = structuredClone(value.providers);
|
|
534
553
|
for (const provider of Object.values(providers)) {
|
|
535
554
|
for (const connection of [provider.common, ...Object.values(provider.services ?? {})]) {
|
|
536
|
-
|
|
537
|
-
|
|
555
|
+
const masked = maskProviderApiKey(connection.apiKey, PROVIDER_SECRET_MASK);
|
|
556
|
+
if (masked !== undefined)
|
|
557
|
+
connection.apiKey = masked;
|
|
538
558
|
for (const field of ['headers', 'queryParams']) {
|
|
539
559
|
const values = connection[field];
|
|
540
560
|
if (values)
|
|
@@ -559,14 +579,16 @@ function retainSecrets(value, previous) {
|
|
|
559
579
|
return provider;
|
|
560
580
|
const connections = [[provider.common, previous?.common],
|
|
561
581
|
...Object.entries(provider.services ?? {}).map(([type, service]) => [service, previous?.services?.[type]])];
|
|
582
|
+
/** Masked pool entries are restored position by position; a new position must carry a real key. */
|
|
583
|
+
const retained = (target, field, old) => {
|
|
584
|
+
const restored = retainProviderApiKey(target[field], old, PROVIDER_SECRET_MASK);
|
|
585
|
+
if (restored !== undefined)
|
|
586
|
+
target[field] = restored;
|
|
587
|
+
};
|
|
562
588
|
for (const [common, old] of connections) {
|
|
563
589
|
if (!common || typeof common !== 'object')
|
|
564
590
|
continue;
|
|
565
|
-
|
|
566
|
-
if (old?.apiKey === undefined)
|
|
567
|
-
throw new Error('A replacement API key is required');
|
|
568
|
-
common.apiKey = old.apiKey;
|
|
569
|
-
}
|
|
591
|
+
retained(common, 'apiKey', old?.apiKey);
|
|
570
592
|
for (const field of ['headers', 'queryParams']) {
|
|
571
593
|
if (!common[field] || typeof common[field] !== 'object' || Array.isArray(common[field]))
|
|
572
594
|
continue;
|
|
@@ -633,7 +655,7 @@ export async function updateProvider(input, file = resolvePaths().providersConfi
|
|
|
633
655
|
function rejectMaskedImportSecrets(providers) {
|
|
634
656
|
for (const [providerId, provider] of Object.entries(providers)) {
|
|
635
657
|
for (const connection of [provider.common, ...Object.values(provider.services ?? {})]) {
|
|
636
|
-
if (connection.apiKey
|
|
658
|
+
if (providerApiKeyEntries(connection.apiKey).includes(PROVIDER_SECRET_MASK)) {
|
|
637
659
|
throw new Error(`Provider ${providerId} has a redacted API key; import a file with the original secret`);
|
|
638
660
|
}
|
|
639
661
|
for (const field of ['headers', 'queryParams']) {
|
|
@@ -705,7 +727,7 @@ function assertProviderDomainUnchanged(previous, next) {
|
|
|
705
727
|
}
|
|
706
728
|
catch (error) {
|
|
707
729
|
const code = error?.code;
|
|
708
|
-
if (previous.domain === undefined &&
|
|
730
|
+
if (previous.domain === undefined && ['PROVIDER_DOMAIN_REQUIRED', 'PROVIDER_DOMAIN_INVALID', 'PROVIDER_BASE_URL_MISSING'].includes(code ?? '')) {
|
|
709
731
|
if (previous.common.baseUrl === next.common.baseUrl) {
|
|
710
732
|
if (next.domain !== undefined)
|
|
711
733
|
next.domain = providerIdentity(next).domain;
|
|
@@ -849,8 +871,10 @@ function providerHostname(baseUrl) {
|
|
|
849
871
|
}
|
|
850
872
|
function mergeImportedProvider(existing, imported, replaceServiceTypes = new Set(), preserveCommon = false) {
|
|
851
873
|
const services = structuredClone(existing.services || {});
|
|
874
|
+
// An existing pool wins as a whole; importing never partially overwrites stored keys.
|
|
875
|
+
const existingHasKey = providerApiKeyEntries(existing.common.apiKey).some(key => key.trim());
|
|
852
876
|
const common = { ...existing.common,
|
|
853
|
-
...(!preserveCommon && !
|
|
877
|
+
...(!preserveCommon && !existingHasKey && imported.common.apiKey ? { apiKey: imported.common.apiKey } : {}),
|
|
854
878
|
};
|
|
855
879
|
const existingVariable = providerEnvironmentVariable(existing.common.baseUrl);
|
|
856
880
|
const importedVariable = providerEnvironmentVariable(imported.common.baseUrl);
|
|
@@ -3,7 +3,6 @@ import { parseConfigSelector } from '../cli/config-selector.js';
|
|
|
3
3
|
import { parseConfigFieldValue, resolveConfigFieldRule, } from './config-field-policy.js';
|
|
4
4
|
import { isAgentOnlyBaseagentField } from './config-field-policy.js';
|
|
5
5
|
import { ConfigError, routeFieldPath } from './config-manager.js';
|
|
6
|
-
import { isValidAid } from '../aun/aid/validation.js';
|
|
7
6
|
const SELECTOR_OPTIONS = {
|
|
8
7
|
'--self': 'value',
|
|
9
8
|
'--peer': 'value',
|
|
@@ -122,14 +121,15 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
122
121
|
reason: 'Agent role policies are managed through the role policy editor',
|
|
123
122
|
};
|
|
124
123
|
}
|
|
124
|
+
// defaults.json 仍只允许手工编辑;Agent 级的 baseagents.<ba>.fallback 走正常字段写入。
|
|
125
125
|
const canContainFallback = field === 'baseagents'
|
|
126
126
|
|| /^baseagents\.[^.]+$/.test(field)
|
|
127
127
|
|| /^baseagents\.[^.]+\.fallback(?:\.|$)/.test(field);
|
|
128
|
-
if (subcommand !== 'get' && canContainFallback) {
|
|
128
|
+
if (subcommand !== 'get' && canContainFallback && selector.scope === 'defaults') {
|
|
129
129
|
return {
|
|
130
130
|
ok: false,
|
|
131
131
|
code: 'DEFAULTS_FILE_ONLY',
|
|
132
|
-
reason: 'Baseagent fallback is configured
|
|
132
|
+
reason: 'Baseagent fallback is configured in agents/defaults.json; edit that file and run `ec config validate --default`',
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
const fieldRule = resolveConfigFieldRule(field, selector.scope);
|
|
@@ -186,19 +186,7 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
186
186
|
const rawValue = subcommand === 'set' ? business.values[1] : undefined;
|
|
187
187
|
let value;
|
|
188
188
|
if (subcommand === 'set') {
|
|
189
|
-
if (
|
|
190
|
-
const owner = rawValue.trim();
|
|
191
|
-
if (!isValidAid(owner))
|
|
192
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: `Invalid owner AID: ${JSON.stringify(rawValue)}` };
|
|
193
|
-
value = owner;
|
|
194
|
-
}
|
|
195
|
-
else if (field === 'owners') {
|
|
196
|
-
const parsedOwners = parseOwnersValue(rawValue);
|
|
197
|
-
if (!parsedOwners.ok)
|
|
198
|
-
return parsedOwners;
|
|
199
|
-
value = parsedOwners.value;
|
|
200
|
-
}
|
|
201
|
-
else if (isRelationRole) {
|
|
189
|
+
if (isRelationRole) {
|
|
202
190
|
const raw = rawValue.trim();
|
|
203
191
|
if (!raw)
|
|
204
192
|
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'Config field role cannot be empty' };
|
|
@@ -552,34 +540,6 @@ function coerceConfigValue(raw, route, field) {
|
|
|
552
540
|
return { ok: true, value: Number(raw) };
|
|
553
541
|
return { ok: true, value: raw };
|
|
554
542
|
}
|
|
555
|
-
function parseOwnersValue(raw) {
|
|
556
|
-
let values;
|
|
557
|
-
const trimmed = raw.trim();
|
|
558
|
-
if (trimmed.startsWith('[')) {
|
|
559
|
-
try {
|
|
560
|
-
values = JSON.parse(trimmed);
|
|
561
|
-
}
|
|
562
|
-
catch {
|
|
563
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must be a valid JSON array of AIDs' };
|
|
564
|
-
}
|
|
565
|
-
if (!Array.isArray(values)) {
|
|
566
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must be a JSON array of AIDs' };
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
values = [raw];
|
|
571
|
-
}
|
|
572
|
-
if (!Array.isArray(values) || values.length === 0) {
|
|
573
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must contain at least one AID' };
|
|
574
|
-
}
|
|
575
|
-
const owners = [...new Set(values
|
|
576
|
-
.filter((value) => typeof value === 'string' && !!value.trim())
|
|
577
|
-
.map(value => value.trim()))];
|
|
578
|
-
if (owners.length === 0 || owners.some(owner => !isValidAid(owner))) {
|
|
579
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: `Invalid owner AID: ${JSON.stringify(owners)}` };
|
|
580
|
-
}
|
|
581
|
-
return { ok: true, value: owners };
|
|
582
|
-
}
|
|
583
543
|
function configErrorResult(error) {
|
|
584
544
|
if (error instanceof ConfigError)
|
|
585
545
|
return { ok: false, code: error.code, reason: error.message };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSupportedBaseagent } from '../agents/baseagent.js';
|
|
1
2
|
import crypto from 'crypto';
|
|
2
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
4
|
import fs from 'fs';
|
|
@@ -8,6 +9,7 @@ import { firstConfiguredOwner } from './owner-config.js';
|
|
|
8
9
|
import { currentVersion, loadSchema } from './schema-registry.js';
|
|
9
10
|
import { planProviderIdentityMigration, validateProviderIdentityMigrationPlan } from './provider-identity-migration.js';
|
|
10
11
|
import { providerIdentity } from './provider-identity.js';
|
|
12
|
+
import { providerApiKeyEntries } from './providers-config.js';
|
|
11
13
|
import { snapshot } from './snapshot.js';
|
|
12
14
|
import { logger } from '../utils/logger.js';
|
|
13
15
|
import { parseContactAlias } from './peer-alias.js';
|
|
@@ -26,7 +28,6 @@ const MIGRATION_KIND = {
|
|
|
26
28
|
'peer-file-v1': 'agent-only-model',
|
|
27
29
|
'peer-state-v4': 'agent-only-model',
|
|
28
30
|
};
|
|
29
|
-
const SUPPORTED_BASEAGENTS = new Set(['claude', 'codex', 'gemini', 'ecagent']);
|
|
30
31
|
const BASEAGENT_ALIASES = new Map([
|
|
31
32
|
['cc', 'claude'],
|
|
32
33
|
['claude-code', 'claude'],
|
|
@@ -98,7 +99,7 @@ function jsonText(value) {
|
|
|
98
99
|
function canonicalBaseagent(value) {
|
|
99
100
|
const key = String(value || '').trim().toLowerCase().replace(/_/g, '-');
|
|
100
101
|
const canonical = BASEAGENT_ALIASES.get(key) || key;
|
|
101
|
-
return
|
|
102
|
+
return isSupportedBaseagent(canonical) ? canonical : undefined;
|
|
102
103
|
}
|
|
103
104
|
function validAid(name) {
|
|
104
105
|
const labels = name.split('.');
|
|
@@ -1131,8 +1132,9 @@ function findProviderForConnection(providers, connection) {
|
|
|
1131
1132
|
catch {
|
|
1132
1133
|
continue;
|
|
1133
1134
|
}
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1135
|
+
const existingKeys = providerApiKeyEntries(provider.common.apiKey)
|
|
1136
|
+
.map(key => key.trim()).filter(Boolean);
|
|
1137
|
+
if (connection.apiKey && !existingKeys.includes(connection.apiKey))
|
|
1136
1138
|
continue;
|
|
1137
1139
|
if (connection.headers && !isDeepStrictEqual(provider.common.headers, connection.headers))
|
|
1138
1140
|
continue;
|
|
@@ -1723,6 +1725,53 @@ const PUBLISHED_SCHEMA_CONSOLIDATIONS = [
|
|
|
1723
1725
|
{ logicalName: 'agent-config', from: 20, to: 19 },
|
|
1724
1726
|
{ logicalName: 'relation-config', from: 13, to: 12 },
|
|
1725
1727
|
];
|
|
1728
|
+
/**
|
|
1729
|
+
* v22 → v23:Owner 只由 ownership 协议授予。
|
|
1730
|
+
*
|
|
1731
|
+
* 顶层的 `owner` / `owners` 曾经是 Owner 的兼容来源和自动绑定目标,现在两者
|
|
1732
|
+
* 都不存在了,字段只剩误导。清掉字段并重打版本号,让存量文件落进 v23 的
|
|
1733
|
+
* `additionalProperties: false`。
|
|
1734
|
+
*/
|
|
1735
|
+
const AGENT_OWNER_FIELD_VERSION = { from: 22, to: 23 };
|
|
1736
|
+
const AGENT_OWNER_RETIRED_FIELDS = ['owner', 'owners'];
|
|
1737
|
+
function stripRetiredOwnerFields(value) {
|
|
1738
|
+
if (value.$schema_version !== AGENT_OWNER_FIELD_VERSION.from)
|
|
1739
|
+
return { value, removed: [] };
|
|
1740
|
+
const next = { ...value };
|
|
1741
|
+
const removed = stripOwnFields(next, AGENT_OWNER_RETIRED_FIELDS);
|
|
1742
|
+
next.$schema_version = AGENT_OWNER_FIELD_VERSION.to;
|
|
1743
|
+
const schema = loadSchema('agent-config', AGENT_OWNER_FIELD_VERSION.to);
|
|
1744
|
+
if (!schema.validate(next)) {
|
|
1745
|
+
const detail = (schema.validate.errors ?? [])
|
|
1746
|
+
.map(error => `${error.instancePath || '/'} ${error.message}`)
|
|
1747
|
+
.join('; ');
|
|
1748
|
+
throw new Error(`agent-config v${AGENT_OWNER_FIELD_VERSION.to} rejected the stripped config: ${detail}`);
|
|
1749
|
+
}
|
|
1750
|
+
return { value: next, removed };
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* daemon.json v9 → v10:控制 Owner 同样只由 ownership 协议授予。
|
|
1754
|
+
*
|
|
1755
|
+
* 顶层 `owner` / `owners` 曾经决定控制 AID 的绑定邀约目标和名片归属,现在两条
|
|
1756
|
+
* 都改为显式发起绑定后从协议取。字段留在这里只会让人以为它还有授权作用。
|
|
1757
|
+
*/
|
|
1758
|
+
const DAEMON_OWNER_FIELD_VERSION = { from: 9, to: 10 };
|
|
1759
|
+
const DAEMON_OWNER_RETIRED_FIELDS = ['owner', 'owners'];
|
|
1760
|
+
function stripRetiredDaemonOwnerFields(value) {
|
|
1761
|
+
if (value.$schema_version !== DAEMON_OWNER_FIELD_VERSION.from)
|
|
1762
|
+
return { value, removed: [] };
|
|
1763
|
+
const next = { ...value };
|
|
1764
|
+
const removed = stripOwnFields(next, DAEMON_OWNER_RETIRED_FIELDS);
|
|
1765
|
+
next.$schema_version = DAEMON_OWNER_FIELD_VERSION.to;
|
|
1766
|
+
const schema = loadSchema('daemon', DAEMON_OWNER_FIELD_VERSION.to);
|
|
1767
|
+
if (!schema.validate(next)) {
|
|
1768
|
+
const detail = (schema.validate.errors ?? [])
|
|
1769
|
+
.map(error => `${error.instancePath || '/'} ${error.message}`)
|
|
1770
|
+
.join('; ');
|
|
1771
|
+
throw new Error(`daemon v${DAEMON_OWNER_FIELD_VERSION.to} rejected the stripped config: ${detail}`);
|
|
1772
|
+
}
|
|
1773
|
+
return { value: next, removed };
|
|
1774
|
+
}
|
|
1726
1775
|
function restampPublishedSchemaConsolidation(value, file, consolidation) {
|
|
1727
1776
|
let next = value;
|
|
1728
1777
|
let chatModeChanged = false;
|
|
@@ -1766,7 +1815,26 @@ function planStartupConfigCompatibilityMigration(home) {
|
|
|
1766
1815
|
relationsScanned: 0,
|
|
1767
1816
|
filesChanged: 0,
|
|
1768
1817
|
filesWithChatModesNormalized: 0,
|
|
1818
|
+
ownerFieldsRemoved: 0,
|
|
1769
1819
|
};
|
|
1820
|
+
// daemon.json moves to v10 independent of whether any Agent directory exists.
|
|
1821
|
+
const daemonFile = path.join(home, 'daemon.json');
|
|
1822
|
+
if (fs.existsSync(daemonFile)) {
|
|
1823
|
+
try {
|
|
1824
|
+
const parsed = readJson(daemonFile);
|
|
1825
|
+
if (isRecord(parsed.value)) {
|
|
1826
|
+
const stripped = stripRetiredDaemonOwnerFields(parsed.value);
|
|
1827
|
+
summary.ownerFieldsRemoved += stripped.removed.length;
|
|
1828
|
+
if (stripped.removed.length > 0) {
|
|
1829
|
+
changes.push({ file: daemonFile, kind: 'agent-only-model', before: parsed.text, after: jsonText(stripped.value) });
|
|
1830
|
+
summary.filesChanged += 1;
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
catch {
|
|
1835
|
+
// Malformed daemon.json is reported by the regular config loader.
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1770
1838
|
const agentsRoot = path.join(home, 'agents');
|
|
1771
1839
|
if (!fs.existsSync(agentsRoot))
|
|
1772
1840
|
return { home, changes, summary };
|
|
@@ -1787,7 +1855,12 @@ function planStartupConfigCompatibilityMigration(home) {
|
|
|
1787
1855
|
continue;
|
|
1788
1856
|
}
|
|
1789
1857
|
if (isRecord(parsed.value)) {
|
|
1790
|
-
const
|
|
1858
|
+
const stripped = stripRetiredOwnerFields(parsed.value);
|
|
1859
|
+
summary.ownerFieldsRemoved += stripped.removed.length;
|
|
1860
|
+
// A stripped config still has to be written even when the consolidation
|
|
1861
|
+
// pass finds nothing to restamp; otherwise the removal is planned but lost.
|
|
1862
|
+
const consolidated = restampPublishedSchemaConsolidation(stripped.value, agentFile, agentConsolidation);
|
|
1863
|
+
const next = consolidated ?? (stripped.removed.length > 0 ? stripped.value : null);
|
|
1791
1864
|
if (next) {
|
|
1792
1865
|
changes.push({ file: agentFile, kind: 'agent-only-model', before: parsed.text, after: jsonText(next) });
|
|
1793
1866
|
summary.filesChanged += 1;
|
|
@@ -61,15 +61,60 @@ export function isSchemaName(name) {
|
|
|
61
61
|
return Object.prototype.hasOwnProperty.call(loadMeta().schemas, name);
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* 字段的 schema 声明默认值(`default` 关键字),无则 undefined。
|
|
65
|
+
*
|
|
66
|
+
* 顶层与嵌套路径统一递归解析——不需要白名单:默认值只允许挂在这条覆盖链上
|
|
67
|
+
* **最低的、声明了该参数的层级**(见 docs/config/11-default-value-levels.md),
|
|
68
|
+
* 高层 schema 里不会出现 default,所以递归不会把"该显式配置"的字段读成一个
|
|
69
|
+
* 看似生效的值。返回 undefined 就是"没配也没默认值",即未配置。
|
|
67
70
|
*/
|
|
68
71
|
export function fieldSchemaDefault(name, fieldPath) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const parts = fieldPath.split('.');
|
|
73
|
+
let fields = loadSchema(name).fields;
|
|
74
|
+
let spec;
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
spec = fields?.get(part);
|
|
77
|
+
if (!spec)
|
|
78
|
+
return undefined;
|
|
79
|
+
fields = spec.children;
|
|
80
|
+
}
|
|
81
|
+
// FieldSpec.default 是无条件赋值的属性,判据必须是 `!== undefined`,不能用 `in`。
|
|
82
|
+
return spec ? spec.default : undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 某层级 schema 的默认值层(按字段树递归展开成对象),供覆盖链合并使用。
|
|
86
|
+
*
|
|
87
|
+
* 语义:**这一层的配置文件里没写这个参数时,这一层仍然以 schema 的 default 参与覆盖。**
|
|
88
|
+
* 因此默认值只能挂在这条链上最低的、声明了该参数的层级;高层挂默认值会永久压掉低层
|
|
89
|
+
* 的用户配置(见 docs/config/11-default-value-levels.md)。
|
|
90
|
+
*
|
|
91
|
+
* 返回的对象是新构造的,调用方可以安全改写;无默认值的字段不出现在结果里。
|
|
92
|
+
*/
|
|
93
|
+
export function schemaDefaultsLayer(name) {
|
|
94
|
+
const build = (fields) => {
|
|
95
|
+
const out = {};
|
|
96
|
+
for (const [key, spec] of fields) {
|
|
97
|
+
if (spec.default !== undefined) {
|
|
98
|
+
out[key] = cloneValue(spec.default);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (spec.children && spec.children.size > 0) {
|
|
102
|
+
const nested = build(spec.children);
|
|
103
|
+
if (Object.keys(nested).length > 0)
|
|
104
|
+
out[key] = nested;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
};
|
|
109
|
+
return build(loadSchema(name).fields);
|
|
110
|
+
}
|
|
111
|
+
function cloneValue(value) {
|
|
112
|
+
if (Array.isArray(value))
|
|
113
|
+
return value.map(cloneValue);
|
|
114
|
+
if (value && typeof value === 'object') {
|
|
115
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, cloneValue(v)]));
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
73
118
|
}
|
|
74
119
|
/** 某版本的 history 元信息(date/description),无则 undefined。 */
|
|
75
120
|
export function schemaHistoryEntry(name, version) {
|