evolcore 0.0.43-test.3 → 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 +82 -0
- package/bin/ecmsg.js +492 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +12 -54
- package/dist/agents/ecagent-runner.js +130 -35
- package/dist/aun/aid/agentmd.js +56 -12
- 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/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +56 -22
- package/dist/channels/daemon.js +12 -4
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +32 -8
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +12 -5
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -21
- package/dist/cli/directory.js +7 -8
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +58 -18
- 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/cli/trigger-command.js +20 -14
- package/dist/config/boot-log.js +23 -2
- package/dist/config/config-field-policy.js +2 -0
- package/dist/config/config-manager.js +13 -17
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- 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/role-schema.js +3 -3
- package/dist/config/schema-migration.js +188 -3
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +45 -11
- package/dist/core/auth/auth-gateway.js +8 -6
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +5 -2
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/command/agent-control.js +4 -1
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -20
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +1 -1
- package/dist/core/command/menu-handler.js +16 -16
- 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 +56 -42
- package/dist/core/daemon-lifecycle.js +35 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/im-renderer.js +24 -19
- package/dist/core/message/message-admission.js +13 -2
- package/dist/core/message/response-engine.js +40 -41
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +117 -14
- package/dist/core/permission/ec-command-parser.js +195 -27
- 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/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +7 -2
- 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 +690 -99
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +7 -9
- 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 +38 -5
- package/dist/ecweb/runtime/supervisor.js +157 -49
- package/dist/index.js +202 -38
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +379 -143
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +48 -13
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -13
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/error-utils.js +8 -0
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +42 -7
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +4 -4
- 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 +3 -2
- 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/file-navigation.md +63 -49
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +33 -3
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +3 -1
- package/kits/docs/evolcore/thread-chain.md +12 -14
- package/kits/docs/evolcore/tool-authorization.md +21 -1
- package/kits/docs/evolcore/trigger.md +12 -9
- 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 -49
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +43 -45
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +20 -27
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- 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 -0
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- 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/identity.md +0 -1
- 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 +17 -13
- package/kits/schemas/agent-config.schema.20.json +0 -925
- package/kits/schemas/relation-config.schema.13.json +0 -289
- package/kits/schemas/role-config.schema.3.json +0 -1038
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { isIP } from 'node:net';
|
|
3
|
+
import { normalizeProviderDomain, providerIdentity } from './provider-identity.js';
|
|
3
4
|
const PROHIBITED_PATH_SEGMENTS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
4
5
|
const MULTIPART_DOMAIN_SUFFIXES = new Set(['com.cn', 'net.cn', 'org.cn', 'gov.cn', 'co.uk', 'org.uk', 'ac.uk', 'com.au', 'net.au', 'co.jp', 'co.nz']);
|
|
5
6
|
const PROVIDER_ENV_REFERENCE = /^\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})$/u;
|
|
@@ -183,7 +184,7 @@ function serviceConfig(value, field, serviceType) {
|
|
|
183
184
|
function providerConfig(value, field) {
|
|
184
185
|
if (!isRecord(value))
|
|
185
186
|
throw new Error(`${field} must be an object`);
|
|
186
|
-
assertFields(value, ['name', 'common', 'services'], field);
|
|
187
|
+
assertFields(value, ['name', 'domain', 'common', 'services'], field);
|
|
187
188
|
if (value.name !== undefined && typeof value.name !== 'string')
|
|
188
189
|
throw new Error(`${field}.name must be a string`);
|
|
189
190
|
if (!isRecord(value.common))
|
|
@@ -202,6 +203,7 @@ function providerConfig(value, field) {
|
|
|
202
203
|
if (typeof common.apiKey === 'string')
|
|
203
204
|
assertProviderEnvironmentSyntax(common.apiKey, `${field}.common.apiKey`);
|
|
204
205
|
const result = {
|
|
206
|
+
...(value.domain !== undefined ? { domain: normalizeProviderDomain(value.domain) } : {}),
|
|
205
207
|
...(typeof value.name === 'string' && value.name.trim() ? { name: value.name.trim() } : {}),
|
|
206
208
|
common: {
|
|
207
209
|
baseUrl,
|
|
@@ -227,12 +229,14 @@ function providerConfig(value, field) {
|
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
}
|
|
232
|
+
if (result.domain !== undefined)
|
|
233
|
+
providerIdentity(result);
|
|
230
234
|
return result;
|
|
231
235
|
}
|
|
232
236
|
export function validateProvidersFile(value) {
|
|
233
237
|
if (!isRecord(value))
|
|
234
238
|
throw new Error('providers.json must be an object');
|
|
235
|
-
assertFields(value, ['$schema_version', 'nextId', 'providers'], 'providers.json');
|
|
239
|
+
assertFields(value, ['$schema_version', 'nextId', 'aliases', 'providers'], 'providers.json');
|
|
236
240
|
if (value.$schema_version !== undefined && (!Number.isInteger(value.$schema_version) || Number(value.$schema_version) < 1)) {
|
|
237
241
|
throw new Error('providers.json.$schema_version must be a positive integer');
|
|
238
242
|
}
|
|
@@ -247,15 +251,36 @@ export function validateProvidersFile(value) {
|
|
|
247
251
|
throw new Error('provider id cannot be empty');
|
|
248
252
|
assertSafeRegistrySegment(providerId, 'provider id');
|
|
249
253
|
providers[providerId] = providerConfig(provider, `providers.${providerId}`);
|
|
254
|
+
if (providers[providerId].domain !== undefined && /^provider-\d{8}$/u.test(providerId)
|
|
255
|
+
&& providerIdentity(providers[providerId]).providerId !== providerId) {
|
|
256
|
+
throw new Error(`Provider ID does not match its domain: ${providerId}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const aliases = {};
|
|
260
|
+
if (value.aliases !== undefined) {
|
|
261
|
+
if (!isRecord(value.aliases))
|
|
262
|
+
throw new Error('providers.json.aliases must be an object');
|
|
263
|
+
for (const [alias, target] of Object.entries(value.aliases)) {
|
|
264
|
+
assertSafeRegistrySegment(alias, 'provider alias');
|
|
265
|
+
if (typeof target !== 'string' || !Object.hasOwn(providers, target) || Object.hasOwn(providers, alias)) {
|
|
266
|
+
throw new Error('Provider aliases must point directly to an existing Provider without shadowing an ID');
|
|
267
|
+
}
|
|
268
|
+
aliases[alias] = target;
|
|
269
|
+
}
|
|
250
270
|
}
|
|
251
271
|
return {
|
|
252
272
|
...(typeof value.$schema_version === 'number' ? { $schema_version: value.$schema_version } : {}),
|
|
253
273
|
...(typeof value.nextId === 'number' ? { nextId: value.nextId } : {}),
|
|
274
|
+
...(Object.keys(aliases).length ? { aliases } : {}),
|
|
254
275
|
providers,
|
|
255
276
|
};
|
|
256
277
|
}
|
|
257
|
-
export function
|
|
278
|
+
export function resolveProviderId(providerId, config) {
|
|
258
279
|
assertSafeRegistrySegment(providerId, 'provider id');
|
|
280
|
+
return config.aliases && Object.hasOwn(config.aliases, providerId) ? config.aliases[providerId] : providerId;
|
|
281
|
+
}
|
|
282
|
+
export function resolveProviderService(providerId, serviceType, config, defaultStyle = 'systemone') {
|
|
283
|
+
providerId = resolveProviderId(providerId, config);
|
|
259
284
|
assertSafeRegistrySegment(serviceType, 'service type');
|
|
260
285
|
const providers = config.providers;
|
|
261
286
|
const provider = Object.hasOwn(providers, providerId) ? providers[providerId] : undefined;
|
|
@@ -273,6 +298,8 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
273
298
|
if (!validProviderBaseUrl(resolvedBaseUrl)) {
|
|
274
299
|
throw new Error(`Provider ${providerId} common.baseUrl must resolve to a valid http(s) URL`);
|
|
275
300
|
}
|
|
301
|
+
if (provider.domain !== undefined)
|
|
302
|
+
providerIdentity({ ...provider, common: { ...provider.common, baseUrl: resolvedBaseUrl } });
|
|
276
303
|
const base = resolvedBaseUrl.endsWith('/') ? resolvedBaseUrl : `${resolvedBaseUrl}/`;
|
|
277
304
|
const parsed = new URL(service.path || '.', base);
|
|
278
305
|
if (parsed.origin !== new URL(base).origin)
|
|
@@ -295,12 +322,13 @@ export function resolveProviderService(providerId, serviceType, config, defaultS
|
|
|
295
322
|
};
|
|
296
323
|
}
|
|
297
324
|
export function resolveProviderServiceForBaseagent(providerId, baseagent, preferredServiceType, config) {
|
|
325
|
+
providerId = resolveProviderId(providerId, config);
|
|
298
326
|
const provider = Object.hasOwn(config.providers, providerId) ? config.providers[providerId] : undefined;
|
|
299
327
|
const serviceType = resolveProviderServiceTypeForBaseagent(baseagent, preferredServiceType, provider);
|
|
300
328
|
return resolveProviderService(providerId, serviceType, config, 'openai-compatible');
|
|
301
329
|
}
|
|
302
330
|
export function resolveProviderModelOverrides(providerId, serviceType, config, baseagent) {
|
|
303
|
-
|
|
331
|
+
providerId = resolveProviderId(providerId, config);
|
|
304
332
|
assertSafeRegistrySegment(serviceType, 'service type');
|
|
305
333
|
const provider = Object.hasOwn(config.providers, providerId) ? config.providers[providerId] : undefined;
|
|
306
334
|
if (!provider)
|