evolcore 0.0.43-test.4 → 0.0.43-test.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/bin/ecmsg.js +437 -91
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +18 -23
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +99 -23
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +19 -7
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +19 -4
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -4
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +206 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +120 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +35 -24
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +41 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +16 -3
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +5 -14
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +277 -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 +155 -0
- package/dist/config/providers-config.js +45 -4
- package/dist/config/providers-management.js +242 -76
- package/dist/config/providers.js +4 -1
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +143 -86
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +48 -9
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -11
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +80 -7
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +29 -17
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +139 -45
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +7 -6
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +83 -5
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +33 -25
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +320 -0
- package/dist/core/ownership/owner-resolver.js +112 -8
- package/dist/core/permission/ec-command-parser.js +159 -16
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +103 -17
- package/dist/core/session/session-manager.js +105 -18
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +739 -109
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +6 -3
- 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 +26 -15
- package/dist/ecweb/runtime/supervisor.js +120 -51
- package/dist/index.js +551 -250
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +40 -17
- package/dist/proxy/service-supervisor.js +67 -33
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +4 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +81 -8
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +188 -12
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +160 -19
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +6 -6
- 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 +5 -3
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +15 -5
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +8 -8
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +38 -30
- package/kits/docs/evolcore/provider.md +57 -5
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +44 -32
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +7 -8
- package/kits/schemas/_meta.json +7 -1
- 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/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- 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 +3 -10
- package/kits/skills/ec-trigger/SKILL.md +9 -9
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +7 -6
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +48 -28
- package/kits/templates/system-fragments/session.md +3 -10
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +4 -4
|
@@ -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)
|
|
@@ -319,6 +347,19 @@ export function resolveProviderModelOverrides(providerId, serviceType, config, b
|
|
|
319
347
|
export function providerIsConfigured(config) {
|
|
320
348
|
return config?.provider !== undefined;
|
|
321
349
|
}
|
|
350
|
+
export function initializationRuntimePlan(record) {
|
|
351
|
+
const migration = record.providerMigration;
|
|
352
|
+
if (migration === undefined)
|
|
353
|
+
return record.plan;
|
|
354
|
+
if (!migration || typeof migration !== 'object' || Array.isArray(migration))
|
|
355
|
+
throw new Error('Invalid initialization Provider migration binding');
|
|
356
|
+
if (typeof migration.from !== 'string' || migration.from !== record.plan.provider || typeof migration.to !== 'string'
|
|
357
|
+
|| !/^[A-Za-z0-9_-]+$/u.test(migration.to)
|
|
358
|
+
|| ['__proto__', 'constructor', 'prototype'].includes(migration.to)) {
|
|
359
|
+
throw new Error('Invalid initialization Provider migration binding');
|
|
360
|
+
}
|
|
361
|
+
return { ...record.plan, provider: migration.to };
|
|
362
|
+
}
|
|
322
363
|
export function resolveServiceSelection(selections, serviceType, resolve) {
|
|
323
364
|
const selection = selections?.[serviceType];
|
|
324
365
|
if (!selection)
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import fs from 'node:fs';
|
|
3
4
|
import path, { posix } from 'node:path';
|
|
4
5
|
import { resolvePaths } from '../paths.js';
|
|
5
|
-
import { ConfigTarget, mutateConfig } from './config-manager.js';
|
|
6
|
+
import { ConfigTarget, mutateConfig, notifyConfigWrite } from './config-manager.js';
|
|
6
7
|
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
7
8
|
import { readProvidersFile, validateProvidersFile } from './providers.js';
|
|
8
|
-
import { providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
9
|
+
import { initializationRuntimePlan, providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderId, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
10
|
+
import { providerIdentity } from './provider-identity.js';
|
|
11
|
+
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
9
12
|
export const PROVIDER_SECRET_MASK = '<redacted>';
|
|
10
13
|
function providerReferences(providerId, providerFile) {
|
|
14
|
+
const registry = readProvidersFile(providerFile);
|
|
15
|
+
const referencedIds = new Set([providerId, ...Object.entries(registry.aliases ?? {}).filter(([, target]) => target === providerId).map(([alias]) => alias)]);
|
|
11
16
|
const root = path.dirname(path.resolve(providerFile));
|
|
12
17
|
const agentsDir = path.join(root, 'agents');
|
|
13
18
|
const candidates = [path.join(agentsDir, 'defaults.json')];
|
|
@@ -26,10 +31,20 @@ function providerReferences(providerId, providerFile) {
|
|
|
26
31
|
};
|
|
27
32
|
for (const agent of directories(agentsDir)) {
|
|
28
33
|
candidates.push(path.join(agentsDir, agent.name, 'config.json'));
|
|
34
|
+
candidates.push(path.join(agentsDir, agent.name, 'data', 'initialization.json'));
|
|
29
35
|
for (const relation of directories(path.join(agentsDir, agent.name, 'relations'))) {
|
|
30
36
|
candidates.push(path.join(agentsDir, agent.name, 'relations', relation.name, 'config.json'));
|
|
31
37
|
}
|
|
32
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
|
+
}
|
|
33
48
|
const references = [];
|
|
34
49
|
const visit = (value, fieldPath, file) => {
|
|
35
50
|
if (Array.isArray(value)) {
|
|
@@ -40,7 +55,7 @@ function providerReferences(providerId, providerFile) {
|
|
|
40
55
|
return;
|
|
41
56
|
for (const [key, child] of Object.entries(value)) {
|
|
42
57
|
const childPath = fieldPath + '.' + key;
|
|
43
|
-
if (key === 'provider' && child ===
|
|
58
|
+
if (key === 'provider' && typeof child === 'string' && referencedIds.has(child))
|
|
44
59
|
references.push({ file, path: childPath });
|
|
45
60
|
visit(child, childPath, file);
|
|
46
61
|
}
|
|
@@ -52,7 +67,20 @@ function providerReferences(providerId, providerFile) {
|
|
|
52
67
|
continue;
|
|
53
68
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
54
69
|
throw new Error();
|
|
55
|
-
|
|
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
|
+
}
|
|
83
|
+
for (const field of ['baseagents', 'agents', 'Services', 'decision_model', 'plan', 'creation']) {
|
|
56
84
|
visit(value[field], field, path.relative(root, file).replace(/\\/g, '/'));
|
|
57
85
|
}
|
|
58
86
|
}
|
|
@@ -82,7 +110,7 @@ function revisionValue(value) {
|
|
|
82
110
|
.map(([key, entry]) => [key, revisionValue(entry)]));
|
|
83
111
|
}
|
|
84
112
|
export function providersRevision(value) {
|
|
85
|
-
return createHash('sha256').update(JSON.stringify(revisionValue({ providers: value.providers, ...(value.nextId !== undefined ? { nextId: value.nextId } : {}) }))).digest('hex');
|
|
113
|
+
return createHash('sha256').update(JSON.stringify(revisionValue({ providers: value.providers, ...(value.nextId !== undefined ? { nextId: value.nextId } : {}), ...(Object.keys(value.aliases ?? {}).length ? { aliases: value.aliases } : {}) }))).digest('hex');
|
|
86
114
|
}
|
|
87
115
|
export function readProvidersSnapshot(file = resolvePaths().providersConfig) {
|
|
88
116
|
return providersSnapshot(readProvidersFile(file));
|
|
@@ -92,7 +120,9 @@ export function readProviderForExport(providerId, serviceType, file = resolvePat
|
|
|
92
120
|
throw new Error('Invalid provider identifier');
|
|
93
121
|
if (serviceType !== undefined && (!/^[A-Za-z0-9_-]+$/u.test(serviceType) || ['__proto__', 'constructor', 'prototype'].includes(serviceType)))
|
|
94
122
|
throw new Error('Invalid service type');
|
|
95
|
-
const
|
|
123
|
+
const registry = readProvidersFile(file);
|
|
124
|
+
providerId = resolveProviderId(providerId, registry);
|
|
125
|
+
const provider = registry.providers[providerId];
|
|
96
126
|
if (!provider)
|
|
97
127
|
throw Object.assign(new Error('Provider not found'), { statusCode: 404 });
|
|
98
128
|
const exported = structuredClone(provider);
|
|
@@ -120,6 +150,7 @@ function providersSnapshot(value) {
|
|
|
120
150
|
return {
|
|
121
151
|
...(value.$schema_version !== undefined ? { $schema_version: value.$schema_version } : {}),
|
|
122
152
|
...(value.nextId !== undefined ? { nextId: value.nextId } : {}),
|
|
153
|
+
...(value.aliases ? { aliases: structuredClone(value.aliases) } : {}),
|
|
123
154
|
providers,
|
|
124
155
|
revision: providersRevision(value),
|
|
125
156
|
};
|
|
@@ -155,14 +186,17 @@ export function resolveProviderDraftService(input, file = resolvePaths().provide
|
|
|
155
186
|
throw new Error('Invalid provider identifier');
|
|
156
187
|
}
|
|
157
188
|
const current = readProvidersFile(file);
|
|
158
|
-
const
|
|
189
|
+
const providerId = resolveProviderId(input.providerId, current);
|
|
190
|
+
const previous = Object.hasOwn(current.providers, providerId) ? current.providers[providerId] : undefined;
|
|
159
191
|
const provider = resolveDraftProvider(input.value, previous, input.imports);
|
|
192
|
+
if (previous)
|
|
193
|
+
assertProviderDomainUnchanged(previous, provider);
|
|
160
194
|
if (input.baseagent) {
|
|
161
|
-
return resolveProviderServiceForBaseagent(
|
|
162
|
-
providers: { [
|
|
195
|
+
return resolveProviderServiceForBaseagent(providerId, input.baseagent, input.serviceType, {
|
|
196
|
+
providers: { [providerId]: provider },
|
|
163
197
|
});
|
|
164
198
|
}
|
|
165
|
-
return resolveProviderService(
|
|
199
|
+
return resolveProviderService(providerId, input.serviceType, { providers: { [providerId]: provider } });
|
|
166
200
|
}
|
|
167
201
|
export async function updateProvider(input, file = resolvePaths().providersConfig) {
|
|
168
202
|
if (!/^[A-Za-z0-9_-]+$/u.test(input.providerId) || ['__proto__', 'constructor', 'prototype'].includes(input.providerId)) {
|
|
@@ -170,23 +204,26 @@ export async function updateProvider(input, file = resolvePaths().providersConfi
|
|
|
170
204
|
}
|
|
171
205
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
172
206
|
const current = config;
|
|
207
|
+
const providerId = resolveProviderId(input.providerId, current);
|
|
173
208
|
if (providersRevision(current) !== input.revision) {
|
|
174
209
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
175
210
|
}
|
|
176
|
-
if (!Object.hasOwn(current.providers,
|
|
211
|
+
if (!Object.hasOwn(current.providers, providerId)) {
|
|
177
212
|
throw Object.assign(new Error(`Provider not found: ${input.providerId}`), { code: 'NOT_FOUND', statusCode: 404 });
|
|
178
213
|
}
|
|
179
214
|
if (input.remove) {
|
|
180
|
-
assertProviderUnreferenced(
|
|
181
|
-
current.
|
|
182
|
-
|
|
215
|
+
assertProviderUnreferenced(providerId, file);
|
|
216
|
+
delete current.providers[providerId];
|
|
217
|
+
removeProviderAliases(current, providerId);
|
|
183
218
|
}
|
|
184
219
|
else {
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
220
|
+
const previous = current.providers[providerId];
|
|
221
|
+
const value = retainSecrets(input.value, previous);
|
|
222
|
+
const normalized = validateProvidersFile({ providers: { draft: value } }).providers.draft;
|
|
223
|
+
assertProviderDomainUnchanged(previous, normalized);
|
|
224
|
+
if (normalized.name !== undefined)
|
|
225
|
+
normalized.name = validateProviderName(normalized.name);
|
|
226
|
+
current.providers[providerId] = normalized;
|
|
190
227
|
}
|
|
191
228
|
return current;
|
|
192
229
|
});
|
|
@@ -228,7 +265,7 @@ export function parseProviderImport(text) {
|
|
|
228
265
|
const value = parsed;
|
|
229
266
|
const isProviderMap = Object.values(value).every(provider => provider && typeof provider === 'object'
|
|
230
267
|
&& !Array.isArray(provider) && Object.hasOwn(provider, 'common'));
|
|
231
|
-
const isSingleProvider = !isProviderMap && ['name', 'common', 'services'].some(field => Object.hasOwn(value, field));
|
|
268
|
+
const isSingleProvider = !isProviderMap && ['name', 'domain', 'common', 'services'].some(field => Object.hasOwn(value, field));
|
|
232
269
|
if (!Object.hasOwn(value, 'providers') && isSingleProvider && !Object.hasOwn(value, 'common')) {
|
|
233
270
|
throw new Error('Provider configuration is missing "common"; check the field spelling');
|
|
234
271
|
}
|
|
@@ -247,18 +284,67 @@ export function previewProviderImport(text) {
|
|
|
247
284
|
}
|
|
248
285
|
export function previewProviderValue(value) {
|
|
249
286
|
const normalized = validateProvidersFile({ providers: { preview: value } });
|
|
287
|
+
normalized.providers.preview.domain = providerIdentity(normalized.providers.preview).domain;
|
|
250
288
|
return { provider: providersSnapshot(normalized).providers.preview };
|
|
251
289
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
290
|
+
function removeProviderAliases(config, providerId) {
|
|
291
|
+
for (const [alias, target] of Object.entries(config.aliases ?? {})) {
|
|
292
|
+
if (target === providerId)
|
|
293
|
+
delete config.aliases[alias];
|
|
294
|
+
}
|
|
295
|
+
if (config.aliases && !Object.keys(config.aliases).length)
|
|
296
|
+
delete config.aliases;
|
|
297
|
+
}
|
|
298
|
+
function assertProviderDomainUnchanged(previous, next) {
|
|
299
|
+
let previousDomain;
|
|
300
|
+
try {
|
|
301
|
+
previousDomain = providerIdentity(previous).domain;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
const code = error?.code;
|
|
305
|
+
if (previous.domain === undefined && (code === 'PROVIDER_DOMAIN_REQUIRED' || code === 'PROVIDER_DOMAIN_INVALID')) {
|
|
306
|
+
if (previous.common.baseUrl === next.common.baseUrl) {
|
|
307
|
+
if (next.domain !== undefined)
|
|
308
|
+
next.domain = providerIdentity(next).domain;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
const identity = providerIdentity(next);
|
|
315
|
+
if (identity.domain !== previousDomain) {
|
|
316
|
+
throw Object.assign(new Error('Provider domain is immutable; create a different Provider'), { code: 'PROVIDER_DOMAIN_IMMUTABLE' });
|
|
317
|
+
}
|
|
318
|
+
next.domain = identity.domain;
|
|
319
|
+
}
|
|
320
|
+
function existingProviderDomain(provider) {
|
|
321
|
+
try {
|
|
322
|
+
return providerIdentity(provider).domain;
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function availableProviderId(config, provider) {
|
|
329
|
+
const identity = providerIdentity(provider);
|
|
330
|
+
provider.domain = identity.domain;
|
|
331
|
+
for (const [existingId, existing] of Object.entries(config.providers)) {
|
|
332
|
+
const domain = existingProviderDomain(existing);
|
|
333
|
+
if (existingId === identity.providerId && domain !== identity.domain) {
|
|
334
|
+
throw Object.assign(new Error('Provider ID hash collision; no ID was reassigned'), {
|
|
335
|
+
code: 'PROVIDER_ID_COLLISION', statusCode: 409, data: { kind: 'provider_id_collision', providerId: identity.providerId, domain: identity.domain, existingDomain: domain },
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (domain === identity.domain) {
|
|
339
|
+
throw Object.assign(new Error('Provider domain already exists; update or explicitly merge it'), {
|
|
340
|
+
code: 'PROVIDER_CONFLICT', statusCode: 409, data: { kind: 'provider_domain_exists', providerId: existingId, domain },
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (Object.hasOwn(config.aliases ?? {}, identity.providerId)) {
|
|
345
|
+
throw Object.assign(new Error('Provider ID conflicts with a legacy alias'), { code: 'PROVIDER_ID_COLLISION', statusCode: 409 });
|
|
346
|
+
}
|
|
347
|
+
return identity.providerId;
|
|
262
348
|
}
|
|
263
349
|
export async function createProvider(input, file = resolvePaths().providersConfig) {
|
|
264
350
|
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
@@ -274,14 +360,85 @@ export async function createProvider(input, file = resolvePaths().providersConfi
|
|
|
274
360
|
if (providersRevision(current) !== input.revision) {
|
|
275
361
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
276
362
|
}
|
|
277
|
-
const
|
|
278
|
-
|
|
363
|
+
const identity = providerIdentity(provider);
|
|
364
|
+
provider.domain = identity.domain;
|
|
365
|
+
const existing = current.providers[identity.providerId];
|
|
366
|
+
if (existing && isDeepStrictEqual(existing, provider))
|
|
367
|
+
return { current, providerId: identity.providerId };
|
|
368
|
+
const providerId = availableProviderId(current, provider);
|
|
279
369
|
current.providers[providerId] = provider;
|
|
280
|
-
current.nextId
|
|
370
|
+
delete current.nextId;
|
|
281
371
|
return { current, providerId };
|
|
282
372
|
});
|
|
283
373
|
return { ...providersSnapshot(result.value.current), providerId: result.value.providerId };
|
|
284
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
|
+
}
|
|
285
442
|
function providerHostname(baseUrl) {
|
|
286
443
|
if (providerEnvironmentVariable(baseUrl))
|
|
287
444
|
return undefined;
|
|
@@ -335,14 +492,16 @@ function resolveDraftProvider(value, previous, imports = []) {
|
|
|
335
492
|
for (const item of imports) {
|
|
336
493
|
const imported = validateProvidersFile({ providers: { imported: item } }).providers.imported;
|
|
337
494
|
rejectMaskedImportSecrets({ imported });
|
|
338
|
-
|
|
339
|
-
const importedHost = providerHostname(imported.common.baseUrl);
|
|
340
|
-
if (secretSource && secretSourceHost && importedHost && secretSourceHost !== importedHost) {
|
|
495
|
+
if (secretSource && providerIdentity(secretSource).domain !== providerIdentity(imported).domain) {
|
|
341
496
|
throw new Error('Imported Provider domain does not match the target Provider');
|
|
342
497
|
}
|
|
343
498
|
secretSource = secretSource ? mergeImportedProvider(secretSource, imported) : imported;
|
|
344
499
|
}
|
|
345
|
-
|
|
500
|
+
const provider = validateProvidersFile({ providers: { draft: retainSecrets(value, secretSource) } }).providers.draft;
|
|
501
|
+
if (imports.length && secretSource && providerIdentity(provider).domain !== providerIdentity(secretSource).domain) {
|
|
502
|
+
throw new Error('Imported Provider domain does not match the draft Provider');
|
|
503
|
+
}
|
|
504
|
+
return provider;
|
|
346
505
|
}
|
|
347
506
|
export async function saveProviderChanges(input, file = resolvePaths().providersConfig) {
|
|
348
507
|
if (!Array.isArray(input.changes) || !input.changes.length)
|
|
@@ -361,42 +520,47 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
361
520
|
}
|
|
362
521
|
identifiers.add(change.providerId);
|
|
363
522
|
}
|
|
364
|
-
const result =
|
|
365
|
-
const current = config;
|
|
523
|
+
const result = await mutateProvidersWithIdentityUpgrade(input.revision, file, current => {
|
|
366
524
|
if (providersRevision(current) !== input.revision) {
|
|
367
525
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
368
526
|
}
|
|
369
527
|
const providerIds = {};
|
|
370
528
|
const originalIds = new Set(Object.keys(current.providers));
|
|
371
|
-
|
|
372
|
-
current.nextId = nextProviderSequence(current);
|
|
529
|
+
const resolvedIds = new Set();
|
|
373
530
|
for (const change of input.changes) {
|
|
374
|
-
|
|
531
|
+
const targetId = change.create ? change.providerId : resolveProviderId(change.providerId, current);
|
|
532
|
+
if (resolvedIds.has(targetId))
|
|
533
|
+
throw new Error('Duplicate provider change');
|
|
534
|
+
resolvedIds.add(targetId);
|
|
535
|
+
if (change.create ? originalIds.has(targetId) : !originalIds.has(targetId)) {
|
|
375
536
|
throw new Error(change.create ? 'Provider already exists' : 'Provider not found');
|
|
376
537
|
}
|
|
377
538
|
if (change.remove) {
|
|
378
|
-
assertProviderUnreferenced(
|
|
379
|
-
delete current.providers[
|
|
539
|
+
assertProviderUnreferenced(targetId, file);
|
|
540
|
+
delete current.providers[targetId];
|
|
541
|
+
removeProviderAliases(current, targetId);
|
|
380
542
|
continue;
|
|
381
543
|
}
|
|
382
|
-
const previous = change.create ? undefined : current.providers[
|
|
544
|
+
const previous = change.create ? undefined : current.providers[targetId];
|
|
383
545
|
const provider = resolveDraftProvider(change.value, previous, change.imports);
|
|
546
|
+
if (previous)
|
|
547
|
+
assertProviderDomainUnchanged(previous, provider);
|
|
384
548
|
provider.name ||= providerNameFromBaseUrlIfStatic(provider.common.baseUrl);
|
|
385
549
|
if (provider.name !== undefined)
|
|
386
550
|
provider.name = validateProviderName(provider.name);
|
|
387
|
-
|
|
551
|
+
let providerId = change.create ? availableProviderId(current, provider) : targetId;
|
|
388
552
|
if (change.create)
|
|
389
|
-
current.nextId
|
|
553
|
+
delete current.nextId;
|
|
390
554
|
current.providers[providerId] = provider;
|
|
555
|
+
if (!change.create && change.imports?.length)
|
|
556
|
+
providerId = upgradeProviderId(current, providerId);
|
|
391
557
|
providerIds[change.providerId] = providerId;
|
|
392
558
|
}
|
|
393
559
|
return { current, providerIds };
|
|
394
560
|
});
|
|
395
|
-
return { ...providersSnapshot(result.
|
|
561
|
+
return { ...providersSnapshot(result.current), providerIds: result.providerIds };
|
|
396
562
|
}
|
|
397
|
-
export
|
|
398
|
-
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
399
|
-
throw new Error('A valid providers revision is required');
|
|
563
|
+
export function importBaseagentProviderIntoRegistry(current, input) {
|
|
400
564
|
const normalized = validateProvidersFile({ providers: { imported: input.value } });
|
|
401
565
|
rejectMaskedImportSecrets(normalized.providers);
|
|
402
566
|
const imported = normalized.providers.imported;
|
|
@@ -405,33 +569,35 @@ export async function importOrMergeBaseagentProvider(input, file = resolvePaths(
|
|
|
405
569
|
imported.name = validateProviderName(input.name);
|
|
406
570
|
if (input.resolution === 'cancel')
|
|
407
571
|
throw Object.assign(new Error('Provider import cancelled'), { code: 'CANCELLED', statusCode: 409 });
|
|
408
|
-
const
|
|
409
|
-
|
|
572
|
+
const identity = providerIdentity(imported);
|
|
573
|
+
imported.domain = identity.domain;
|
|
574
|
+
const match = Object.entries(current.providers).find(([, provider]) => existingProviderDomain(provider) === identity.domain);
|
|
575
|
+
if (match && input.requireResolution && input.resolution === undefined) {
|
|
576
|
+
const [providerId, existing] = match;
|
|
577
|
+
throw Object.assign(new Error('Provider conflict requires an explicit resolution'), {
|
|
578
|
+
code: 'PROVIDER_CONFLICT', statusCode: 409,
|
|
579
|
+
data: { kind: 'provider_conflict', providerId, overlaps: Object.keys(imported.services || {}).filter(type => Object.hasOwn(existing.services || {}, type)) },
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
if (match && input.resolution !== 'create') {
|
|
583
|
+
const [providerId, existing] = match;
|
|
584
|
+
const replaceServiceTypes = new Set(Object.entries(input.serviceDecisions || {}).filter(([, decision]) => decision === 'imported').map(([type]) => type));
|
|
585
|
+
current.providers[providerId] = validateProvidersFile({ providers: { [providerId]: mergeImportedProvider(existing, imported, replaceServiceTypes) } }).providers[providerId];
|
|
586
|
+
return { current, providerId: upgradeProviderId(current, providerId), merged: true };
|
|
587
|
+
}
|
|
588
|
+
const providerId = availableProviderId(current, imported);
|
|
589
|
+
current.providers[providerId] = imported;
|
|
590
|
+
delete current.nextId;
|
|
591
|
+
return { current, providerId, merged: false };
|
|
592
|
+
}
|
|
593
|
+
export async function importOrMergeBaseagentProvider(input, file = resolvePaths().providersConfig) {
|
|
594
|
+
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
595
|
+
throw new Error('A valid providers revision is required');
|
|
596
|
+
const result = await mutateProvidersWithIdentityUpgrade(input.revision, file, current => {
|
|
410
597
|
if (providersRevision(current) !== input.revision) {
|
|
411
598
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
412
599
|
}
|
|
413
|
-
|
|
414
|
-
const importedName = imported.name?.trim().toLowerCase();
|
|
415
|
-
const match = Object.entries(current.providers).find(([, provider]) => (!!importedName && provider.name?.trim().toLowerCase() === importedName)
|
|
416
|
-
|| (!!importedHost && providerHostname(provider.common.baseUrl) === importedHost));
|
|
417
|
-
if (match && input.requireResolution && input.resolution === undefined) {
|
|
418
|
-
const [providerId, existing] = match;
|
|
419
|
-
throw Object.assign(new Error('Provider conflict requires an explicit resolution'), {
|
|
420
|
-
code: 'PROVIDER_CONFLICT', statusCode: 409,
|
|
421
|
-
data: { kind: 'provider_conflict', providerId, overlaps: Object.keys(imported.services || {}).filter(type => Object.hasOwn(existing.services || {}, type)) },
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
if (match && input.resolution !== 'create') {
|
|
425
|
-
const [providerId, existing] = match;
|
|
426
|
-
const replaceServiceTypes = new Set(Object.entries(input.serviceDecisions || {}).filter(([, decision]) => decision === 'imported').map(([type]) => type));
|
|
427
|
-
current.providers[providerId] = validateProvidersFile({ providers: { [providerId]: mergeImportedProvider(existing, imported, replaceServiceTypes) } }).providers[providerId];
|
|
428
|
-
return { current, providerId, merged: true };
|
|
429
|
-
}
|
|
430
|
-
const sequence = nextProviderSequence(current);
|
|
431
|
-
const providerId = `provider-${sequence}`;
|
|
432
|
-
current.providers[providerId] = imported;
|
|
433
|
-
current.nextId = sequence + 1;
|
|
434
|
-
return { current, providerId, merged: false };
|
|
600
|
+
return importBaseagentProviderIntoRegistry(current, input);
|
|
435
601
|
});
|
|
436
|
-
return { ...providersSnapshot(result.
|
|
602
|
+
return { ...providersSnapshot(result.current), providerId: result.providerId, merged: result.merged };
|
|
437
603
|
}
|
package/dist/config/providers.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { resolvePaths } from '../paths.js';
|
|
2
2
|
import { ConfigTarget, read, write } from './config-manager.js';
|
|
3
|
-
import { assertProviderSelectionWrite as validateSelectionWrite, resolveProviderModelOverrides as resolveModelOverrides, resolveProviderService as resolveService, resolveProviderServiceForBaseagent as resolveServiceForBaseagent, resolveServiceSelection as resolveSelection, } from './providers-config.js';
|
|
3
|
+
import { assertProviderSelectionWrite as validateSelectionWrite, resolveProviderModelOverrides as resolveModelOverrides, resolveProviderService as resolveService, resolveProviderServiceForBaseagent as resolveServiceForBaseagent, resolveServiceSelection as resolveSelection, resolveProviderId as resolveId, } from './providers-config.js';
|
|
4
4
|
export { providerIsConfigured, providerServiceTypeForBaseagent, providerServiceTypesForBaseagent, providerServiceTypeForPurpose, validateProvidersFile, } from './providers-config.js';
|
|
5
5
|
export function readProvidersFile(file = resolvePaths().providersConfig) {
|
|
6
6
|
return read(ConfigTarget.Providers, { providerFile: file }) ?? { providers: {} };
|
|
7
7
|
}
|
|
8
|
+
export function resolveProviderId(providerId, file = resolvePaths().providersConfig) {
|
|
9
|
+
return resolveId(providerId, readProvidersFile(file));
|
|
10
|
+
}
|
|
8
11
|
export function writeProvidersFile(value, file = resolvePaths().providersConfig) {
|
|
9
12
|
write(ConfigTarget.Providers, value, { providerFile: file });
|
|
10
13
|
}
|