evolcore 0.0.43-test.5 → 0.0.43-test.6
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 +47 -0
- package/bin/ecmsg.js +126 -43
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +6 -6
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +73 -10
- package/dist/cli/agent-create.js +16 -6
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +30 -1
- package/dist/cli/ecmsg-gateway.js +3 -1
- package/dist/cli/init.js +75 -0
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +24 -5
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +1 -1
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +80 -87
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +44 -7
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/command-handler.js +5 -5
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +82 -11
- package/dist/core/command/role-menu.js +27 -15
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +2 -2
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +10 -2
- package/dist/core/message/send-routing.js +12 -2
- package/dist/core/ownership/owner-resolver.js +1 -0
- package/dist/core/permission/ec-command-parser.js +11 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +57 -16
- package/dist/directory/owner-directory-query-operation.js +4 -1
- package/dist/ecweb/runtime/lifecycle.js +9 -7
- package/dist/ecweb/runtime/supervisor.js +44 -27
- package/dist/index.js +548 -251
- package/dist/proxy/manager.js +38 -17
- package/dist/proxy/service-supervisor.js +65 -31
- package/dist/trigger/application-service.js +3 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/utils/cross-platform.js +152 -4
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/startup-trace.js +160 -19
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/evolcore/INDEX.md +3 -2
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/msg.md +13 -6
- package/kits/docs/evolcore/provider.md +21 -3
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/eck_manifest.json +19 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/06-channel.md +5 -6
- package/kits/schemas/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/reply.md +2 -1
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +1 -1
- package/package.json +4 -3
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
4
4
|
import { agentRoleConfig, agentRolesDir, agentRolesIndex, kitsRoleTemplatesDir, resolvePaths, } from '../paths.js';
|
|
5
|
-
import { applyManagementRoleCeiling,
|
|
5
|
+
import { applyManagementRoleCeiling, DEFAULT_INTERNAL_CONTACT_ROLE, expectedRoleRank, getManagementRoleDefinition } from './builtin-roles.js';
|
|
6
6
|
import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
|
|
7
7
|
import { loadSchema } from './schema-registry.js';
|
|
8
8
|
import { normalizeRoleEffortCompat, normalizeRoleGroupChatmodeCompat, validateRoleConfig } from './role-schema.js';
|
|
@@ -88,7 +88,6 @@ export function roleIsAssignable(selfAid, roleId) {
|
|
|
88
88
|
function readRegistry(selfAid, diagnostics) {
|
|
89
89
|
const file = agentRolesIndex(selfAid);
|
|
90
90
|
let raw;
|
|
91
|
-
let invalidPaTeam = false;
|
|
92
91
|
try {
|
|
93
92
|
raw = atomicReadJson(file);
|
|
94
93
|
}
|
|
@@ -102,30 +101,29 @@ function readRegistry(selfAid, diagnostics) {
|
|
|
102
101
|
}
|
|
103
102
|
if (raw !== null) {
|
|
104
103
|
const schema = loadSchema('role-registry');
|
|
104
|
+
// 旧键名迁移:`paTeam` → `internalContact`。schema 已不再接受旧键
|
|
105
|
+
// (additionalProperties:false),所以必须在校验前改名,否则一份存量
|
|
106
|
+
// 注册表会被判成整份非法、连带丢掉 roles 列表。
|
|
105
107
|
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
106
108
|
const record = raw;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
if (Object.hasOwn(
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
invalidPaTeam = true;
|
|
118
|
-
}
|
|
109
|
+
const defaults = record.defaultRoles;
|
|
110
|
+
if (defaults && typeof defaults === 'object' && !Array.isArray(defaults)) {
|
|
111
|
+
const legacy = defaults;
|
|
112
|
+
if (Object.hasOwn(legacy, 'paTeam')) {
|
|
113
|
+
const migrated = { ...legacy };
|
|
114
|
+
const carried = migrated.paTeam;
|
|
115
|
+
delete migrated.paTeam;
|
|
116
|
+
if (!Object.hasOwn(migrated, 'internalContact'))
|
|
117
|
+
migrated.internalContact = carried;
|
|
118
|
+
raw = { ...record, defaultRoles: migrated };
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
if (schema.validate(raw)) {
|
|
123
123
|
const value = raw;
|
|
124
124
|
const roles = [...new Set(value.roles)];
|
|
125
|
-
const defaultRoles = { ...value.defaultRoles,
|
|
126
|
-
for (const scene of ['private', 'group', '
|
|
127
|
-
if (scene === 'paTeam' && invalidPaTeam)
|
|
128
|
-
continue;
|
|
125
|
+
const defaultRoles = { ...value.defaultRoles, internalContact: value.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE };
|
|
126
|
+
for (const scene of ['private', 'group', 'internalContact']) {
|
|
129
127
|
const selected = defaultRoles[scene];
|
|
130
128
|
if (selected === null || (roles.includes(selected) && selected !== 'owner'))
|
|
131
129
|
continue;
|
|
@@ -133,11 +131,13 @@ function readRegistry(selfAid, diagnostics) {
|
|
|
133
131
|
code: 'INVALID_ROLE_ASSIGNMENT',
|
|
134
132
|
roleId: selected,
|
|
135
133
|
file: path.relative(resolvePaths().root, file),
|
|
136
|
-
message: `defaultRoles.${scene} references invalid or unregistered role ${selected}; ${scene === '
|
|
137
|
-
? '
|
|
134
|
+
message: `defaultRoles.${scene} references invalid or unregistered role ${selected}; ${scene === 'internalContact'
|
|
135
|
+
? 'internal-contact default role is disabled' : `using ${scene === 'group' ? 'member' : 'visitor'} fallback`}`,
|
|
138
136
|
});
|
|
139
|
-
if (scene !== '
|
|
137
|
+
if (scene !== 'internalContact')
|
|
140
138
|
defaultRoles[scene] = null;
|
|
139
|
+
else
|
|
140
|
+
defaultRoles[scene] = '';
|
|
141
141
|
}
|
|
142
142
|
return { ...value, roles, defaultRoles };
|
|
143
143
|
}
|
|
@@ -156,7 +156,7 @@ function readRegistry(selfAid, diagnostics) {
|
|
|
156
156
|
return fallbackRegistry();
|
|
157
157
|
}
|
|
158
158
|
function fallbackRegistry() {
|
|
159
|
-
return { $schema_version: 1, roles: [...BUILTIN_ROLES], defaultRoles: { private: null, group: null,
|
|
159
|
+
return { $schema_version: 1, roles: [...BUILTIN_ROLES], defaultRoles: { private: null, group: null, internalContact: DEFAULT_INTERNAL_CONTACT_ROLE } };
|
|
160
160
|
}
|
|
161
161
|
function readDefinition(selfAid, roleId, diagnostics) {
|
|
162
162
|
const local = agentRoleConfig(selfAid, roleId);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { resolvePaths } from '../paths.js';
|
|
5
6
|
import { acquireConfigMutationLock, ConfigError } from './config-manager.js';
|
|
6
7
|
import { firstConfiguredOwner } from './owner-config.js';
|
|
7
|
-
import { resolveLegacyBaseagentModelSelection } from '../agents/baseagent.js';
|
|
8
8
|
import { loadSchema } from './schema-registry.js';
|
|
9
9
|
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
10
|
+
import { providerIdentity } from './provider-identity.js';
|
|
11
|
+
import { snapshot } from './snapshot.js';
|
|
10
12
|
const MIGRATION_KIND = {
|
|
11
13
|
'auxiliary-model-v1': 'auxiliary-model',
|
|
12
14
|
'agent-only-model-v1': 'agent-only-model',
|
|
@@ -599,25 +601,30 @@ function recoverJournal(home, id) {
|
|
|
599
601
|
function applyMigration(plan, id) {
|
|
600
602
|
if (plan.changes.length === 0)
|
|
601
603
|
return null;
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
604
|
+
let backup;
|
|
605
|
+
if (id === 'provider-domain-id-v1') {
|
|
606
|
+
const result = snapshot('schema-migration', { root: plan.home, description: 'before Provider identity migration',
|
|
607
|
+
expectedFiles: new Map(plan.changes.map(item => [path.relative(plan.home, item.file).split(path.sep).join('/'), item.before])) });
|
|
608
|
+
backup = result.version ?? null;
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
612
|
+
backup = path.join(plan.home, 'backups', `${id}-migration`, stamp);
|
|
613
|
+
fs.mkdirSync(path.join(backup, 'files'), { recursive: true });
|
|
614
|
+
for (const item of plan.changes) {
|
|
615
|
+
if (item.before === null)
|
|
616
|
+
continue;
|
|
617
|
+
const destination = path.join(backup, 'files', path.relative(plan.home, item.file));
|
|
618
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
619
|
+
fs.writeFileSync(destination, item.before);
|
|
620
|
+
}
|
|
621
|
+
fs.writeFileSync(path.join(backup, 'manifest.json'), jsonText({
|
|
622
|
+
schemaVersion: 1,
|
|
623
|
+
createdAt: new Date().toISOString(),
|
|
624
|
+
summary: plan.summary,
|
|
625
|
+
files: plan.changes.map(item => ({ path: path.relative(plan.home, item.file), kind: item.kind })),
|
|
626
|
+
}));
|
|
611
627
|
}
|
|
612
|
-
fs.writeFileSync(path.join(backup, 'manifest.json'), jsonText({
|
|
613
|
-
schemaVersion: 1,
|
|
614
|
-
createdAt: new Date().toISOString(),
|
|
615
|
-
summary: plan.summary,
|
|
616
|
-
files: plan.changes.map(item => ({
|
|
617
|
-
path: path.relative(plan.home, item.file),
|
|
618
|
-
kind: item.kind,
|
|
619
|
-
})),
|
|
620
|
-
}));
|
|
621
628
|
writeJournal(plan, 'prepared', id);
|
|
622
629
|
try {
|
|
623
630
|
for (const item of plan.changes)
|
|
@@ -673,7 +680,7 @@ export async function ensureAuxiliaryModelMigrationOnStartup() {
|
|
|
673
680
|
throw new ConfigError('AUXILIARY_MODEL_MIGRATION_FAILED', `Automatic Session Renew auxiliary-model schema migration failed: ${detail}`, { cause: error });
|
|
674
681
|
}
|
|
675
682
|
}
|
|
676
|
-
// ── Preserve
|
|
683
|
+
// ── Preserve explicit Owner selections once, before removing legacy relation settings. ──
|
|
677
684
|
export function runLegacyModelSelectionMigration(options = {}) {
|
|
678
685
|
const home = path.resolve(options.home || resolvePaths().root);
|
|
679
686
|
const id = 'legacy-model-selection-v1';
|
|
@@ -696,7 +703,6 @@ export function runLegacyModelSelectionMigration(options = {}) {
|
|
|
696
703
|
const defaults = fs.existsSync(defaultsFile) ? readJson(defaultsFile).value : {};
|
|
697
704
|
if (!isRecord(defaults))
|
|
698
705
|
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
699
|
-
const inheritedBlocks = baseagentSource(defaults) ?? {};
|
|
700
706
|
const entries = fs.existsSync(agentsRoot) ? fs.readdirSync(agentsRoot, { withFileTypes: true }) : [];
|
|
701
707
|
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
702
708
|
if (!entry.isDirectory() || !validAid(entry.name))
|
|
@@ -733,7 +739,6 @@ export function runLegacyModelSelectionMigration(options = {}) {
|
|
|
733
739
|
let nextBlocks = { ...blocks };
|
|
734
740
|
for (const backend of backends) {
|
|
735
741
|
const block = isRecord(blocks[backend]) ? blocks[backend] : {};
|
|
736
|
-
const inherited = isRecord(inheritedBlocks[backend]) ? inheritedBlocks[backend] : {};
|
|
737
742
|
const ownerSelection = ownerSelections.get(backend);
|
|
738
743
|
const nextBlock = { ...block };
|
|
739
744
|
const migrated = { aid: entry.name, baseagent: backend };
|
|
@@ -749,24 +754,6 @@ export function runLegacyModelSelectionMigration(options = {}) {
|
|
|
749
754
|
migrated.effort = ownerSelection.effort;
|
|
750
755
|
migrated.effortSource = 'owner-relation';
|
|
751
756
|
}
|
|
752
|
-
// Preserve the runner's historical selection when no Agent/defaults
|
|
753
|
-
// model exists and the Owner relation did not provide one. This is a
|
|
754
|
-
// one-time compatibility fallback; other relation values are ignored.
|
|
755
|
-
const hasAgentModel = typeof block.model === 'string' && block.model.trim().length > 0;
|
|
756
|
-
const hasDefaultModel = typeof inherited.model === 'string' && inherited.model.trim().length > 0;
|
|
757
|
-
if (backend === baseagent && !hasAgentModel && !hasDefaultModel && ownerSelection?.model === undefined) {
|
|
758
|
-
const legacy = resolveLegacyBaseagentModelSelection(backend);
|
|
759
|
-
if (legacy) {
|
|
760
|
-
nextBlock.model = legacy.model;
|
|
761
|
-
migrated.model = legacy.model;
|
|
762
|
-
migrated.modelSource = legacy.source;
|
|
763
|
-
if (!block.effort && ownerSelection?.effort === undefined && legacy.effort) {
|
|
764
|
-
nextBlock.effort = legacy.effort;
|
|
765
|
-
migrated.effort = legacy.effort;
|
|
766
|
-
migrated.effortSource = legacy.source;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
757
|
if (Object.keys(migrated).length > 2) {
|
|
771
758
|
nextBlocks = { ...nextBlocks, [backend]: nextBlock };
|
|
772
759
|
selections.push(migrated);
|
|
@@ -904,7 +891,6 @@ function planAgentOnlyModelMigration(home) {
|
|
|
904
891
|
: fs.existsSync(defaultsFile) ? readJson(defaultsFile).value : {};
|
|
905
892
|
if (!isRecord(defaultsRaw))
|
|
906
893
|
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
907
|
-
const inheritedBlocks = baseagentSource(defaultsRaw) ?? {};
|
|
908
894
|
const agentEntries = fs.readdirSync(agentsRoot, { withFileTypes: true })
|
|
909
895
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
910
896
|
for (const entry of agentEntries) {
|
|
@@ -934,7 +920,6 @@ function planAgentOnlyModelMigration(home) {
|
|
|
934
920
|
const migrated = [];
|
|
935
921
|
for (const backend of backends) {
|
|
936
922
|
const block = isRecord(sourceBlocks[backend]) ? sourceBlocks[backend] : {};
|
|
937
|
-
const inherited = isRecord(inheritedBlocks[backend]) ? inheritedBlocks[backend] : {};
|
|
938
923
|
const owner = ownerSelections.get(backend);
|
|
939
924
|
const next = { ...block };
|
|
940
925
|
if (owner?.model !== undefined && owner.model !== block.model) {
|
|
@@ -947,20 +932,6 @@ function planAgentOnlyModelMigration(home) {
|
|
|
947
932
|
migrated.push(`baseagents.${backend}.effort from owner relation`);
|
|
948
933
|
summary.ownerEffortsPromoted += 1;
|
|
949
934
|
}
|
|
950
|
-
const hasAgentModel = typeof block.model === 'string' && block.model.trim().length > 0;
|
|
951
|
-
const hasDefaultModel = typeof inherited.model === 'string' && inherited.model.trim().length > 0;
|
|
952
|
-
if (backend === selected && !hasAgentModel && !hasDefaultModel && owner?.model === undefined) {
|
|
953
|
-
const legacy = resolveLegacyBaseagentModelSelection(backend);
|
|
954
|
-
if (legacy) {
|
|
955
|
-
next.model = legacy.model;
|
|
956
|
-
migrated.push(`baseagents.${backend}.model from ${legacy.source}`);
|
|
957
|
-
summary.legacyModelsRestored += 1;
|
|
958
|
-
if (!block.effort && owner?.effort === undefined && legacy.effort) {
|
|
959
|
-
next.effort = legacy.effort;
|
|
960
|
-
migrated.push(`baseagents.${backend}.effort from ${legacy.source}`);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
935
|
if (Object.keys(next).length > 0)
|
|
965
936
|
nextBlocks[backend] = next;
|
|
966
937
|
}
|
|
@@ -1056,37 +1027,32 @@ const BASEAGENT_SERVICE_TYPES = {
|
|
|
1056
1027
|
gemini: 'gemini',
|
|
1057
1028
|
ecagent: 'text',
|
|
1058
1029
|
};
|
|
1059
|
-
/**
|
|
1060
|
-
* providers.json 中已存在同 baseUrl 且同凭证的服务时复用该条目,避免重复登记。
|
|
1061
|
-
* 端点相同但凭证不同必须单独建条目:否则显式 apiKey 会在迁移中丢失。
|
|
1062
|
-
*/
|
|
1063
1030
|
function findProviderForConnection(providers, connection) {
|
|
1064
1031
|
for (const [providerId, provider] of Object.entries(providers)) {
|
|
1065
1032
|
if (!isRecord(provider) || !isRecord(provider.common))
|
|
1066
1033
|
continue;
|
|
1067
1034
|
const baseUrl = typeof provider.common.baseUrl === 'string' ? provider.common.baseUrl.trim() : '';
|
|
1068
|
-
|
|
1035
|
+
try {
|
|
1036
|
+
if (providerIdentity(provider).domain
|
|
1037
|
+
!== providerIdentity({ common: { baseUrl: connection.baseUrl } }).domain)
|
|
1038
|
+
continue;
|
|
1039
|
+
if (new URL(baseUrl).origin !== new URL(connection.baseUrl).origin)
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
catch {
|
|
1069
1043
|
continue;
|
|
1044
|
+
}
|
|
1070
1045
|
const existingKey = typeof provider.common.apiKey === 'string' ? provider.common.apiKey.trim() : '';
|
|
1071
1046
|
if (connection.apiKey && existingKey !== connection.apiKey)
|
|
1072
1047
|
continue;
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1048
|
+
if (connection.headers && !isDeepStrictEqual(provider.common.headers, connection.headers))
|
|
1049
|
+
continue;
|
|
1050
|
+
if (connection.queryParams && !isDeepStrictEqual(provider.common.queryParams, connection.queryParams))
|
|
1051
|
+
continue;
|
|
1052
|
+
return providerId;
|
|
1076
1053
|
}
|
|
1077
1054
|
return undefined;
|
|
1078
1055
|
}
|
|
1079
|
-
function createProviderId(providers) {
|
|
1080
|
-
let sequence = 1;
|
|
1081
|
-
for (const providerId of Object.keys(providers)) {
|
|
1082
|
-
const match = /^provider-(\d+)$/u.exec(providerId);
|
|
1083
|
-
if (match)
|
|
1084
|
-
sequence = Math.max(sequence, Number(match[1]) + 1);
|
|
1085
|
-
}
|
|
1086
|
-
while (hasOwn(providers, `provider-${sequence}`))
|
|
1087
|
-
sequence += 1;
|
|
1088
|
-
return `provider-${sequence}`;
|
|
1089
|
-
}
|
|
1090
1056
|
/** 旧写法 $ENV:NAME 统一成 providers 认识的整体引用 ${NAME};明文原样保留。 */
|
|
1091
1057
|
function normalizeProviderSecret(value) {
|
|
1092
1058
|
if (typeof value !== 'string')
|
|
@@ -1148,15 +1114,42 @@ function connectionFromDecisionModel(block) {
|
|
|
1148
1114
|
path: servicePath,
|
|
1149
1115
|
};
|
|
1150
1116
|
}
|
|
1151
|
-
function registerConnection(providers, connection, servicePath, summary) {
|
|
1117
|
+
function registerConnection(providers, connection, servicePath, summary, aliases) {
|
|
1152
1118
|
const existing = findProviderForConnection(providers, connection);
|
|
1153
|
-
const
|
|
1119
|
+
const identity = providerIdentity({ common: { baseUrl: connection.baseUrl } });
|
|
1120
|
+
const providerId = existing ?? identity.providerId;
|
|
1121
|
+
if (!existing) {
|
|
1122
|
+
if (hasOwn(aliases, providerId))
|
|
1123
|
+
throw Object.assign(new Error('Provider ID is reserved by a legacy alias'), { code: 'PROVIDER_ID_COLLISION' });
|
|
1124
|
+
for (const [candidateId, candidate] of Object.entries(providers)) {
|
|
1125
|
+
let domain;
|
|
1126
|
+
try {
|
|
1127
|
+
domain = providerIdentity(candidate).domain;
|
|
1128
|
+
}
|
|
1129
|
+
catch { }
|
|
1130
|
+
if (candidateId === providerId || domain === identity.domain) {
|
|
1131
|
+
throw Object.assign(new Error('Legacy Provider connection conflicts with an existing domain; reconcile before migration'), {
|
|
1132
|
+
code: candidateId === providerId && domain !== identity.domain ? 'PROVIDER_ID_COLLISION' : 'PROVIDER_CONFLICT',
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1154
1137
|
const current = existing && isRecord(providers[existing]) ? providers[existing] : undefined;
|
|
1155
1138
|
const common = current && isRecord(current.common) ? { ...current.common } : {};
|
|
1156
1139
|
const services = current && isRecord(current.services) ? { ...current.services } : {};
|
|
1140
|
+
const baseUrl = typeof common.baseUrl === 'string' ? common.baseUrl : connection.baseUrl;
|
|
1141
|
+
const endpoint = new URL(servicePath || '.', connection.baseUrl.endsWith('/') ? connection.baseUrl : `${connection.baseUrl}/`);
|
|
1142
|
+
const existingService = services[connection.serviceType];
|
|
1143
|
+
if (isRecord(existingService)) {
|
|
1144
|
+
const existingEndpoint = new URL(typeof existingService.path === 'string' && existingService.path ? existingService.path : '.', baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`);
|
|
1145
|
+
if (existingEndpoint.href.replace(/\/+$/u, '') !== endpoint.href.replace(/\/+$/u, '')) {
|
|
1146
|
+
throw Object.assign(new Error('Legacy Provider service endpoint conflicts; reconcile before migration'), { code: 'PROVIDER_CONFLICT' });
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
const targetPath = baseUrl === connection.baseUrl ? servicePath : `${endpoint.pathname}${endpoint.search}${endpoint.hash}`;
|
|
1157
1150
|
const nextCommon = {
|
|
1158
1151
|
...common,
|
|
1159
|
-
baseUrl
|
|
1152
|
+
baseUrl,
|
|
1160
1153
|
...(connection.apiKey && !common.apiKey ? { apiKey: connection.apiKey } : {}),
|
|
1161
1154
|
...(connection.headers ? { headers: connection.headers } : {}),
|
|
1162
1155
|
...(connection.queryParams ? { queryParams: connection.queryParams } : {}),
|
|
@@ -1165,11 +1158,11 @@ function registerConnection(providers, connection, servicePath, summary) {
|
|
|
1165
1158
|
...services,
|
|
1166
1159
|
[connection.serviceType]: {
|
|
1167
1160
|
...(isRecord(services[connection.serviceType]) ? services[connection.serviceType] : {}),
|
|
1168
|
-
...(
|
|
1161
|
+
...(targetPath ? { path: targetPath } : {}),
|
|
1169
1162
|
...(connection.serviceType === 'decision' ? { style: 'systemone' } : {}),
|
|
1170
1163
|
},
|
|
1171
1164
|
};
|
|
1172
|
-
const nextProvider = { ...(current ?? {}), common: nextCommon, services: nextServices };
|
|
1165
|
+
const nextProvider = { ...(current ?? {}), domain: identity.domain, common: nextCommon, services: nextServices };
|
|
1173
1166
|
if (!hasOwn(nextProvider, 'name'))
|
|
1174
1167
|
nextProvider.name = providerId;
|
|
1175
1168
|
providers[providerId] = nextProvider;
|
|
@@ -1240,7 +1233,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1240
1233
|
const serviceType = BASEAGENT_SERVICE_TYPES[name];
|
|
1241
1234
|
const connection = serviceType ? connectionFromBlock(block, serviceType) : undefined;
|
|
1242
1235
|
if (connection)
|
|
1243
|
-
defaultConnections.set(name, registerConnection(providers, connection, '', summary));
|
|
1236
|
+
defaultConnections.set(name, registerConnection(providers, connection, '', summary, isRecord(providerRegistry.aliases) ? providerRegistry.aliases : {}));
|
|
1244
1237
|
}
|
|
1245
1238
|
}
|
|
1246
1239
|
for (const [file, entry] of parsed) {
|
|
@@ -1276,7 +1269,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1276
1269
|
.map(field => `baseagents.${name}.${field}`));
|
|
1277
1270
|
if (serviceType && block.provider === undefined) {
|
|
1278
1271
|
const providerId = own
|
|
1279
|
-
? registerConnection(providers, own, '', summary)
|
|
1272
|
+
? registerConnection(providers, own, '', summary, isRecord(providerRegistry.aliases) ? providerRegistry.aliases : {})
|
|
1280
1273
|
: defaultConnections.get(name);
|
|
1281
1274
|
if (providerId)
|
|
1282
1275
|
block.provider = providerId;
|
|
@@ -1291,7 +1284,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1291
1284
|
const decisionMigrated = ownDecision ? connectionFromDecisionModel(ownDecision) : undefined;
|
|
1292
1285
|
let decisionSelection;
|
|
1293
1286
|
if (decisionMigrated) {
|
|
1294
|
-
const providerId = registerConnection(providers, decisionMigrated.connection, decisionMigrated.path, summary);
|
|
1287
|
+
const providerId = registerConnection(providers, decisionMigrated.connection, decisionMigrated.path, summary, isRecord(providerRegistry.aliases) ? providerRegistry.aliases : {});
|
|
1295
1288
|
const model = typeof ownDecision.model === 'string' ? ownDecision.model.trim() : '';
|
|
1296
1289
|
decisionSelection = { provider: providerId, ...(model ? { model } : {}) };
|
|
1297
1290
|
summary.decisionModelsMigrated += 1;
|
|
@@ -1427,8 +1420,8 @@ export function runProviderIdentitySchemaMigration(options = {}) {
|
|
|
1427
1420
|
try {
|
|
1428
1421
|
assertDaemonStopped(home);
|
|
1429
1422
|
recoverJournal(home, id);
|
|
1430
|
-
const plan = planProviderIdentityMigration(home);
|
|
1431
|
-
const backup = options.apply ?
|
|
1423
|
+
const plan = planProviderIdentityMigration(home, undefined, { cleanupAliases: true });
|
|
1424
|
+
const backup = options.apply ? commitProviderSyncMigration(plan, true) : null;
|
|
1432
1425
|
return { ok: true, mode: options.apply ? 'applied' : 'dry-run',
|
|
1433
1426
|
home, changedFiles: plan.changes.length, backup, summary: plan.summary, pending: plan.pending };
|
|
1434
1427
|
}
|
|
@@ -1445,9 +1438,9 @@ export async function ensureProviderIdentityMigrationOnStartup() {
|
|
|
1445
1438
|
throw new ConfigError('PROVIDER_IDENTITY_MIGRATION_FAILED', 'Automatic Provider identity migration failed; resolve conflicting domains or connection settings before restarting', { cause: error });
|
|
1446
1439
|
}
|
|
1447
1440
|
}
|
|
1448
|
-
export function commitProviderSyncMigration(plan) {
|
|
1441
|
+
export function commitProviderSyncMigration(plan, migrationLocked = false) {
|
|
1449
1442
|
const id = 'provider-domain-id-v1';
|
|
1450
|
-
const releaseMigration = acquireLock(plan.home, id);
|
|
1443
|
+
const releaseMigration = migrationLocked ? () => { } : acquireLock(plan.home, id);
|
|
1451
1444
|
const releases = [];
|
|
1452
1445
|
try {
|
|
1453
1446
|
if (fs.existsSync(journalPath(plan.home, id))) {
|