evolcore 0.0.49 → 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 +64 -1
- 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 +280 -6
- 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 +4 -1
- 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 +29 -1
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +537 -189
- 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/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +23 -4
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +1 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +11 -9
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +17 -8
- package/dist/config/config-manager.js +86 -46
- 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 +99 -16
- package/dist/config/providers-management.js +35 -19
- package/dist/config/resolved-config-op.js +1 -42
- 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/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +50 -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 +15 -0
- 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 +91 -72
- package/dist/core/command/menu-protocol.js +5 -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/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 +2 -1
- package/dist/core/daemon-lifecycle.js +13 -5
- package/dist/core/evolagent-registry.js +12 -7
- 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 +4 -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 +98 -21
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/message-bridge.js +105 -6
- package/dist/core/message/message-log.js +8 -0
- package/dist/core/message/message-queue.js +5 -3
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +23 -8
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +4 -0
- package/dist/core/permission/ec-command-parser.js +182 -58
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +9 -2
- package/dist/core/permission/tool-policy.js +21 -9
- 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/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 +52 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/eck/kit-renderer.js +2 -1
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/index.js +116 -41
- package/dist/ipc.js +58 -2
- 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 +176 -18
- package/dist/services/ipc-operation.js +204 -44
- package/dist/services/script-runner.js +515 -83
- package/dist/services/validation.js +109 -4
- 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 -20
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +73 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- 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/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 +7 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +20 -3
- package/kits/docs/evolcore/config.md +1 -1
- 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 +68 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +21 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -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.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 +13 -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 +12 -5
- 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 +1 -1
- 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/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +4 -3
- 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 -129
- package/kits/templates/system-fragments/venue.md +16 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +37 -23
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +16 -4
- package/scripts/agent-template/shared/team-schema.json +20 -4
- package/scripts/agent-template/shared/template-contract.mjs +53 -13
- package/scripts/agent-template/shared/template-package.mjs +90 -26
- package/scripts/agent-template/shared/template-runtime.mjs +111 -1
- package/scripts/agent-template/shared/template.mjs +65 -7
- package/scripts/agent-template/team-pack.mjs +89 -33
- 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,3 +1,4 @@
|
|
|
1
|
+
import { listSupportedBaseagents } from '../agents/baseagent.js';
|
|
1
2
|
/**
|
|
2
3
|
* gateway-config.ts — baseagent 模型选择与 provider 指认管理。
|
|
3
4
|
*
|
|
@@ -23,7 +24,7 @@ import { logger } from '../utils/logger.js';
|
|
|
23
24
|
import { resolveProviderServiceForBaseagent } from './providers.js';
|
|
24
25
|
import { stripLegacyAunGatewayConfig } from './config-manager.js';
|
|
25
26
|
/** 已知 baseagent 类型(模型选择可管理范围)。 */
|
|
26
|
-
const
|
|
27
|
+
const gatewayTypes = () => listSupportedBaseagents();
|
|
27
28
|
const DISPLAY_NAMES = {
|
|
28
29
|
claude: 'Claude',
|
|
29
30
|
codex: 'Codex (OpenAI)',
|
|
@@ -74,7 +75,7 @@ function extractEntries(raw, scope) {
|
|
|
74
75
|
const ba = raw?.baseagents;
|
|
75
76
|
if (!ba || typeof ba !== 'object')
|
|
76
77
|
return out;
|
|
77
|
-
for (const type of
|
|
78
|
+
for (const type of gatewayTypes()) {
|
|
78
79
|
const c = ba[type];
|
|
79
80
|
if (!c || typeof c !== 'object')
|
|
80
81
|
continue;
|
|
@@ -104,7 +105,7 @@ export function gatewayList() {
|
|
|
104
105
|
gateways.push(...extractEntries(raw, aid));
|
|
105
106
|
}
|
|
106
107
|
const effective = computeEffective(aids);
|
|
107
|
-
return { data: { gateways, scopes: aids, types:
|
|
108
|
+
return { data: { gateways, scopes: aids, types: gatewayTypes(), effective } };
|
|
108
109
|
}
|
|
109
110
|
catch (e) {
|
|
110
111
|
logger.error('[gateway] gatewayList 执行出错:', e);
|
|
@@ -123,7 +124,7 @@ function computeEffective(aids) {
|
|
|
123
124
|
logger.error(`[GatewayConfig] active_baseagent is empty for aid=${aid}, skipping`);
|
|
124
125
|
continue;
|
|
125
126
|
}
|
|
126
|
-
if (!
|
|
127
|
+
if (!gatewayTypes().includes(activeRaw)) {
|
|
127
128
|
logger.error(`[GatewayConfig] unknown baseagent type '${activeRaw}' for aid=${aid}, skipping`);
|
|
128
129
|
continue;
|
|
129
130
|
}
|
|
@@ -143,7 +144,7 @@ function computeEffective(aids) {
|
|
|
143
144
|
// ── 写入 ──
|
|
144
145
|
/** 校验 type 合法。 */
|
|
145
146
|
function validateType(type) {
|
|
146
|
-
return typeof type === 'string' &&
|
|
147
|
+
return typeof type === 'string' && gatewayTypes().includes(type);
|
|
147
148
|
}
|
|
148
149
|
/** 网关连接信息(baseUrl/apiKey/headers/queryParams)只存在于 providers.json,Agent 级只选 provider。 */
|
|
149
150
|
const REMOVED_GATEWAY_FIELDS = ['baseUrl', 'apiKey', 'model', 'effort', 'reasoning', 'mode', 'useVertex', 'project', 'location'];
|
|
@@ -194,7 +195,7 @@ export async function gatewayUpdate(args) {
|
|
|
194
195
|
return { error: 'defaults 不承载 baseagent 配置;连接信息在 providers.json,模型选择在各 Agent 的 config.json', code: 'INVALID_ARGS' };
|
|
195
196
|
}
|
|
196
197
|
if (!validateType(type))
|
|
197
|
-
return { error: `无效 type: ${type}(可选 ${
|
|
198
|
+
return { error: `无效 type: ${type}(可选 ${gatewayTypes().join('/')})`, code: 'INVALID_ARGS' };
|
|
198
199
|
const built = buildPatch(type, args?.patch ?? {});
|
|
199
200
|
if ('error' in built)
|
|
200
201
|
return { error: built.error, code: 'INVALID_ARGS' };
|
|
@@ -256,12 +257,12 @@ function resolveGatewayCreds(scope, type) {
|
|
|
256
257
|
return {
|
|
257
258
|
baseUrl: resolved.baseUrl,
|
|
258
259
|
apiKey: resolved.apiKey,
|
|
259
|
-
headers: buildModelRequestHeaders({
|
|
260
|
+
headers: type === 'claude' || type === 'codex' || type === 'ecagent' ? buildModelRequestHeaders({
|
|
260
261
|
baseagent: type,
|
|
261
262
|
baseUrl: resolved.baseUrl,
|
|
262
263
|
agentAid: scope,
|
|
263
264
|
configuredHeaders: resolved.headers,
|
|
264
|
-
}),
|
|
265
|
+
}) : resolved.headers,
|
|
265
266
|
queryParams: resolved.queryParams,
|
|
266
267
|
};
|
|
267
268
|
}
|
|
@@ -21,17 +21,6 @@ export function firstConfiguredOwner(value) {
|
|
|
21
21
|
}
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
|
-
/** Runtime compatibility projection for binding-target input; this is not an authorization list. */
|
|
25
|
-
export function configuredOwnerList(value) {
|
|
26
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
27
|
-
return [];
|
|
28
|
-
const record = value;
|
|
29
|
-
const values = [record.owner, ...(Array.isArray(record.owners) ? record.owners : [])];
|
|
30
|
-
return [...new Set(values
|
|
31
|
-
.filter((candidate) => typeof candidate === 'string')
|
|
32
|
-
.map(candidate => candidate.trim())
|
|
33
|
-
.filter(Boolean))];
|
|
34
|
-
}
|
|
35
24
|
export function assertOwnerConfigRecord(value, label, validateId) {
|
|
36
25
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
37
26
|
return;
|
|
@@ -55,11 +44,6 @@ export function assertOwnerConfigRecord(value, label, validateId) {
|
|
|
55
44
|
}
|
|
56
45
|
});
|
|
57
46
|
}
|
|
58
|
-
for (const owner of configuredOwnerList(record)) {
|
|
59
|
-
if (validateId && !validateId(owner)) {
|
|
60
|
-
throw new Error(`${label}.owner is invalid: ${JSON.stringify(owner)}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
47
|
}
|
|
64
48
|
/** Normalize one config record for persistence: write only the scalar owner. */
|
|
65
49
|
export function normalizeSingleOwnerRecord(value) {
|
|
@@ -9,7 +9,6 @@ import { isManagementRole } from './builtin-roles.js';
|
|
|
9
9
|
import { getRoleDefinition, getRoleRank, normalizeDefaultRole, roleExists } from './roles.js';
|
|
10
10
|
import { getStoredRoleRegistry, roleRegistryExists } from './role-store.js';
|
|
11
11
|
import { resolvePrincipal } from './peer-book.js';
|
|
12
|
-
import { configuredOwnerList } from './owner-config.js';
|
|
13
12
|
import { tryParseChannelKey } from '../core/channel-loader.js';
|
|
14
13
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
15
14
|
import { getOwners, ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
@@ -19,13 +18,8 @@ import { isOwnerDirectoryContact } from '../directory/owner-directory-admission.
|
|
|
19
18
|
export function isAuthenticated(userId) {
|
|
20
19
|
return isValidAid(String(userId || '').trim());
|
|
21
20
|
}
|
|
22
|
-
/** Return the protocol Owner
|
|
21
|
+
/** Return the protocol Owner. Configured values are never an authorization source. */
|
|
23
22
|
export function listStaticAgentOwners(aid, opts = {}) {
|
|
24
|
-
try {
|
|
25
|
-
const config = read(ConfigTarget.Agent, { self: aid }, { cache: opts.fresh !== true });
|
|
26
|
-
ownerResolver.setAgentConfiguredOwners(aid, configuredOwnerList(config));
|
|
27
|
-
}
|
|
28
|
-
catch { }
|
|
29
23
|
return ownerResolver.owners(aid);
|
|
30
24
|
}
|
|
31
25
|
/** Direct AUN relations with role=admin are the addressable Agent admin set. */
|
|
@@ -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)
|
|
@@ -227,12 +317,9 @@ function serviceConfig(value, field, serviceType) {
|
|
|
227
317
|
throw new Error(`${field} must be an object`);
|
|
228
318
|
assertFields(value, ['path', 'catalogPath', 'style', 'models', 'modelPolicy', 'apiKey', 'headers', 'queryParams'], field);
|
|
229
319
|
const result = {};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
assertProviderEnvironmentSyntax(value.apiKey, `${field}.apiKey`);
|
|
234
|
-
result.apiKey = value.apiKey;
|
|
235
|
-
}
|
|
320
|
+
const apiKey = providerApiKeyValue(value.apiKey, `${field}.apiKey`);
|
|
321
|
+
if (apiKey !== undefined)
|
|
322
|
+
result.apiKey = apiKey;
|
|
236
323
|
for (const name of ['headers', 'queryParams']) {
|
|
237
324
|
const values = stringMap(value[name], `${field}.${name}`);
|
|
238
325
|
if (values !== undefined)
|
|
@@ -304,16 +391,13 @@ function providerConfig(value, field) {
|
|
|
304
391
|
}
|
|
305
392
|
const headers = stringMap(common.headers, `${field}.common.headers`);
|
|
306
393
|
const queryParams = stringMap(common.queryParams, `${field}.common.queryParams`);
|
|
307
|
-
|
|
308
|
-
throw new Error(`${field}.common.apiKey must be a string`);
|
|
309
|
-
if (typeof common.apiKey === 'string')
|
|
310
|
-
assertProviderEnvironmentSyntax(common.apiKey, `${field}.common.apiKey`);
|
|
394
|
+
const apiKey = providerApiKeyValue(common.apiKey, `${field}.common.apiKey`);
|
|
311
395
|
const result = {
|
|
312
396
|
...(value.domain !== undefined ? { domain: normalizeProviderDomain(value.domain) } : {}),
|
|
313
397
|
...(typeof value.name === 'string' && value.name.trim() ? { name: value.name.trim() } : {}),
|
|
314
398
|
common: {
|
|
315
399
|
baseUrl,
|
|
316
|
-
...(
|
|
400
|
+
...(apiKey !== undefined ? { apiKey } : {}),
|
|
317
401
|
...(headers ? { headers } : {}),
|
|
318
402
|
...(queryParams ? { queryParams } : {}),
|
|
319
403
|
},
|
|
@@ -427,7 +511,7 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
427
511
|
const catalogBaseUrl = catalogParsed.toString().replace(/\/+$/u, '');
|
|
428
512
|
const catalogPath = new URL(catalogBaseUrl).pathname.replace(/\/+$/u, '');
|
|
429
513
|
const credentials = providerServiceCredentials(provider, serviceType);
|
|
430
|
-
if (service.apiKey !== undefined && service.apiKey
|
|
514
|
+
if (service.apiKey !== undefined && !isDeepStrictEqual(providerApiKeyEntries(service.apiKey), providerApiKeyEntries(provider.common.apiKey))) {
|
|
431
515
|
const hasSharedAuthHeader = Object.keys(provider.common.headers ?? {})
|
|
432
516
|
.some(name => ['authorization', 'x-api-key', 'x-goog-api-key', 'api-key'].includes(name.toLowerCase()));
|
|
433
517
|
const hasSharedAuthQuery = Object.keys(provider.common.queryParams ?? {})
|
|
@@ -438,9 +522,7 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
438
522
|
});
|
|
439
523
|
}
|
|
440
524
|
}
|
|
441
|
-
const
|
|
442
|
-
? undefined
|
|
443
|
-
: resolveProviderEnvironmentValue(providerId, 'apiKey', credentials.apiKey, service.apiKey === undefined ? 'common' : `services.${serviceType}`);
|
|
525
|
+
const apiKeys = resolveProviderApiKeys(providerId, credentials.apiKey, service.apiKey === undefined ? 'common' : `services.${serviceType}`);
|
|
444
526
|
return {
|
|
445
527
|
providerId,
|
|
446
528
|
serviceType,
|
|
@@ -448,7 +530,8 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
448
530
|
baseUrl: finalUrl,
|
|
449
531
|
catalogPath,
|
|
450
532
|
catalogBaseUrl,
|
|
451
|
-
apiKey,
|
|
533
|
+
...(apiKeys.length ? { apiKey: apiKeys[0] } : {}),
|
|
534
|
+
apiKeys,
|
|
452
535
|
headers: credentials.headers,
|
|
453
536
|
queryParams: credentials.queryParams,
|
|
454
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';
|
|
@@ -10,7 +11,7 @@ import { initializationRuntimePlan, providerEnvironmentVariable, providerNameFro
|
|
|
10
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, resolveProviderBaseUrl } 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';
|
|
15
16
|
/** Derive a missing identity during management without changing the stored URL reference. */
|
|
16
17
|
function providerIdentity(provider) {
|
|
@@ -84,7 +85,7 @@ export function previewProviderTemplate(templateId, config, context) {
|
|
|
84
85
|
}
|
|
85
86
|
/** Capture facts before an attempt; never infer a service or protocol from error text. */
|
|
86
87
|
export function providerConnectionContext(baseagent, providerId, nativeBaseUrl, nativeApiKey, nativeMetadata) {
|
|
87
|
-
if (!
|
|
88
|
+
if (!isSupportedBaseagent(baseagent))
|
|
88
89
|
return undefined;
|
|
89
90
|
const registry = readProvidersFile();
|
|
90
91
|
const id = providerId ? resolveProviderId(providerId, registry) : undefined;
|
|
@@ -121,13 +122,20 @@ export function providerConnectionContext(baseagent, providerId, nativeBaseUrl,
|
|
|
121
122
|
/** Raw references can stay unchanged while the effective endpoint or key changes. */
|
|
122
123
|
function providerEnvironmentRevision(provider) {
|
|
123
124
|
const connections = [provider?.common, ...Object.values(provider?.services ?? {})];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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');
|
|
129
134
|
}
|
|
130
|
-
/**
|
|
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
|
+
*/
|
|
131
139
|
function replaceConnectionKey(provider, apiKey, serviceType) {
|
|
132
140
|
const target = serviceType ? provider.services?.[serviceType] : provider.common;
|
|
133
141
|
if (!target)
|
|
@@ -139,7 +147,8 @@ function replaceConnectionKey(provider, apiKey, serviceType) {
|
|
|
139
147
|
if (effective.queryParams)
|
|
140
148
|
target.queryParams = { ...effective.queryParams };
|
|
141
149
|
}
|
|
142
|
-
|
|
150
|
+
const backups = providerApiKeyEntries(target.apiKey).slice(1);
|
|
151
|
+
target.apiKey = backups.length ? [apiKey, ...backups] : apiKey;
|
|
143
152
|
for (const name of Object.keys(target.headers ?? {})) {
|
|
144
153
|
const lower = name.toLowerCase();
|
|
145
154
|
if (lower === 'authorization' && /^Bearer\s/iu.test(target.headers[name])) {
|
|
@@ -183,8 +192,10 @@ export class ProviderConnectionQuestions {
|
|
|
183
192
|
return true;
|
|
184
193
|
const fields = new Set(rule.question.fields);
|
|
185
194
|
const supplied = (field) => {
|
|
195
|
+
// Repair collects the primary key; stored backups are restored by replaceConnectionKey.
|
|
186
196
|
const raw = field === 'baseUrl' ? context.baseUrl : context.provider
|
|
187
|
-
? providerServiceCredentials(context.provider, context.serviceType).apiKey
|
|
197
|
+
? providerApiKeyEntries(providerServiceCredentials(context.provider, context.serviceType).apiKey)[0]
|
|
198
|
+
: context.nativeApiKey;
|
|
188
199
|
const variable = raw ? providerEnvironmentVariable(raw) : undefined;
|
|
189
200
|
return variable ? process.env[variable] : raw;
|
|
190
201
|
};
|
|
@@ -541,8 +552,9 @@ function providersSnapshot(value) {
|
|
|
541
552
|
const providers = structuredClone(value.providers);
|
|
542
553
|
for (const provider of Object.values(providers)) {
|
|
543
554
|
for (const connection of [provider.common, ...Object.values(provider.services ?? {})]) {
|
|
544
|
-
|
|
545
|
-
|
|
555
|
+
const masked = maskProviderApiKey(connection.apiKey, PROVIDER_SECRET_MASK);
|
|
556
|
+
if (masked !== undefined)
|
|
557
|
+
connection.apiKey = masked;
|
|
546
558
|
for (const field of ['headers', 'queryParams']) {
|
|
547
559
|
const values = connection[field];
|
|
548
560
|
if (values)
|
|
@@ -567,14 +579,16 @@ function retainSecrets(value, previous) {
|
|
|
567
579
|
return provider;
|
|
568
580
|
const connections = [[provider.common, previous?.common],
|
|
569
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
|
+
};
|
|
570
588
|
for (const [common, old] of connections) {
|
|
571
589
|
if (!common || typeof common !== 'object')
|
|
572
590
|
continue;
|
|
573
|
-
|
|
574
|
-
if (old?.apiKey === undefined)
|
|
575
|
-
throw new Error('A replacement API key is required');
|
|
576
|
-
common.apiKey = old.apiKey;
|
|
577
|
-
}
|
|
591
|
+
retained(common, 'apiKey', old?.apiKey);
|
|
578
592
|
for (const field of ['headers', 'queryParams']) {
|
|
579
593
|
if (!common[field] || typeof common[field] !== 'object' || Array.isArray(common[field]))
|
|
580
594
|
continue;
|
|
@@ -641,7 +655,7 @@ export async function updateProvider(input, file = resolvePaths().providersConfi
|
|
|
641
655
|
function rejectMaskedImportSecrets(providers) {
|
|
642
656
|
for (const [providerId, provider] of Object.entries(providers)) {
|
|
643
657
|
for (const connection of [provider.common, ...Object.values(provider.services ?? {})]) {
|
|
644
|
-
if (connection.apiKey
|
|
658
|
+
if (providerApiKeyEntries(connection.apiKey).includes(PROVIDER_SECRET_MASK)) {
|
|
645
659
|
throw new Error(`Provider ${providerId} has a redacted API key; import a file with the original secret`);
|
|
646
660
|
}
|
|
647
661
|
for (const field of ['headers', 'queryParams']) {
|
|
@@ -857,8 +871,10 @@ function providerHostname(baseUrl) {
|
|
|
857
871
|
}
|
|
858
872
|
function mergeImportedProvider(existing, imported, replaceServiceTypes = new Set(), preserveCommon = false) {
|
|
859
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());
|
|
860
876
|
const common = { ...existing.common,
|
|
861
|
-
...(!preserveCommon && !
|
|
877
|
+
...(!preserveCommon && !existingHasKey && imported.common.apiKey ? { apiKey: imported.common.apiKey } : {}),
|
|
862
878
|
};
|
|
863
879
|
const existingVariable = providerEnvironmentVariable(existing.common.baseUrl);
|
|
864
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',
|
|
@@ -187,19 +186,7 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
187
186
|
const rawValue = subcommand === 'set' ? business.values[1] : undefined;
|
|
188
187
|
let value;
|
|
189
188
|
if (subcommand === 'set') {
|
|
190
|
-
if (
|
|
191
|
-
const owner = rawValue.trim();
|
|
192
|
-
if (!isValidAid(owner))
|
|
193
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: `Invalid owner AID: ${JSON.stringify(rawValue)}` };
|
|
194
|
-
value = owner;
|
|
195
|
-
}
|
|
196
|
-
else if (field === 'owners') {
|
|
197
|
-
const parsedOwners = parseOwnersValue(rawValue);
|
|
198
|
-
if (!parsedOwners.ok)
|
|
199
|
-
return parsedOwners;
|
|
200
|
-
value = parsedOwners.value;
|
|
201
|
-
}
|
|
202
|
-
else if (isRelationRole) {
|
|
189
|
+
if (isRelationRole) {
|
|
203
190
|
const raw = rawValue.trim();
|
|
204
191
|
if (!raw)
|
|
205
192
|
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'Config field role cannot be empty' };
|
|
@@ -553,34 +540,6 @@ function coerceConfigValue(raw, route, field) {
|
|
|
553
540
|
return { ok: true, value: Number(raw) };
|
|
554
541
|
return { ok: true, value: raw };
|
|
555
542
|
}
|
|
556
|
-
function parseOwnersValue(raw) {
|
|
557
|
-
let values;
|
|
558
|
-
const trimmed = raw.trim();
|
|
559
|
-
if (trimmed.startsWith('[')) {
|
|
560
|
-
try {
|
|
561
|
-
values = JSON.parse(trimmed);
|
|
562
|
-
}
|
|
563
|
-
catch {
|
|
564
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must be a valid JSON array of AIDs' };
|
|
565
|
-
}
|
|
566
|
-
if (!Array.isArray(values)) {
|
|
567
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must be a JSON array of AIDs' };
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
values = [raw];
|
|
572
|
-
}
|
|
573
|
-
if (!Array.isArray(values) || values.length === 0) {
|
|
574
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: 'owners must contain at least one AID' };
|
|
575
|
-
}
|
|
576
|
-
const owners = [...new Set(values
|
|
577
|
-
.filter((value) => typeof value === 'string' && !!value.trim())
|
|
578
|
-
.map(value => value.trim()))];
|
|
579
|
-
if (owners.length === 0 || owners.some(owner => !isValidAid(owner))) {
|
|
580
|
-
return { ok: false, code: 'INVALID_CONFIG_VALUE', reason: `Invalid owner AID: ${JSON.stringify(owners)}` };
|
|
581
|
-
}
|
|
582
|
-
return { ok: true, value: owners };
|
|
583
|
-
}
|
|
584
543
|
function configErrorResult(error) {
|
|
585
544
|
if (error instanceof ConfigError)
|
|
586
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;
|