evolcore 0.0.43-test.5 → 0.0.43-test.7
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 +95 -0
- package/bin/ecmsg.js +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- 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 +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +58 -16
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- 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/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- 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-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- 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/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- 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/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -3,11 +3,12 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path, { posix } from 'node:path';
|
|
5
5
|
import { resolvePaths } from '../paths.js';
|
|
6
|
-
import { ConfigTarget, mutateConfig } from './config-manager.js';
|
|
6
|
+
import { ConfigTarget, mutateConfig, notifyConfigWrite } from './config-manager.js';
|
|
7
7
|
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
8
8
|
import { readProvidersFile, validateProvidersFile } from './providers.js';
|
|
9
|
-
import { providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderId, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
9
|
+
import { initializationRuntimePlan, providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderId, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
10
10
|
import { providerIdentity } from './provider-identity.js';
|
|
11
|
+
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
11
12
|
export const PROVIDER_SECRET_MASK = '<redacted>';
|
|
12
13
|
function providerReferences(providerId, providerFile) {
|
|
13
14
|
const registry = readProvidersFile(providerFile);
|
|
@@ -35,6 +36,15 @@ function providerReferences(providerId, providerFile) {
|
|
|
35
36
|
candidates.push(path.join(agentsDir, agent.name, 'relations', relation.name, 'config.json'));
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
const ecwebDir = path.join(root, 'data', 'ecweb');
|
|
40
|
+
candidates.push(path.join(ecwebDir, 'init-state.json'));
|
|
41
|
+
const creations = path.join(ecwebDir, 'agent-creations');
|
|
42
|
+
if (fs.existsSync(creations)) {
|
|
43
|
+
for (const entry of fs.readdirSync(creations, { withFileTypes: true })) {
|
|
44
|
+
if (entry.name.endsWith('.json') && (entry.isFile() || entry.isSymbolicLink()))
|
|
45
|
+
candidates.push(path.join(creations, entry.name));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
38
48
|
const references = [];
|
|
39
49
|
const visit = (value, fieldPath, file) => {
|
|
40
50
|
if (Array.isArray(value)) {
|
|
@@ -57,6 +67,19 @@ function providerReferences(providerId, providerFile) {
|
|
|
57
67
|
continue;
|
|
58
68
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
59
69
|
throw new Error();
|
|
70
|
+
if (path.basename(file) === 'initialization.json' && value.plan)
|
|
71
|
+
value.plan = initializationRuntimePlan(value);
|
|
72
|
+
if (value.creation?.plan) {
|
|
73
|
+
value.creation = { ...value.creation, plan: initializationRuntimePlan(value.creation) };
|
|
74
|
+
}
|
|
75
|
+
if (value.providerIds && typeof value.providerIds === 'object' && !Array.isArray(value.providerIds)) {
|
|
76
|
+
for (const [key, id] of Object.entries(value.providerIds)) {
|
|
77
|
+
if (typeof id === 'string' && referencedIds.has(id))
|
|
78
|
+
references.push({
|
|
79
|
+
file: path.relative(root, file), path: `providerIds.${key}`,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
60
83
|
for (const field of ['baseagents', 'agents', 'Services', 'decision_model', 'plan', 'creation']) {
|
|
61
84
|
visit(value[field], field, path.relative(root, file).replace(/\\/g, '/'));
|
|
62
85
|
}
|
|
@@ -349,6 +372,73 @@ export async function createProvider(input, file = resolvePaths().providersConfi
|
|
|
349
372
|
});
|
|
350
373
|
return { ...providersSnapshot(result.value.current), providerId: result.value.providerId };
|
|
351
374
|
}
|
|
375
|
+
function upgradeProviderId(current, oldId) {
|
|
376
|
+
const provider = current.providers[oldId];
|
|
377
|
+
const identity = providerIdentity(provider);
|
|
378
|
+
provider.domain = identity.domain;
|
|
379
|
+
if (oldId === identity.providerId)
|
|
380
|
+
return oldId;
|
|
381
|
+
const remaining = { ...current.providers };
|
|
382
|
+
delete remaining[oldId];
|
|
383
|
+
const aliases = { ...current.aliases };
|
|
384
|
+
if (aliases[identity.providerId] === oldId)
|
|
385
|
+
delete aliases[identity.providerId];
|
|
386
|
+
const providerId = availableProviderId({ providers: remaining, aliases }, provider);
|
|
387
|
+
for (const [alias, target] of Object.entries(aliases)) {
|
|
388
|
+
if (target === oldId)
|
|
389
|
+
aliases[alias] = providerId;
|
|
390
|
+
}
|
|
391
|
+
aliases[oldId] = providerId;
|
|
392
|
+
delete current.providers[oldId];
|
|
393
|
+
current.providers[providerId] = provider;
|
|
394
|
+
current.aliases = aliases;
|
|
395
|
+
delete current.nextId;
|
|
396
|
+
return providerId;
|
|
397
|
+
}
|
|
398
|
+
async function mutateProvidersWithIdentityUpgrade(revision, file, mutation) {
|
|
399
|
+
if (!/^[a-f0-9]{64}$/u.test(revision))
|
|
400
|
+
throw new Error('A valid providers revision is required');
|
|
401
|
+
const assertRevision = (current) => {
|
|
402
|
+
if (providersRevision(current) !== revision) {
|
|
403
|
+
throw Object.assign(new Error('Providers changed after loading; reload before saving'), {
|
|
404
|
+
code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' },
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
const previous = readProvidersFile(file);
|
|
409
|
+
assertRevision(previous);
|
|
410
|
+
const draft = structuredClone(previous);
|
|
411
|
+
const result = mutation(draft);
|
|
412
|
+
const upgraded = Object.keys(previous.providers).some(id => !Object.hasOwn(draft.providers, id) && draft.aliases?.[id]);
|
|
413
|
+
if (!upgraded) {
|
|
414
|
+
return mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
415
|
+
const current = config;
|
|
416
|
+
assertRevision(current);
|
|
417
|
+
return mutation(current);
|
|
418
|
+
}).value;
|
|
419
|
+
}
|
|
420
|
+
if (path.basename(file) !== 'providers.json')
|
|
421
|
+
throw new Error('Provider ID upgrade requires the canonical providers.json registry');
|
|
422
|
+
const plan = planProviderIdentityMigration(path.dirname(path.resolve(file)), draft, { preserveProviderIds: true });
|
|
423
|
+
const original = plan.expected.find(item => item.file === path.resolve(file));
|
|
424
|
+
if (!original?.before)
|
|
425
|
+
throw Object.assign(new Error('Provider registry changed during import'), { code: 'CONFLICT', statusCode: 409 });
|
|
426
|
+
assertRevision(validateProvidersFile(JSON.parse(original.before.replace(/^\uFEFF/u, ''))));
|
|
427
|
+
const { commitProviderSyncMigration } = await import('./schema-migration.js');
|
|
428
|
+
commitProviderSyncMigration(plan);
|
|
429
|
+
for (const change of plan.changes) {
|
|
430
|
+
const parts = path.relative(plan.home, change.file).split(path.sep);
|
|
431
|
+
if (parts[0] === 'providers.json')
|
|
432
|
+
notifyConfigWrite(ConfigTarget.Providers, { providerFile: file });
|
|
433
|
+
else if (parts[1] === 'defaults.json')
|
|
434
|
+
notifyConfigWrite(ConfigTarget.Defaults);
|
|
435
|
+
else if (parts[2] === 'config.json')
|
|
436
|
+
notifyConfigWrite(ConfigTarget.Agent, { self: parts[1] });
|
|
437
|
+
else if (parts[2] === 'relations')
|
|
438
|
+
notifyConfigWrite(ConfigTarget.Relation, { self: parts[1], peerKey: parts[3] });
|
|
439
|
+
}
|
|
440
|
+
return { ...result, current: plan.registry };
|
|
441
|
+
}
|
|
352
442
|
function providerHostname(baseUrl) {
|
|
353
443
|
if (providerEnvironmentVariable(baseUrl))
|
|
354
444
|
return undefined;
|
|
@@ -430,8 +520,7 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
430
520
|
}
|
|
431
521
|
identifiers.add(change.providerId);
|
|
432
522
|
}
|
|
433
|
-
const result =
|
|
434
|
-
const current = config;
|
|
523
|
+
const result = await mutateProvidersWithIdentityUpgrade(input.revision, file, current => {
|
|
435
524
|
if (providersRevision(current) !== input.revision) {
|
|
436
525
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
437
526
|
}
|
|
@@ -459,15 +548,17 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
459
548
|
provider.name ||= providerNameFromBaseUrlIfStatic(provider.common.baseUrl);
|
|
460
549
|
if (provider.name !== undefined)
|
|
461
550
|
provider.name = validateProviderName(provider.name);
|
|
462
|
-
|
|
551
|
+
let providerId = change.create ? availableProviderId(current, provider) : targetId;
|
|
463
552
|
if (change.create)
|
|
464
553
|
delete current.nextId;
|
|
465
554
|
current.providers[providerId] = provider;
|
|
555
|
+
if (!change.create && change.imports?.length)
|
|
556
|
+
providerId = upgradeProviderId(current, providerId);
|
|
466
557
|
providerIds[change.providerId] = providerId;
|
|
467
558
|
}
|
|
468
559
|
return { current, providerIds };
|
|
469
560
|
});
|
|
470
|
-
return { ...providersSnapshot(result.
|
|
561
|
+
return { ...providersSnapshot(result.current), providerIds: result.providerIds };
|
|
471
562
|
}
|
|
472
563
|
export function importBaseagentProviderIntoRegistry(current, input) {
|
|
473
564
|
const normalized = validateProvidersFile({ providers: { imported: input.value } });
|
|
@@ -492,7 +583,7 @@ export function importBaseagentProviderIntoRegistry(current, input) {
|
|
|
492
583
|
const [providerId, existing] = match;
|
|
493
584
|
const replaceServiceTypes = new Set(Object.entries(input.serviceDecisions || {}).filter(([, decision]) => decision === 'imported').map(([type]) => type));
|
|
494
585
|
current.providers[providerId] = validateProvidersFile({ providers: { [providerId]: mergeImportedProvider(existing, imported, replaceServiceTypes) } }).providers[providerId];
|
|
495
|
-
return { current, providerId, merged: true };
|
|
586
|
+
return { current, providerId: upgradeProviderId(current, providerId), merged: true };
|
|
496
587
|
}
|
|
497
588
|
const providerId = availableProviderId(current, imported);
|
|
498
589
|
current.providers[providerId] = imported;
|
|
@@ -502,12 +593,11 @@ export function importBaseagentProviderIntoRegistry(current, input) {
|
|
|
502
593
|
export async function importOrMergeBaseagentProvider(input, file = resolvePaths().providersConfig) {
|
|
503
594
|
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
504
595
|
throw new Error('A valid providers revision is required');
|
|
505
|
-
const result =
|
|
506
|
-
const current = config;
|
|
596
|
+
const result = await mutateProvidersWithIdentityUpgrade(input.revision, file, current => {
|
|
507
597
|
if (providersRevision(current) !== input.revision) {
|
|
508
598
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
509
599
|
}
|
|
510
600
|
return importBaseagentProviderIntoRegistry(current, input);
|
|
511
601
|
});
|
|
512
|
-
return { ...providersSnapshot(result.
|
|
602
|
+
return { ...providersSnapshot(result.current), providerId: result.providerId, merged: result.merged };
|
|
513
603
|
}
|
|
@@ -5,7 +5,7 @@ import { agentRelationConfig, agentRelationsDir, agentRoleConfig, agentRolesInde
|
|
|
5
5
|
import { registerFile, unregisterFile } from '../core/file-integrity/store.js';
|
|
6
6
|
import { currentVersion, loadSchema } from './schema-registry.js';
|
|
7
7
|
import { clearRoleStoreCache, getStoredRoleRegistry, isRoleName, readRoleStore, roleRegistryExists, } from './role-store.js';
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_INTERNAL_CONTACT_ROLE, expectedRoleRank, isManagementRole } from './builtin-roles.js';
|
|
9
9
|
import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
|
|
10
10
|
import { normalizeRoleEffortCompat, validateRoleConfig } from './role-schema.js';
|
|
11
11
|
export class RoleServiceError extends Error {
|
|
@@ -30,7 +30,7 @@ export function ensureInitialRoleRegistry(selfAid) {
|
|
|
30
30
|
writeRoleRegistry(selfAid, {
|
|
31
31
|
$schema_version: 1,
|
|
32
32
|
roles: ['owner', 'admin', 'member', 'visitor'],
|
|
33
|
-
defaultRoles: { private: null, group: null,
|
|
33
|
+
defaultRoles: { private: null, group: null, internalContact: DEFAULT_INTERNAL_CONTACT_ROLE },
|
|
34
34
|
});
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
@@ -125,8 +125,8 @@ export function unregisterRole(selfAid, roleId, replacementRoleId) {
|
|
|
125
125
|
defaultRoles: {
|
|
126
126
|
private: registry.defaultRoles.private === roleId ? (replacement ?? null) : registry.defaultRoles.private,
|
|
127
127
|
group: registry.defaultRoles.group === roleId ? (replacement ?? null) : registry.defaultRoles.group,
|
|
128
|
-
|
|
129
|
-
? (replacement ??
|
|
128
|
+
internalContact: (registry.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE) === roleId
|
|
129
|
+
? (replacement ?? DEFAULT_INTERNAL_CONTACT_ROLE) : registry.defaultRoles.internalContact,
|
|
130
130
|
},
|
|
131
131
|
};
|
|
132
132
|
validateRegistry(selfAid, nextRegistry);
|
|
@@ -174,8 +174,8 @@ function validateRegistry(selfAid, value) {
|
|
|
174
174
|
const registry = normalized;
|
|
175
175
|
if (!registry.roles.includes('visitor'))
|
|
176
176
|
throw new RoleServiceError('VISITOR_REQUIRED', 'visitor must remain registered');
|
|
177
|
-
for (const role of ['private', 'group', '
|
|
178
|
-
const selected = role === '
|
|
177
|
+
for (const role of ['private', 'group', 'internalContact']) {
|
|
178
|
+
const selected = role === 'internalContact' ? registry.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE : registry.defaultRoles[role];
|
|
179
179
|
if (selected !== null && (selected === 'owner' || !registry.roles.includes(selected))) {
|
|
180
180
|
throw new RoleServiceError('INVALID_DEFAULT_ROLE', `defaultRoles.${role} must reference an assignable registered role`);
|
|
181
181
|
}
|
|
@@ -206,8 +206,8 @@ function findRoleReferences(selfAid, roleId, registry) {
|
|
|
206
206
|
references.push('defaultRoles.private');
|
|
207
207
|
if (registry.defaultRoles.group === roleId)
|
|
208
208
|
references.push('defaultRoles.group');
|
|
209
|
-
if ((registry.defaultRoles.
|
|
210
|
-
references.push('defaultRoles.
|
|
209
|
+
if ((registry.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE) === roleId)
|
|
210
|
+
references.push('defaultRoles.internalContact');
|
|
211
211
|
const relations = agentRelationsDir(selfAid);
|
|
212
212
|
if (!fs.existsSync(relations))
|
|
213
213
|
return references;
|
|
@@ -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 {
|
|
8
|
-
import { loadSchema } from './schema-registry.js';
|
|
8
|
+
import { currentVersion, 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))) {
|
|
@@ -1622,6 +1615,11 @@ const PUBLISHED_SCHEMA_CONSOLIDATIONS = [
|
|
|
1622
1615
|
function restampPublishedSchemaConsolidation(value, file, consolidation) {
|
|
1623
1616
|
if (value.$schema_version !== consolidation.from)
|
|
1624
1617
|
return null;
|
|
1618
|
+
// A consolidation only applies while the source version is unpublished.
|
|
1619
|
+
// Once that version is current, its fields (for example agent-config.team)
|
|
1620
|
+
// must be retained instead of being validated against the older schema.
|
|
1621
|
+
if (currentVersion(consolidation.logicalName) >= consolidation.from)
|
|
1622
|
+
return null;
|
|
1625
1623
|
const next = { ...value, $schema_version: consolidation.to };
|
|
1626
1624
|
const schema = loadSchema(consolidation.logicalName, consolidation.to);
|
|
1627
1625
|
if (!schema.validate(next)) {
|