evolcore 0.0.43-test.4 → 0.0.43-test.5
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 +46 -0
- package/bin/ecmsg.js +354 -91
- package/dist/agents/codex-runner.js +12 -17
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/channels/aun.js +30 -17
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +4 -2
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +10 -3
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +12 -3
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +45 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +11 -19
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +3 -0
- package/dist/config/boot-log.js +12 -1
- package/dist/config/config-manager.js +4 -13
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +5 -5
- package/dist/config/provider-identity-migration.js +202 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +153 -0
- package/dist/config/providers-config.js +32 -4
- package/dist/config/providers-management.js +144 -68
- package/dist/config/providers.js +4 -1
- package/dist/config/schema-migration.js +67 -3
- package/dist/core/agent-runtime.js +4 -2
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +11 -6
- package/dist/core/command/menu-protocol.js +4 -2
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/response-engine.js +23 -23
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/ownership/owner-resolver.js +111 -8
- package/dist/core/permission/ec-command-parser.js +148 -15
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/session-idle-monitor.js +94 -16
- package/dist/core/session/session-manager.js +69 -16
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-cache.js +686 -97
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +2 -2
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -9
- package/dist/ecweb/runtime/supervisor.js +76 -24
- package/dist/index.js +4 -0
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/scheduler.js +3 -3
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +13 -4
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +28 -28
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +1 -1
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +5 -5
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +47 -28
- package/kits/templates/system-fragments/session.md +2 -9
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +2 -3
package/dist/config/boot-log.js
CHANGED
|
@@ -15,7 +15,7 @@ import { logger } from '../utils/logger.js';
|
|
|
15
15
|
import { autoMigrateIfNeeded } from '../config-store.js';
|
|
16
16
|
import { ConfigTarget, initConfigManager, notifyConfigWrite } from './config-manager.js';
|
|
17
17
|
import { ensureRoleConfigV4OnStartup, ensureRoleConfigV5OnStartup } from './role-migration-startup.js';
|
|
18
|
-
import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensurePeerFileRenameOnStartup, ensurePublishedSchemaConsolidationMigrationOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup, invalidateMigrationReadCache, withMigrationReadCache, } from './schema-migration.js';
|
|
18
|
+
import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensurePeerFileRenameOnStartup, ensurePublishedSchemaConsolidationMigrationOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureProviderIdentityMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup, invalidateMigrationReadCache, withMigrationReadCache, } from './schema-migration.js';
|
|
19
19
|
import { ensureContactBookV2OnStartup } from './peer-book-v2-startup.js';
|
|
20
20
|
import { synchronizeAllManagementPeersSync } from './peer-book-store.js';
|
|
21
21
|
import { readInstalledEvolcoreVersion, readFastaunVersion } from '../utils/evolcore-version.js';
|
|
@@ -95,6 +95,17 @@ export async function prepareStartupConfig(recoverRoleMutations, onStep) {
|
|
|
95
95
|
logger.info(`[config] ${detail.file}${detail.removed.length ? `: removed ${detail.removed.join(', ')}` : ''}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
step('providerIdentity');
|
|
99
|
+
const providerIdentityMigration = await ensureProviderIdentityMigrationOnStartup();
|
|
100
|
+
if (providerIdentityMigration) {
|
|
101
|
+
const message = `Provider domain ID migration: ${providerIdentityMigration.summary.providersMigrated} provider(s), ${providerIdentityMigration.changedFiles} file(s)`
|
|
102
|
+
+ (providerIdentityMigration.backup ? `; backup: ${providerIdentityMigration.backup}` : '');
|
|
103
|
+
logger.info(message);
|
|
104
|
+
console.error(message);
|
|
105
|
+
if (providerIdentityMigration.pending.length) {
|
|
106
|
+
logger.warn(`[config] Provider domain required for legacy entries: ${providerIdentityMigration.pending.join(', ')}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
98
109
|
step('accessPolicy');
|
|
99
110
|
const accessPolicyMigration = await ensureAccessPolicyMigrationOnStartup();
|
|
100
111
|
if (accessPolicyMigration) {
|
|
@@ -1077,7 +1077,7 @@ export function mutateConfig(target, sel, mutate) {
|
|
|
1077
1077
|
release();
|
|
1078
1078
|
}
|
|
1079
1079
|
}
|
|
1080
|
-
/**
|
|
1080
|
+
/** Retire both local compatibility fields after freshly confirmed protocol ownership. */
|
|
1081
1081
|
export function clearConfiguredOwnerAfterConsensus(subjectAid, ownerAid) {
|
|
1082
1082
|
const normalizedOwnerAid = ownerAid.trim();
|
|
1083
1083
|
if (!isValidAid(normalizedOwnerAid) || subjectAid === ownerResolver.getDaemonAid())
|
|
@@ -1092,17 +1092,8 @@ export function clearConfiguredOwnerAfterConsensus(subjectAid, ownerAid) {
|
|
|
1092
1092
|
return mutateConfig(ConfigTarget.Agent, { self: subjectAid }, config => {
|
|
1093
1093
|
if (!isConfirmed())
|
|
1094
1094
|
return;
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
if (!Array.isArray(config.owners))
|
|
1098
|
-
return;
|
|
1099
|
-
const owners = config.owners.filter((owner) => typeof owner !== 'string' || owner.trim() !== normalizedOwnerAid);
|
|
1100
|
-
if (owners.length === config.owners.length)
|
|
1101
|
-
return;
|
|
1102
|
-
if (owners.length > 0)
|
|
1103
|
-
config.owners = owners;
|
|
1104
|
-
else
|
|
1105
|
-
delete config.owners;
|
|
1095
|
+
delete config.owner;
|
|
1096
|
+
delete config.owners;
|
|
1106
1097
|
}).changed;
|
|
1107
1098
|
}
|
|
1108
1099
|
function cloneConfigValue(value) {
|
|
@@ -1120,7 +1111,7 @@ function sortConfigValue(value) {
|
|
|
1120
1111
|
.sort(([left], [right]) => left.localeCompare(right))
|
|
1121
1112
|
.map(([key, nested]) => [key, sortConfigValue(nested)]));
|
|
1122
1113
|
}
|
|
1123
|
-
function acquireConfigMutationLock(file) {
|
|
1114
|
+
export function acquireConfigMutationLock(file) {
|
|
1124
1115
|
const lockDir = resolveManagedLockPath('config', file, `${file}.mutation.lock`);
|
|
1125
1116
|
const ownerFile = path.join(lockDir, 'owner.json');
|
|
1126
1117
|
const token = crypto.randomBytes(16).toString('hex');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const SERVICE_RESTART_MAX_ATTEMPTS = 3;
|
|
2
2
|
export const SERVICE_RESTART_WINDOW_MS = 900000;
|
|
3
3
|
export const SERVICE_RESTART_BACKOFF_MS = 5000;
|
|
4
|
+
export const SERVICE_STARTUP_TIMEOUT_MS = 45000;
|
|
4
5
|
export const SERVICE_HEALTH_INTERVALS = {
|
|
5
6
|
tcp: { startup: 500, running: 10000 },
|
|
6
7
|
http: { startup: 1000, running: 15000 },
|
|
@@ -13,7 +13,7 @@ import { configuredOwnerList } from './owner-config.js';
|
|
|
13
13
|
import { tryParseChannelKey } from '../core/channel-loader.js';
|
|
14
14
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
15
15
|
import { getOwners, ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
16
|
-
import {
|
|
16
|
+
import { sameOwnerQualification, sameOwnerRevision, requiresSameOwnerProof } from '../core/relation/same-owner-proof.js';
|
|
17
17
|
import { readRoleStore } from './role-store.js';
|
|
18
18
|
export function isAuthenticated(userId) {
|
|
19
19
|
return isValidAid(String(userId || '').trim());
|
|
@@ -60,7 +60,7 @@ export function getFirstStaticAgentOwner(aid) {
|
|
|
60
60
|
}
|
|
61
61
|
/** Revision for security-sensitive owner/contact/relation authorization inputs. */
|
|
62
62
|
export function authorizationConfigRevision(aid) {
|
|
63
|
-
const fingerprints = [ownerResolver.revision(aid),
|
|
63
|
+
const fingerprints = [ownerResolver.revision(aid), sameOwnerRevision(aid),
|
|
64
64
|
JSON.stringify(readRoleStore(aid)), fileRevision(agentConfig(aid)), fileRevision(agentPeerConfig(aid))];
|
|
65
65
|
const relations = agentRelationsDir(aid);
|
|
66
66
|
try {
|
|
@@ -105,8 +105,8 @@ export function resolvePeerRoleDetail(ctx) {
|
|
|
105
105
|
}
|
|
106
106
|
const actorRole = resolveActorDirectRole(ctx.selfAid, actor, channelType, operatorId);
|
|
107
107
|
if (channelType === 'aun' && ctx.chatType === 'private' && hasTrustedPrincipal(actor)
|
|
108
|
-
&& (
|
|
109
|
-
||
|
|
108
|
+
&& (sameOwnerQualification(ctx.selfAid, actor.principalId) === 'matched'
|
|
109
|
+
|| requiresSameOwnerProof(ctx.selfAid, actor.principalId))) {
|
|
110
110
|
const ownerCandidate = candidates.find(candidate => candidate.role === 'owner');
|
|
111
111
|
if (ownerCandidate)
|
|
112
112
|
return resultFor('owner', 'agent-owner', actor, ctx.selfAid);
|
|
@@ -114,7 +114,7 @@ export function resolvePeerRoleDetail(ctx) {
|
|
|
114
114
|
if (relation?.role !== undefined && relation.role !== null) {
|
|
115
115
|
return resultFor(actorRole, 'relation-actor', actor, ctx.selfAid);
|
|
116
116
|
}
|
|
117
|
-
if (
|
|
117
|
+
if (sameOwnerQualification(ctx.selfAid, actor.principalId) !== 'matched') {
|
|
118
118
|
return resultFor(null, 'none', actor, ctx.selfAid);
|
|
119
119
|
}
|
|
120
120
|
const store = readRoleStore(ctx.selfAid);
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
4
|
+
import { providerIdentity } from './provider-identity.js';
|
|
5
|
+
import { providerEnvironmentVariable } from './providers-config.js';
|
|
6
|
+
import { validateProvidersFile } from './providers-config.js';
|
|
7
|
+
export function planProviderIdentityMigration(home, registry) {
|
|
8
|
+
const changes = [];
|
|
9
|
+
const expected = [];
|
|
10
|
+
const summary = { providersMigrated: 0, skippedProviders: 0, filesChanged: 0, referencesUpdated: 0 };
|
|
11
|
+
const pending = [];
|
|
12
|
+
const providerFile = path.join(home, 'providers.json');
|
|
13
|
+
const readJson = (file) => {
|
|
14
|
+
if (fs.lstatSync(file).isSymbolicLink())
|
|
15
|
+
throw new Error('Provider migration does not follow configuration symlinks');
|
|
16
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
17
|
+
expected.push({ file, before: text });
|
|
18
|
+
const value = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
|
|
19
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
20
|
+
throw new Error('Provider migration requires object configurations');
|
|
21
|
+
return { text, value: value };
|
|
22
|
+
};
|
|
23
|
+
if (!fs.existsSync(providerFile) && !registry)
|
|
24
|
+
return { home, changes, summary, pending, expected, registry: { providers: {} } };
|
|
25
|
+
const original = fs.existsSync(providerFile) ? readJson(providerFile) : { text: null, value: { providers: {} } };
|
|
26
|
+
if (original.text === null)
|
|
27
|
+
expected.push({ file: providerFile, before: null });
|
|
28
|
+
const source = validateProvidersFile(registry ?? original.value);
|
|
29
|
+
const providers = {};
|
|
30
|
+
const mapping = {};
|
|
31
|
+
const sourceIds = new Map();
|
|
32
|
+
const mergeServicesFrom = (target, source, providerIds) => {
|
|
33
|
+
const targetBase = target.common.baseUrl;
|
|
34
|
+
const sourceBase = source.common.baseUrl;
|
|
35
|
+
const staticUrls = !providerEnvironmentVariable(targetBase) && !providerEnvironmentVariable(sourceBase);
|
|
36
|
+
const conflicts = [];
|
|
37
|
+
const targetCommon = { ...target.common, baseUrl: staticUrls ? new URL(targetBase).origin : targetBase };
|
|
38
|
+
const sourceCommon = { ...source.common, baseUrl: staticUrls ? new URL(sourceBase).origin : sourceBase };
|
|
39
|
+
for (const field of ['baseUrl', 'apiKey', 'headers', 'queryParams']) {
|
|
40
|
+
if (!isDeepStrictEqual(targetCommon[field], sourceCommon[field]))
|
|
41
|
+
conflicts.push(`common.${field}`);
|
|
42
|
+
}
|
|
43
|
+
const services = { ...(target.services ?? {}) };
|
|
44
|
+
for (const [serviceType, rawService] of Object.entries(source.services ?? {})) {
|
|
45
|
+
let service = rawService;
|
|
46
|
+
if (staticUrls && targetBase !== sourceBase && new URL(targetBase).origin === new URL(sourceBase).origin) {
|
|
47
|
+
const resolved = new URL(rawService.path || '.', sourceBase.endsWith('/') ? sourceBase : `${sourceBase}/`);
|
|
48
|
+
service = { ...rawService, path: `${resolved.pathname}${resolved.search}${resolved.hash}` };
|
|
49
|
+
}
|
|
50
|
+
if (Object.hasOwn(services, serviceType)) {
|
|
51
|
+
const existing = services[serviceType];
|
|
52
|
+
const equivalent = staticUrls
|
|
53
|
+
? new URL(existing.path || '.', targetBase.endsWith('/') ? targetBase : `${targetBase}/`).href.replace(/\/+$/u, '')
|
|
54
|
+
=== new URL(rawService.path || '.', sourceBase.endsWith('/') ? sourceBase : `${sourceBase}/`).href.replace(/\/+$/u, '')
|
|
55
|
+
&& isDeepStrictEqual({ ...existing, path: undefined }, { ...rawService, path: undefined })
|
|
56
|
+
: isDeepStrictEqual(existing, service);
|
|
57
|
+
if (!equivalent) {
|
|
58
|
+
const sameEndpoint = staticUrls
|
|
59
|
+
? new URL(existing.path || '.', targetBase.endsWith('/') ? targetBase : `${targetBase}/`).href.replace(/\/+$/u, '')
|
|
60
|
+
=== new URL(rawService.path || '.', sourceBase.endsWith('/') ? sourceBase : `${sourceBase}/`).href.replace(/\/+$/u, '')
|
|
61
|
+
: isDeepStrictEqual(existing.path, service.path);
|
|
62
|
+
if (!sameEndpoint)
|
|
63
|
+
conflicts.push(`services.${serviceType}.path`);
|
|
64
|
+
for (const field of ['style', 'models']) {
|
|
65
|
+
if (!isDeepStrictEqual(existing[field], service[field]))
|
|
66
|
+
conflicts.push(`services.${serviceType}.${field}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
services[serviceType] = service;
|
|
72
|
+
}
|
|
73
|
+
if (conflicts.length) {
|
|
74
|
+
throw Object.assign(new Error('Provider migration conflicts; no configuration was changed'), {
|
|
75
|
+
code: 'PROVIDER_CONFLICT',
|
|
76
|
+
data: { kind: 'provider_migration_conflict', providerIds, domain: target.domain, fields: conflicts },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
target.services = services;
|
|
80
|
+
};
|
|
81
|
+
for (const [oldId, provider] of Object.entries(source.providers).sort(([left], [right]) => left.localeCompare(right))) {
|
|
82
|
+
let identity;
|
|
83
|
+
try {
|
|
84
|
+
identity = providerIdentity(provider);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const errorCode = error?.code;
|
|
88
|
+
const legacyUnresolved = provider.domain === undefined && (providerEnvironmentVariable(provider.common.baseUrl)
|
|
89
|
+
? errorCode === 'PROVIDER_DOMAIN_REQUIRED' : errorCode === 'PROVIDER_DOMAIN_INVALID');
|
|
90
|
+
if (!legacyUnresolved)
|
|
91
|
+
throw error;
|
|
92
|
+
if (Object.hasOwn(providers, oldId)) {
|
|
93
|
+
throw Object.assign(new Error(`Provider ID collision with a legacy entry: ${oldId}`), { code: 'PROVIDER_ID_COLLISION' });
|
|
94
|
+
}
|
|
95
|
+
providers[oldId] = provider;
|
|
96
|
+
pending.push(oldId);
|
|
97
|
+
summary.skippedProviders++;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const normalized = { ...provider, domain: identity.domain };
|
|
101
|
+
const existing = providers[identity.providerId];
|
|
102
|
+
if (existing) {
|
|
103
|
+
if (existing.domain !== identity.domain) {
|
|
104
|
+
throw Object.assign(new Error(`Provider ID collision: ${identity.providerId}`), { code: 'PROVIDER_ID_COLLISION' });
|
|
105
|
+
}
|
|
106
|
+
mergeServicesFrom(existing, normalized, [...sourceIds.get(identity.providerId), oldId]);
|
|
107
|
+
sourceIds.get(identity.providerId).push(oldId);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
providers[identity.providerId] = normalized;
|
|
111
|
+
sourceIds.set(identity.providerId, [oldId]);
|
|
112
|
+
}
|
|
113
|
+
if (oldId !== identity.providerId) {
|
|
114
|
+
mapping[oldId] = identity.providerId;
|
|
115
|
+
summary.providersMigrated++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const aliases = {};
|
|
119
|
+
for (const [alias, target] of Object.entries(source.aliases ?? {}))
|
|
120
|
+
aliases[alias] = mapping[target] ?? target;
|
|
121
|
+
Object.assign(aliases, mapping);
|
|
122
|
+
for (const [alias, target] of Object.entries(aliases)) {
|
|
123
|
+
if (Object.hasOwn(providers, alias))
|
|
124
|
+
throw new Error(`Provider ID conflicts with an old ID: ${alias} -> ${target}`);
|
|
125
|
+
}
|
|
126
|
+
const normalizedRegistry = validateProvidersFile({ $schema_version: 2, providers, ...(Object.keys(aliases).length ? { aliases } : {}) });
|
|
127
|
+
const queue = (file, before, value) => {
|
|
128
|
+
changes.push({ file, kind: 'provider-domain-id', before, after: JSON.stringify(value, null, 2) + String.fromCharCode(10) });
|
|
129
|
+
summary.filesChanged++;
|
|
130
|
+
};
|
|
131
|
+
if (!isDeepStrictEqual(original.value, normalizedRegistry))
|
|
132
|
+
queue(providerFile, original.text, normalizedRegistry);
|
|
133
|
+
if (!Object.keys(aliases).length)
|
|
134
|
+
return { home, changes, summary, pending, expected, registry: normalizedRegistry };
|
|
135
|
+
const agentsDir = path.join(home, 'agents');
|
|
136
|
+
if (!fs.existsSync(agentsDir))
|
|
137
|
+
return { home, changes, summary, pending, expected, registry: normalizedRegistry };
|
|
138
|
+
if (fs.lstatSync(agentsDir).isSymbolicLink())
|
|
139
|
+
throw new Error('Provider migration does not follow agent directory symlinks');
|
|
140
|
+
const files = [path.join(agentsDir, 'defaults.json')];
|
|
141
|
+
for (const agent of fs.readdirSync(agentsDir, { withFileTypes: true })) {
|
|
142
|
+
if (!agent.isDirectory() || !/^[a-z0-9-]+(?:[.][a-z0-9-]+){2,}$/iu.test(agent.name))
|
|
143
|
+
continue;
|
|
144
|
+
const agentDir = path.join(agentsDir, agent.name);
|
|
145
|
+
files.push(path.join(agentDir, 'config.json'));
|
|
146
|
+
const relations = path.join(agentDir, 'relations');
|
|
147
|
+
if (!fs.existsSync(relations))
|
|
148
|
+
continue;
|
|
149
|
+
if (fs.lstatSync(relations).isSymbolicLink())
|
|
150
|
+
throw new Error('Provider migration does not follow relation directory symlinks');
|
|
151
|
+
for (const relation of fs.readdirSync(relations, { withFileTypes: true })) {
|
|
152
|
+
if (relation.isDirectory())
|
|
153
|
+
files.push(path.join(relations, relation.name, 'config.json'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const rewriteSelection = (value) => {
|
|
157
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
158
|
+
return 0;
|
|
159
|
+
let count = 0;
|
|
160
|
+
const selection = value;
|
|
161
|
+
if (typeof selection.provider === 'string' && Object.hasOwn(aliases, selection.provider)) {
|
|
162
|
+
selection.provider = aliases[selection.provider];
|
|
163
|
+
count++;
|
|
164
|
+
}
|
|
165
|
+
if (Array.isArray(selection.fallback)) {
|
|
166
|
+
for (const fallback of selection.fallback) {
|
|
167
|
+
if (fallback && typeof fallback === 'object' && !Array.isArray(fallback)) {
|
|
168
|
+
const candidate = fallback;
|
|
169
|
+
if (typeof candidate.provider === 'string' && Object.hasOwn(aliases, candidate.provider)) {
|
|
170
|
+
candidate.provider = aliases[candidate.provider];
|
|
171
|
+
count++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return count;
|
|
177
|
+
};
|
|
178
|
+
const rewriteSelections = (value) => {
|
|
179
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
180
|
+
return 0;
|
|
181
|
+
let count = 0;
|
|
182
|
+
for (const entry of Object.values(value)) {
|
|
183
|
+
count += rewriteSelection(entry);
|
|
184
|
+
}
|
|
185
|
+
return count;
|
|
186
|
+
};
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
if (!fs.existsSync(file))
|
|
189
|
+
continue;
|
|
190
|
+
const parsed = readJson(file);
|
|
191
|
+
let count = 0;
|
|
192
|
+
count += rewriteSelections(parsed.value.baseagents);
|
|
193
|
+
count += rewriteSelections(parsed.value.agents);
|
|
194
|
+
count += rewriteSelections(parsed.value.Services);
|
|
195
|
+
count += rewriteSelection(parsed.value.decision_model);
|
|
196
|
+
if (!count)
|
|
197
|
+
continue;
|
|
198
|
+
summary.referencesUpdated += count;
|
|
199
|
+
queue(file, parsed.text, parsed.value);
|
|
200
|
+
}
|
|
201
|
+
return { home, changes, summary, pending, expected, registry: normalizedRegistry };
|
|
202
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { isIP } from 'node:net';
|
|
3
|
+
import { domainToASCII } from 'node:url';
|
|
4
|
+
import { registrableProviderDomain } from '../utils/public-suffix.js';
|
|
5
|
+
export function normalizeProviderDomain(value) {
|
|
6
|
+
if (typeof value !== 'string' || !value.trim() || /[\s/\\:@?#%]/u.test(value.trim())) {
|
|
7
|
+
throw Object.assign(new Error('Provider domain must be a hostname without a scheme, port or path'), { code: 'PROVIDER_DOMAIN_INVALID' });
|
|
8
|
+
}
|
|
9
|
+
const domain = domainToASCII(value.trim().replace(/\.$/u, '')).toLowerCase();
|
|
10
|
+
const labels = domain.split('.');
|
|
11
|
+
if (domain.length > 253 || labels.length < 2 || isIP(domain)
|
|
12
|
+
|| labels.some(label => label.length > 63 || !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(label))) {
|
|
13
|
+
throw Object.assign(new Error('Provider domain must be a valid DNS hostname'), { code: 'PROVIDER_DOMAIN_INVALID' });
|
|
14
|
+
}
|
|
15
|
+
const registrable = registrableProviderDomain(domain);
|
|
16
|
+
if (!registrable)
|
|
17
|
+
throw Object.assign(new Error('Provider domain must include a name before the public suffix'), { code: 'PROVIDER_DOMAIN_INVALID' });
|
|
18
|
+
return domain === registrable ? `www.${domain}` : domain;
|
|
19
|
+
}
|
|
20
|
+
export function providerIdFromDomain(domain) {
|
|
21
|
+
const canonical = normalizeProviderDomain(domain);
|
|
22
|
+
const digest = createHash('sha256').update(canonical, 'utf8').digest('hex');
|
|
23
|
+
return `provider-${(BigInt(`0x${digest}`) % 100000000n).toString().padStart(8, '0')}`;
|
|
24
|
+
}
|
|
25
|
+
export function providerIdentity(provider) {
|
|
26
|
+
const baseUrl = provider.common.baseUrl;
|
|
27
|
+
const environmentReference = /^\$(?:[A-Za-z_][A-Za-z0-9_]*|\{[A-Za-z_][A-Za-z0-9_]*\})$/u.test(baseUrl);
|
|
28
|
+
if (environmentReference && provider.domain === undefined) {
|
|
29
|
+
throw Object.assign(new Error('Provider domain is required when common.baseUrl is an environment reference'), { code: 'PROVIDER_DOMAIN_REQUIRED' });
|
|
30
|
+
}
|
|
31
|
+
const endpointDomain = environmentReference ? undefined : normalizeProviderDomain(new URL(baseUrl).hostname);
|
|
32
|
+
const domain = provider.domain === undefined ? endpointDomain : normalizeProviderDomain(provider.domain);
|
|
33
|
+
if (endpointDomain !== undefined && domain !== endpointDomain) {
|
|
34
|
+
throw Object.assign(new Error('Provider domain must match the normalized common.baseUrl hostname'), { code: 'PROVIDER_DOMAIN_MISMATCH' });
|
|
35
|
+
}
|
|
36
|
+
return { domain, providerId: providerIdFromDomain(domain) };
|
|
37
|
+
}
|
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { TextDecoder } from 'node:util';
|
|
4
4
|
import { auditCommandAuthorization } from '../core/auth/authorization-audit.js';
|
|
5
5
|
import { createProvider, parseProviderImport, readProvidersSnapshot, updateProvider } from './providers-management.js';
|
|
6
|
+
import { resolveProviderId } from './providers-config.js';
|
|
6
7
|
export const PROVIDER_INPUT_LIMIT = 1024 * 1024;
|
|
7
8
|
export function providerArgumentError(message) {
|
|
8
9
|
throw Object.assign(new Error(message), { code: 'INVALID_ARGUMENT' });
|
|
@@ -18,7 +19,7 @@ export function parseProviderCommand(argv) {
|
|
|
18
19
|
providerArgumentError('provider.op requires Provider argv');
|
|
19
20
|
}
|
|
20
21
|
const operation = argv[1];
|
|
21
|
-
if (!['list', 'show', 'create', 'import', 'update', 'delete'].includes(operation)) {
|
|
22
|
+
if (!['list', 'show', 'create', 'import', 'update', 'delete', 'sync'].includes(operation)) {
|
|
22
23
|
providerArgumentError('Unsupported Provider command');
|
|
23
24
|
}
|
|
24
25
|
const options = new Map();
|
|
@@ -70,6 +71,37 @@ export function providerFailure(error) {
|
|
|
70
71
|
const failure = error;
|
|
71
72
|
if (failure?.code === 'NOT_FOUND')
|
|
72
73
|
return { ok: false, code: 'NOT_FOUND', error: 'Provider not found' };
|
|
74
|
+
if (failure?.code === 'PROVIDER_CONFLICT' && failure.data && typeof failure.data === 'object') {
|
|
75
|
+
const details = failure.data;
|
|
76
|
+
if (details.kind === 'provider_migration_conflict'
|
|
77
|
+
&& Array.isArray(details.providerIds) && details.providerIds.length >= 2 && details.providerIds.length <= 100
|
|
78
|
+
&& details.providerIds.every(value => typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/u.test(value))
|
|
79
|
+
&& typeof details.domain === 'string' && details.domain.length <= 253
|
|
80
|
+
&& /^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/u.test(details.domain)
|
|
81
|
+
&& Array.isArray(details.fields) && details.fields.length > 0 && details.fields.length <= 100
|
|
82
|
+
&& details.fields.every(value => typeof value === 'string' && value.length <= 160
|
|
83
|
+
&& /^(?:common\.(?:baseUrl|apiKey|headers|queryParams)|services\.[A-Za-z0-9_-]+\.(?:path|style|models))$/u.test(value))) {
|
|
84
|
+
const data = { kind: details.kind, providerIds: details.providerIds, domain: details.domain, fields: details.fields };
|
|
85
|
+
return { ok: false, code: 'PROVIDER_CONFLICT', data,
|
|
86
|
+
error: `Provider migration conflict between ${data.providerIds.join(', ')} (${data.domain}): ${data.fields.join(', ')} differ; reconcile these fields and retry ec provider sync. Credential fields compare configured values/references, not resolved secrets. No configuration was changed` };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const identityErrors = {
|
|
90
|
+
PROVIDER_ID_COLLISION: 'Provider ID hash collision or reserved legacy ID; no ID was reassigned',
|
|
91
|
+
PROVIDER_CONFLICT: 'Provider domain already exists; update or explicitly merge the existing Provider',
|
|
92
|
+
PROVIDER_DOMAIN_REQUIRED: 'Provider domain is required when common.baseUrl is an environment reference',
|
|
93
|
+
PROVIDER_DOMAIN_INVALID: 'Provider domain must be a valid DNS hostname without a scheme, port or path',
|
|
94
|
+
PROVIDER_DOMAIN_MISMATCH: 'Provider domain must match the normalized common.baseUrl hostname',
|
|
95
|
+
PROVIDER_DOMAIN_IMMUTABLE: 'Provider domain is immutable; create a different Provider',
|
|
96
|
+
PROVIDER_ENV_BASE_URL_MISSING: 'A Provider base URL environment variable is unset or empty in the daemon; no configuration was changed',
|
|
97
|
+
PROVIDER_ENV_BASE_URL_INVALID: 'A Provider base URL environment variable is not a valid HTTP(S) URL; no configuration was changed',
|
|
98
|
+
PROVIDER_CATALOG_UNAVAILABLE: 'Cannot load a fresh preferred Provider model catalog; no configuration was changed',
|
|
99
|
+
PROVIDER_SERVICE_UNAVAILABLE: 'The preferred Provider has no usable ecagent/text connection; no configuration was changed',
|
|
100
|
+
PROVIDER_MODEL_NOT_FOUND: 'The preferred Provider has no enabled DeepSeek Flash model; no configuration was changed',
|
|
101
|
+
};
|
|
102
|
+
if (failure?.code && Object.hasOwn(identityErrors, failure.code)) {
|
|
103
|
+
return { ok: false, code: failure.code, error: identityErrors[failure.code] };
|
|
104
|
+
}
|
|
73
105
|
if (failure?.code === 'CONFLICT' || failure?.statusCode === 409) {
|
|
74
106
|
return { ok: false, code: 'CONFLICT', error: 'Provider configuration changed or is still referenced', data: failure.data };
|
|
75
107
|
}
|
|
@@ -119,15 +151,20 @@ export async function executeProviderOperation(command) {
|
|
|
119
151
|
/** Shared business execution; callers must authorize before reading input files. */
|
|
120
152
|
export async function executeParsedProviderOperation(parsed) {
|
|
121
153
|
try {
|
|
154
|
+
if (parsed.operation === 'sync') {
|
|
155
|
+
const { syncLocalProviders } = await import('./provider-local-sync.js');
|
|
156
|
+
return { ok: true, data: await syncLocalProviders() };
|
|
157
|
+
}
|
|
122
158
|
const text = parsed.file ? readProviderInput(parsed.file) : undefined;
|
|
123
159
|
const snapshot = readProvidersSnapshot();
|
|
124
160
|
if (parsed.operation === 'list')
|
|
125
161
|
return { ok: true, data: snapshot };
|
|
126
162
|
if (parsed.operation === 'show') {
|
|
127
|
-
const
|
|
163
|
+
const providerId = resolveProviderId(parsed.providerId, snapshot);
|
|
164
|
+
const provider = snapshot.providers[providerId];
|
|
128
165
|
if (!provider)
|
|
129
166
|
throw Object.assign(new Error('Provider not found'), { code: 'NOT_FOUND' });
|
|
130
|
-
return { ok: true, data: { providerId
|
|
167
|
+
return { ok: true, data: { providerId, provider, revision: snapshot.revision } };
|
|
131
168
|
}
|
|
132
169
|
const value = parsed.operation === 'import' ? parseProviderImport(text)
|
|
133
170
|
: text === undefined ? undefined : parseProviderObject(text);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { resolvePaths } from '../paths.js';
|
|
4
|
+
import { previewProviderCatalog } from '../core/model/model-catalog.js';
|
|
5
|
+
import { ConfigTarget, notifyConfigWrite, validateConfig } from './config-manager.js';
|
|
6
|
+
import { loadSchema } from './schema-registry.js';
|
|
7
|
+
import { providerEnvironmentVariable, resolveProviderId, resolveProviderServiceForBaseagent, validateProvidersFile } from './providers-config.js';
|
|
8
|
+
import { providerIdentity } from './provider-identity.js';
|
|
9
|
+
import { listBaseagentImportSources, providerFromBaseagent } from './providers-import.js';
|
|
10
|
+
import { importBaseagentProviderIntoRegistry } from './providers-management.js';
|
|
11
|
+
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
12
|
+
import { commitProviderSyncMigration } from './schema-migration.js';
|
|
13
|
+
const PREFERRED_PROVIDER = 'provider-96659517';
|
|
14
|
+
export function selectDeepseekFlashModel(models) {
|
|
15
|
+
return models.filter(model => /^deepseek(?:[-._].*)?[-._]flash$/iu.test(model.id) && model.verification === 'listed')
|
|
16
|
+
.sort((left, right) => right.id.localeCompare(left.id, 'en', { numeric: true })
|
|
17
|
+
|| (right.created ?? 0) - (left.created ?? 0))[0];
|
|
18
|
+
}
|
|
19
|
+
export async function syncLocalProviders() {
|
|
20
|
+
const home = resolvePaths().root;
|
|
21
|
+
const providerFile = resolvePaths().providersConfig;
|
|
22
|
+
if (fs.existsSync(providerFile) && fs.lstatSync(providerFile).isSymbolicLink()) {
|
|
23
|
+
throw Object.assign(new Error('Provider sync does not follow configuration symlinks'), { code: 'INVALID_ARGUMENT' });
|
|
24
|
+
}
|
|
25
|
+
const providersBefore = fs.existsSync(providerFile) ? fs.readFileSync(providerFile, 'utf8') : null;
|
|
26
|
+
const registry = validateProvidersFile(providersBefore === null ? { providers: {} }
|
|
27
|
+
: JSON.parse(providersBefore.replace(/^\uFEFF/u, '')));
|
|
28
|
+
const environment = { ...process.env };
|
|
29
|
+
let materializedBaseUrls = 0;
|
|
30
|
+
const materializeBaseUrl = (provider) => {
|
|
31
|
+
const variable = providerEnvironmentVariable(provider.common.baseUrl);
|
|
32
|
+
if (!variable)
|
|
33
|
+
return provider;
|
|
34
|
+
const baseUrl = environment[variable]?.trim();
|
|
35
|
+
if (!baseUrl) {
|
|
36
|
+
throw Object.assign(new Error(`Provider base URL environment variable ${variable} is unset or empty; no configuration was changed`), { code: 'PROVIDER_ENV_BASE_URL_MISSING' });
|
|
37
|
+
}
|
|
38
|
+
let resolved;
|
|
39
|
+
try {
|
|
40
|
+
if (providerEnvironmentVariable(baseUrl))
|
|
41
|
+
throw new Error('Nested environment reference');
|
|
42
|
+
resolved = validateProvidersFile({ providers: { resolved: {
|
|
43
|
+
...provider, common: { ...provider.common, baseUrl },
|
|
44
|
+
} } }).providers.resolved;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error?.code === 'PROVIDER_DOMAIN_MISMATCH')
|
|
48
|
+
throw error;
|
|
49
|
+
throw Object.assign(new Error(`Provider base URL environment variable ${variable} is not a valid HTTP(S) URL; no configuration was changed`), { code: 'PROVIDER_ENV_BASE_URL_INVALID' });
|
|
50
|
+
}
|
|
51
|
+
resolved.domain = providerIdentity(resolved).domain;
|
|
52
|
+
materializedBaseUrls++;
|
|
53
|
+
return resolved;
|
|
54
|
+
};
|
|
55
|
+
for (const [providerId, provider] of Object.entries(registry.providers)) {
|
|
56
|
+
registry.providers[providerId] = materializeBaseUrl(provider);
|
|
57
|
+
}
|
|
58
|
+
planProviderIdentityMigration(home, registry);
|
|
59
|
+
const imports = listBaseagentImportSources().map(source => {
|
|
60
|
+
const result = importBaseagentProviderIntoRegistry(registry, { value: materializeBaseUrl(providerFromBaseagent(source.baseagent)) });
|
|
61
|
+
return { baseagent: source.baseagent, providerId: result.providerId, merged: result.merged };
|
|
62
|
+
});
|
|
63
|
+
const plan = planProviderIdentityMigration(home, registry);
|
|
64
|
+
if (plan.expected.find(item => item.file === providerFile)?.before !== providersBefore) {
|
|
65
|
+
throw Object.assign(new Error('Providers changed during scanning; retry after reviewing the current configuration'), { code: 'CONFLICT' });
|
|
66
|
+
}
|
|
67
|
+
const defaultsFile = path.join(home, 'agents', 'defaults.json');
|
|
68
|
+
const defaultsChange = plan.changes.find(change => change.file === defaultsFile);
|
|
69
|
+
if (fs.existsSync(defaultsFile) && fs.lstatSync(defaultsFile).isSymbolicLink()) {
|
|
70
|
+
throw Object.assign(new Error('Provider sync does not follow configuration symlinks'), { code: 'INVALID_ARGUMENT' });
|
|
71
|
+
}
|
|
72
|
+
const before = defaultsChange?.before ?? (fs.existsSync(defaultsFile) ? fs.readFileSync(defaultsFile, 'utf8') : null);
|
|
73
|
+
if (!plan.expected.some(item => item.file === defaultsFile))
|
|
74
|
+
plan.expected.push({ file: defaultsFile, before });
|
|
75
|
+
const defaults = defaultsChange ? JSON.parse(defaultsChange.after)
|
|
76
|
+
: before === null ? {} : JSON.parse(before.replace(/^\uFEFF/u, ''));
|
|
77
|
+
if (!defaults || typeof defaults !== 'object' || Array.isArray(defaults)) {
|
|
78
|
+
throw Object.assign(new Error('Defaults must be an object'), { code: 'INVALID_ARGUMENT' });
|
|
79
|
+
}
|
|
80
|
+
const warnings = [];
|
|
81
|
+
let selectedModel;
|
|
82
|
+
if (Object.hasOwn(plan.registry.providers, PREFERRED_PROVIDER)) {
|
|
83
|
+
let connection;
|
|
84
|
+
try {
|
|
85
|
+
connection = resolveProviderServiceForBaseagent(PREFERRED_PROVIDER, 'ecagent', undefined, plan.registry);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw Object.assign(new Error('The preferred Provider has no usable ecagent/text connection; no configuration was changed'), { code: 'PROVIDER_SERVICE_UNAVAILABLE' });
|
|
89
|
+
}
|
|
90
|
+
const catalog = await previewProviderCatalog(connection, 'ecagent').catch(() => {
|
|
91
|
+
throw Object.assign(new Error('Cannot fetch the preferred Provider model catalog; no configuration was changed'), { code: 'PROVIDER_CATALOG_UNAVAILABLE' });
|
|
92
|
+
});
|
|
93
|
+
if (catalog.source !== 'gateway' || catalog.freshness !== 'fresh') {
|
|
94
|
+
throw Object.assign(new Error('A fresh Provider model catalog is required; no configuration was changed'), { code: 'PROVIDER_CATALOG_UNAVAILABLE' });
|
|
95
|
+
}
|
|
96
|
+
const model = selectDeepseekFlashModel(catalog.models.filter(entry => connection.modelOverrides[entry.aliasFor ?? entry.id]?.enabled !== false));
|
|
97
|
+
if (!model) {
|
|
98
|
+
throw Object.assign(new Error('The preferred Provider has no enabled DeepSeek Flash model; no configuration was changed'), { code: 'PROVIDER_MODEL_NOT_FOUND' });
|
|
99
|
+
}
|
|
100
|
+
defaults.baseagents ??= {};
|
|
101
|
+
defaults.baseagents.ecagent ??= {};
|
|
102
|
+
const selection = defaults.baseagents.ecagent;
|
|
103
|
+
selection.provider = PREFERRED_PROVIDER;
|
|
104
|
+
selection.model = model.id;
|
|
105
|
+
if (selection.effort && !model.reasoningLevels?.includes(selection.effort))
|
|
106
|
+
delete selection.effort;
|
|
107
|
+
selectedModel = model.id;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
warnings.push('PREFERRED_PROVIDER_NOT_FOUND');
|
|
111
|
+
}
|
|
112
|
+
if (!imports.length)
|
|
113
|
+
warnings.push('NO_LOCAL_PROVIDER_SOURCES');
|
|
114
|
+
if (plan.pending.length)
|
|
115
|
+
warnings.push('LEGACY_PROVIDER_DOMAIN_REQUIRED');
|
|
116
|
+
defaults.$schema_version ??= loadSchema('defaults').version;
|
|
117
|
+
defaults.active_baseagent = 'ecagent';
|
|
118
|
+
const errors = validateConfig(ConfigTarget.Defaults, defaults);
|
|
119
|
+
if (errors.length)
|
|
120
|
+
throw Object.assign(new Error('Defaults validation failed; no configuration was changed'), { code: 'INVALID_ARGUMENT' });
|
|
121
|
+
const after = JSON.stringify(defaults, null, 2) + '\n';
|
|
122
|
+
if (after !== before) {
|
|
123
|
+
if (defaultsChange)
|
|
124
|
+
defaultsChange.after = after;
|
|
125
|
+
else
|
|
126
|
+
plan.changes.push({ file: defaultsFile, kind: 'provider-domain-id', before, after });
|
|
127
|
+
}
|
|
128
|
+
plan.summary.filesChanged = plan.changes.length;
|
|
129
|
+
const backup = commitProviderSyncMigration(plan);
|
|
130
|
+
for (const change of plan.changes) {
|
|
131
|
+
const parts = path.relative(home, change.file).split(path.sep);
|
|
132
|
+
if (parts[0] === 'providers.json')
|
|
133
|
+
notifyConfigWrite(ConfigTarget.Providers);
|
|
134
|
+
else if (parts[1] === 'defaults.json')
|
|
135
|
+
notifyConfigWrite(ConfigTarget.Defaults);
|
|
136
|
+
else if (parts[2] === 'config.json')
|
|
137
|
+
notifyConfigWrite(ConfigTarget.Agent, { self: parts[1] });
|
|
138
|
+
else if (parts[2] === 'relations')
|
|
139
|
+
notifyConfigWrite(ConfigTarget.Relation, { self: parts[1], peerKey: parts[3] });
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
materializedBaseUrls,
|
|
143
|
+
imports: imports.map(item => ({ ...item, providerId: resolveProviderId(item.providerId, plan.registry) })),
|
|
144
|
+
aliases: plan.registry.aliases ?? {},
|
|
145
|
+
pending: plan.pending,
|
|
146
|
+
changedFiles: plan.changes.length,
|
|
147
|
+
referencesUpdated: plan.summary.referencesUpdated,
|
|
148
|
+
backup,
|
|
149
|
+
activeBaseagent: 'ecagent',
|
|
150
|
+
selection: selectedModel ? { provider: PREFERRED_PROVIDER, model: selectedModel } : null,
|
|
151
|
+
warnings,
|
|
152
|
+
};
|
|
153
|
+
}
|