evolcore 0.0.43-test.4 → 0.0.43-test.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/bin/ecmsg.js +354 -91
- package/dist/agents/codex-runner.js +12 -17
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/channels/aun.js +30 -17
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +4 -2
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +10 -3
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +12 -3
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +45 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +11 -19
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +3 -0
- package/dist/config/boot-log.js +12 -1
- package/dist/config/config-manager.js +4 -13
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +5 -5
- package/dist/config/provider-identity-migration.js +202 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +153 -0
- package/dist/config/providers-config.js +32 -4
- package/dist/config/providers-management.js +144 -68
- package/dist/config/providers.js +4 -1
- package/dist/config/schema-migration.js +67 -3
- package/dist/core/agent-runtime.js +4 -2
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +11 -6
- package/dist/core/command/menu-protocol.js +4 -2
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/response-engine.js +23 -23
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/ownership/owner-resolver.js +111 -8
- package/dist/core/permission/ec-command-parser.js +148 -15
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/session-idle-monitor.js +94 -16
- package/dist/core/session/session-manager.js +69 -16
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-cache.js +686 -97
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +2 -2
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -9
- package/dist/ecweb/runtime/supervisor.js +76 -24
- package/dist/index.js +4 -0
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/scheduler.js +3 -3
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +13 -4
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +28 -28
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +1 -1
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +5 -5
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +47 -28
- package/kits/templates/system-fragments/session.md +2 -9
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +2 -3
|
@@ -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)
|
|
@@ -1,13 +1,17 @@
|
|
|
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
6
|
import { ConfigTarget, mutateConfig } 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 { providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderId, resolveProviderService, resolveProviderServiceForBaseagent, validateProviderName } from './providers-config.js';
|
|
10
|
+
import { providerIdentity } from './provider-identity.js';
|
|
9
11
|
export const PROVIDER_SECRET_MASK = '<redacted>';
|
|
10
12
|
function providerReferences(providerId, providerFile) {
|
|
13
|
+
const registry = readProvidersFile(providerFile);
|
|
14
|
+
const referencedIds = new Set([providerId, ...Object.entries(registry.aliases ?? {}).filter(([, target]) => target === providerId).map(([alias]) => alias)]);
|
|
11
15
|
const root = path.dirname(path.resolve(providerFile));
|
|
12
16
|
const agentsDir = path.join(root, 'agents');
|
|
13
17
|
const candidates = [path.join(agentsDir, 'defaults.json')];
|
|
@@ -26,6 +30,7 @@ function providerReferences(providerId, providerFile) {
|
|
|
26
30
|
};
|
|
27
31
|
for (const agent of directories(agentsDir)) {
|
|
28
32
|
candidates.push(path.join(agentsDir, agent.name, 'config.json'));
|
|
33
|
+
candidates.push(path.join(agentsDir, agent.name, 'data', 'initialization.json'));
|
|
29
34
|
for (const relation of directories(path.join(agentsDir, agent.name, 'relations'))) {
|
|
30
35
|
candidates.push(path.join(agentsDir, agent.name, 'relations', relation.name, 'config.json'));
|
|
31
36
|
}
|
|
@@ -40,7 +45,7 @@ function providerReferences(providerId, providerFile) {
|
|
|
40
45
|
return;
|
|
41
46
|
for (const [key, child] of Object.entries(value)) {
|
|
42
47
|
const childPath = fieldPath + '.' + key;
|
|
43
|
-
if (key === 'provider' && child ===
|
|
48
|
+
if (key === 'provider' && typeof child === 'string' && referencedIds.has(child))
|
|
44
49
|
references.push({ file, path: childPath });
|
|
45
50
|
visit(child, childPath, file);
|
|
46
51
|
}
|
|
@@ -52,7 +57,7 @@ function providerReferences(providerId, providerFile) {
|
|
|
52
57
|
continue;
|
|
53
58
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
54
59
|
throw new Error();
|
|
55
|
-
for (const field of ['baseagents', 'agents', 'Services', 'decision_model']) {
|
|
60
|
+
for (const field of ['baseagents', 'agents', 'Services', 'decision_model', 'plan', 'creation']) {
|
|
56
61
|
visit(value[field], field, path.relative(root, file).replace(/\\/g, '/'));
|
|
57
62
|
}
|
|
58
63
|
}
|
|
@@ -82,7 +87,7 @@ function revisionValue(value) {
|
|
|
82
87
|
.map(([key, entry]) => [key, revisionValue(entry)]));
|
|
83
88
|
}
|
|
84
89
|
export function providersRevision(value) {
|
|
85
|
-
return createHash('sha256').update(JSON.stringify(revisionValue({ providers: value.providers, ...(value.nextId !== undefined ? { nextId: value.nextId } : {}) }))).digest('hex');
|
|
90
|
+
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
91
|
}
|
|
87
92
|
export function readProvidersSnapshot(file = resolvePaths().providersConfig) {
|
|
88
93
|
return providersSnapshot(readProvidersFile(file));
|
|
@@ -92,7 +97,9 @@ export function readProviderForExport(providerId, serviceType, file = resolvePat
|
|
|
92
97
|
throw new Error('Invalid provider identifier');
|
|
93
98
|
if (serviceType !== undefined && (!/^[A-Za-z0-9_-]+$/u.test(serviceType) || ['__proto__', 'constructor', 'prototype'].includes(serviceType)))
|
|
94
99
|
throw new Error('Invalid service type');
|
|
95
|
-
const
|
|
100
|
+
const registry = readProvidersFile(file);
|
|
101
|
+
providerId = resolveProviderId(providerId, registry);
|
|
102
|
+
const provider = registry.providers[providerId];
|
|
96
103
|
if (!provider)
|
|
97
104
|
throw Object.assign(new Error('Provider not found'), { statusCode: 404 });
|
|
98
105
|
const exported = structuredClone(provider);
|
|
@@ -120,6 +127,7 @@ function providersSnapshot(value) {
|
|
|
120
127
|
return {
|
|
121
128
|
...(value.$schema_version !== undefined ? { $schema_version: value.$schema_version } : {}),
|
|
122
129
|
...(value.nextId !== undefined ? { nextId: value.nextId } : {}),
|
|
130
|
+
...(value.aliases ? { aliases: structuredClone(value.aliases) } : {}),
|
|
123
131
|
providers,
|
|
124
132
|
revision: providersRevision(value),
|
|
125
133
|
};
|
|
@@ -155,14 +163,17 @@ export function resolveProviderDraftService(input, file = resolvePaths().provide
|
|
|
155
163
|
throw new Error('Invalid provider identifier');
|
|
156
164
|
}
|
|
157
165
|
const current = readProvidersFile(file);
|
|
158
|
-
const
|
|
166
|
+
const providerId = resolveProviderId(input.providerId, current);
|
|
167
|
+
const previous = Object.hasOwn(current.providers, providerId) ? current.providers[providerId] : undefined;
|
|
159
168
|
const provider = resolveDraftProvider(input.value, previous, input.imports);
|
|
169
|
+
if (previous)
|
|
170
|
+
assertProviderDomainUnchanged(previous, provider);
|
|
160
171
|
if (input.baseagent) {
|
|
161
|
-
return resolveProviderServiceForBaseagent(
|
|
162
|
-
providers: { [
|
|
172
|
+
return resolveProviderServiceForBaseagent(providerId, input.baseagent, input.serviceType, {
|
|
173
|
+
providers: { [providerId]: provider },
|
|
163
174
|
});
|
|
164
175
|
}
|
|
165
|
-
return resolveProviderService(
|
|
176
|
+
return resolveProviderService(providerId, input.serviceType, { providers: { [providerId]: provider } });
|
|
166
177
|
}
|
|
167
178
|
export async function updateProvider(input, file = resolvePaths().providersConfig) {
|
|
168
179
|
if (!/^[A-Za-z0-9_-]+$/u.test(input.providerId) || ['__proto__', 'constructor', 'prototype'].includes(input.providerId)) {
|
|
@@ -170,23 +181,26 @@ export async function updateProvider(input, file = resolvePaths().providersConfi
|
|
|
170
181
|
}
|
|
171
182
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
172
183
|
const current = config;
|
|
184
|
+
const providerId = resolveProviderId(input.providerId, current);
|
|
173
185
|
if (providersRevision(current) !== input.revision) {
|
|
174
186
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
175
187
|
}
|
|
176
|
-
if (!Object.hasOwn(current.providers,
|
|
188
|
+
if (!Object.hasOwn(current.providers, providerId)) {
|
|
177
189
|
throw Object.assign(new Error(`Provider not found: ${input.providerId}`), { code: 'NOT_FOUND', statusCode: 404 });
|
|
178
190
|
}
|
|
179
191
|
if (input.remove) {
|
|
180
|
-
assertProviderUnreferenced(
|
|
181
|
-
current.
|
|
182
|
-
|
|
192
|
+
assertProviderUnreferenced(providerId, file);
|
|
193
|
+
delete current.providers[providerId];
|
|
194
|
+
removeProviderAliases(current, providerId);
|
|
183
195
|
}
|
|
184
196
|
else {
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
const previous = current.providers[providerId];
|
|
198
|
+
const value = retainSecrets(input.value, previous);
|
|
199
|
+
const normalized = validateProvidersFile({ providers: { draft: value } }).providers.draft;
|
|
200
|
+
assertProviderDomainUnchanged(previous, normalized);
|
|
201
|
+
if (normalized.name !== undefined)
|
|
202
|
+
normalized.name = validateProviderName(normalized.name);
|
|
203
|
+
current.providers[providerId] = normalized;
|
|
190
204
|
}
|
|
191
205
|
return current;
|
|
192
206
|
});
|
|
@@ -228,7 +242,7 @@ export function parseProviderImport(text) {
|
|
|
228
242
|
const value = parsed;
|
|
229
243
|
const isProviderMap = Object.values(value).every(provider => provider && typeof provider === 'object'
|
|
230
244
|
&& !Array.isArray(provider) && Object.hasOwn(provider, 'common'));
|
|
231
|
-
const isSingleProvider = !isProviderMap && ['name', 'common', 'services'].some(field => Object.hasOwn(value, field));
|
|
245
|
+
const isSingleProvider = !isProviderMap && ['name', 'domain', 'common', 'services'].some(field => Object.hasOwn(value, field));
|
|
232
246
|
if (!Object.hasOwn(value, 'providers') && isSingleProvider && !Object.hasOwn(value, 'common')) {
|
|
233
247
|
throw new Error('Provider configuration is missing "common"; check the field spelling');
|
|
234
248
|
}
|
|
@@ -247,18 +261,67 @@ export function previewProviderImport(text) {
|
|
|
247
261
|
}
|
|
248
262
|
export function previewProviderValue(value) {
|
|
249
263
|
const normalized = validateProvidersFile({ providers: { preview: value } });
|
|
264
|
+
normalized.providers.preview.domain = providerIdentity(normalized.providers.preview).domain;
|
|
250
265
|
return { provider: providersSnapshot(normalized).providers.preview };
|
|
251
266
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (match)
|
|
257
|
-
nextId = Math.max(nextId, Number(match[1]) + 1);
|
|
267
|
+
function removeProviderAliases(config, providerId) {
|
|
268
|
+
for (const [alias, target] of Object.entries(config.aliases ?? {})) {
|
|
269
|
+
if (target === providerId)
|
|
270
|
+
delete config.aliases[alias];
|
|
258
271
|
}
|
|
259
|
-
if (!
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
if (config.aliases && !Object.keys(config.aliases).length)
|
|
273
|
+
delete config.aliases;
|
|
274
|
+
}
|
|
275
|
+
function assertProviderDomainUnchanged(previous, next) {
|
|
276
|
+
let previousDomain;
|
|
277
|
+
try {
|
|
278
|
+
previousDomain = providerIdentity(previous).domain;
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
const code = error?.code;
|
|
282
|
+
if (previous.domain === undefined && (code === 'PROVIDER_DOMAIN_REQUIRED' || code === 'PROVIDER_DOMAIN_INVALID')) {
|
|
283
|
+
if (previous.common.baseUrl === next.common.baseUrl) {
|
|
284
|
+
if (next.domain !== undefined)
|
|
285
|
+
next.domain = providerIdentity(next).domain;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
const identity = providerIdentity(next);
|
|
292
|
+
if (identity.domain !== previousDomain) {
|
|
293
|
+
throw Object.assign(new Error('Provider domain is immutable; create a different Provider'), { code: 'PROVIDER_DOMAIN_IMMUTABLE' });
|
|
294
|
+
}
|
|
295
|
+
next.domain = identity.domain;
|
|
296
|
+
}
|
|
297
|
+
function existingProviderDomain(provider) {
|
|
298
|
+
try {
|
|
299
|
+
return providerIdentity(provider).domain;
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function availableProviderId(config, provider) {
|
|
306
|
+
const identity = providerIdentity(provider);
|
|
307
|
+
provider.domain = identity.domain;
|
|
308
|
+
for (const [existingId, existing] of Object.entries(config.providers)) {
|
|
309
|
+
const domain = existingProviderDomain(existing);
|
|
310
|
+
if (existingId === identity.providerId && domain !== identity.domain) {
|
|
311
|
+
throw Object.assign(new Error('Provider ID hash collision; no ID was reassigned'), {
|
|
312
|
+
code: 'PROVIDER_ID_COLLISION', statusCode: 409, data: { kind: 'provider_id_collision', providerId: identity.providerId, domain: identity.domain, existingDomain: domain },
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
if (domain === identity.domain) {
|
|
316
|
+
throw Object.assign(new Error('Provider domain already exists; update or explicitly merge it'), {
|
|
317
|
+
code: 'PROVIDER_CONFLICT', statusCode: 409, data: { kind: 'provider_domain_exists', providerId: existingId, domain },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (Object.hasOwn(config.aliases ?? {}, identity.providerId)) {
|
|
322
|
+
throw Object.assign(new Error('Provider ID conflicts with a legacy alias'), { code: 'PROVIDER_ID_COLLISION', statusCode: 409 });
|
|
323
|
+
}
|
|
324
|
+
return identity.providerId;
|
|
262
325
|
}
|
|
263
326
|
export async function createProvider(input, file = resolvePaths().providersConfig) {
|
|
264
327
|
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
@@ -274,10 +337,14 @@ export async function createProvider(input, file = resolvePaths().providersConfi
|
|
|
274
337
|
if (providersRevision(current) !== input.revision) {
|
|
275
338
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
276
339
|
}
|
|
277
|
-
const
|
|
278
|
-
|
|
340
|
+
const identity = providerIdentity(provider);
|
|
341
|
+
provider.domain = identity.domain;
|
|
342
|
+
const existing = current.providers[identity.providerId];
|
|
343
|
+
if (existing && isDeepStrictEqual(existing, provider))
|
|
344
|
+
return { current, providerId: identity.providerId };
|
|
345
|
+
const providerId = availableProviderId(current, provider);
|
|
279
346
|
current.providers[providerId] = provider;
|
|
280
|
-
current.nextId
|
|
347
|
+
delete current.nextId;
|
|
281
348
|
return { current, providerId };
|
|
282
349
|
});
|
|
283
350
|
return { ...providersSnapshot(result.value.current), providerId: result.value.providerId };
|
|
@@ -335,14 +402,16 @@ function resolveDraftProvider(value, previous, imports = []) {
|
|
|
335
402
|
for (const item of imports) {
|
|
336
403
|
const imported = validateProvidersFile({ providers: { imported: item } }).providers.imported;
|
|
337
404
|
rejectMaskedImportSecrets({ imported });
|
|
338
|
-
|
|
339
|
-
const importedHost = providerHostname(imported.common.baseUrl);
|
|
340
|
-
if (secretSource && secretSourceHost && importedHost && secretSourceHost !== importedHost) {
|
|
405
|
+
if (secretSource && providerIdentity(secretSource).domain !== providerIdentity(imported).domain) {
|
|
341
406
|
throw new Error('Imported Provider domain does not match the target Provider');
|
|
342
407
|
}
|
|
343
408
|
secretSource = secretSource ? mergeImportedProvider(secretSource, imported) : imported;
|
|
344
409
|
}
|
|
345
|
-
|
|
410
|
+
const provider = validateProvidersFile({ providers: { draft: retainSecrets(value, secretSource) } }).providers.draft;
|
|
411
|
+
if (imports.length && secretSource && providerIdentity(provider).domain !== providerIdentity(secretSource).domain) {
|
|
412
|
+
throw new Error('Imported Provider domain does not match the draft Provider');
|
|
413
|
+
}
|
|
414
|
+
return provider;
|
|
346
415
|
}
|
|
347
416
|
export async function saveProviderChanges(input, file = resolvePaths().providersConfig) {
|
|
348
417
|
if (!Array.isArray(input.changes) || !input.changes.length)
|
|
@@ -368,25 +437,31 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
368
437
|
}
|
|
369
438
|
const providerIds = {};
|
|
370
439
|
const originalIds = new Set(Object.keys(current.providers));
|
|
371
|
-
|
|
372
|
-
current.nextId = nextProviderSequence(current);
|
|
440
|
+
const resolvedIds = new Set();
|
|
373
441
|
for (const change of input.changes) {
|
|
374
|
-
|
|
442
|
+
const targetId = change.create ? change.providerId : resolveProviderId(change.providerId, current);
|
|
443
|
+
if (resolvedIds.has(targetId))
|
|
444
|
+
throw new Error('Duplicate provider change');
|
|
445
|
+
resolvedIds.add(targetId);
|
|
446
|
+
if (change.create ? originalIds.has(targetId) : !originalIds.has(targetId)) {
|
|
375
447
|
throw new Error(change.create ? 'Provider already exists' : 'Provider not found');
|
|
376
448
|
}
|
|
377
449
|
if (change.remove) {
|
|
378
|
-
assertProviderUnreferenced(
|
|
379
|
-
delete current.providers[
|
|
450
|
+
assertProviderUnreferenced(targetId, file);
|
|
451
|
+
delete current.providers[targetId];
|
|
452
|
+
removeProviderAliases(current, targetId);
|
|
380
453
|
continue;
|
|
381
454
|
}
|
|
382
|
-
const previous = change.create ? undefined : current.providers[
|
|
455
|
+
const previous = change.create ? undefined : current.providers[targetId];
|
|
383
456
|
const provider = resolveDraftProvider(change.value, previous, change.imports);
|
|
457
|
+
if (previous)
|
|
458
|
+
assertProviderDomainUnchanged(previous, provider);
|
|
384
459
|
provider.name ||= providerNameFromBaseUrlIfStatic(provider.common.baseUrl);
|
|
385
460
|
if (provider.name !== undefined)
|
|
386
461
|
provider.name = validateProviderName(provider.name);
|
|
387
|
-
const providerId = change.create ?
|
|
462
|
+
const providerId = change.create ? availableProviderId(current, provider) : targetId;
|
|
388
463
|
if (change.create)
|
|
389
|
-
current.nextId
|
|
464
|
+
delete current.nextId;
|
|
390
465
|
current.providers[providerId] = provider;
|
|
391
466
|
providerIds[change.providerId] = providerId;
|
|
392
467
|
}
|
|
@@ -394,9 +469,7 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
394
469
|
});
|
|
395
470
|
return { ...providersSnapshot(result.value.current), providerIds: result.value.providerIds };
|
|
396
471
|
}
|
|
397
|
-
export
|
|
398
|
-
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
399
|
-
throw new Error('A valid providers revision is required');
|
|
472
|
+
export function importBaseagentProviderIntoRegistry(current, input) {
|
|
400
473
|
const normalized = validateProvidersFile({ providers: { imported: input.value } });
|
|
401
474
|
rejectMaskedImportSecrets(normalized.providers);
|
|
402
475
|
const imported = normalized.providers.imported;
|
|
@@ -405,33 +478,36 @@ export async function importOrMergeBaseagentProvider(input, file = resolvePaths(
|
|
|
405
478
|
imported.name = validateProviderName(input.name);
|
|
406
479
|
if (input.resolution === 'cancel')
|
|
407
480
|
throw Object.assign(new Error('Provider import cancelled'), { code: 'CANCELLED', statusCode: 409 });
|
|
481
|
+
const identity = providerIdentity(imported);
|
|
482
|
+
imported.domain = identity.domain;
|
|
483
|
+
const match = Object.entries(current.providers).find(([, provider]) => existingProviderDomain(provider) === identity.domain);
|
|
484
|
+
if (match && input.requireResolution && input.resolution === undefined) {
|
|
485
|
+
const [providerId, existing] = match;
|
|
486
|
+
throw Object.assign(new Error('Provider conflict requires an explicit resolution'), {
|
|
487
|
+
code: 'PROVIDER_CONFLICT', statusCode: 409,
|
|
488
|
+
data: { kind: 'provider_conflict', providerId, overlaps: Object.keys(imported.services || {}).filter(type => Object.hasOwn(existing.services || {}, type)) },
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (match && input.resolution !== 'create') {
|
|
492
|
+
const [providerId, existing] = match;
|
|
493
|
+
const replaceServiceTypes = new Set(Object.entries(input.serviceDecisions || {}).filter(([, decision]) => decision === 'imported').map(([type]) => type));
|
|
494
|
+
current.providers[providerId] = validateProvidersFile({ providers: { [providerId]: mergeImportedProvider(existing, imported, replaceServiceTypes) } }).providers[providerId];
|
|
495
|
+
return { current, providerId, merged: true };
|
|
496
|
+
}
|
|
497
|
+
const providerId = availableProviderId(current, imported);
|
|
498
|
+
current.providers[providerId] = imported;
|
|
499
|
+
delete current.nextId;
|
|
500
|
+
return { current, providerId, merged: false };
|
|
501
|
+
}
|
|
502
|
+
export async function importOrMergeBaseagentProvider(input, file = resolvePaths().providersConfig) {
|
|
503
|
+
if (!/^[a-f0-9]{64}$/u.test(input.revision))
|
|
504
|
+
throw new Error('A valid providers revision is required');
|
|
408
505
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
409
506
|
const current = config;
|
|
410
507
|
if (providersRevision(current) !== input.revision) {
|
|
411
508
|
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
412
509
|
}
|
|
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 };
|
|
510
|
+
return importBaseagentProviderIntoRegistry(current, input);
|
|
435
511
|
});
|
|
436
512
|
return { ...providersSnapshot(result.value.current), providerId: result.value.providerId, merged: result.value.merged };
|
|
437
513
|
}
|
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
|
}
|
|
@@ -2,15 +2,17 @@ import crypto from 'crypto';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { resolvePaths } from '../paths.js';
|
|
5
|
-
import { ConfigError } from './config-manager.js';
|
|
5
|
+
import { acquireConfigMutationLock, ConfigError } from './config-manager.js';
|
|
6
6
|
import { firstConfiguredOwner } from './owner-config.js';
|
|
7
7
|
import { resolveLegacyBaseagentModelSelection } from '../agents/baseagent.js';
|
|
8
8
|
import { loadSchema } from './schema-registry.js';
|
|
9
|
+
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
9
10
|
const MIGRATION_KIND = {
|
|
10
11
|
'auxiliary-model-v1': 'auxiliary-model',
|
|
11
12
|
'agent-only-model-v1': 'agent-only-model',
|
|
12
13
|
'agent-model-provider-v1': 'agent-only-model',
|
|
13
14
|
'provider-service-type-v1': 'provider-service-type',
|
|
15
|
+
'provider-domain-id-v1': 'provider-domain-id',
|
|
14
16
|
'relation-config-v11-v1': 'agent-only-model',
|
|
15
17
|
'published-schema-consolidation-v1': 'agent-only-model',
|
|
16
18
|
'legacy-model-selection-v1': 'agent-only-model',
|
|
@@ -1213,11 +1215,14 @@ function planAgentModelProviderMigration(home) {
|
|
|
1213
1215
|
}
|
|
1214
1216
|
const providersFile = path.join(home, 'providers.json');
|
|
1215
1217
|
let providers = {};
|
|
1218
|
+
let providerRegistry = {};
|
|
1216
1219
|
if (fs.existsSync(providersFile)) {
|
|
1217
1220
|
try {
|
|
1218
1221
|
const raw = readJson(providersFile).value;
|
|
1219
|
-
if (isRecord(raw) && isRecord(raw.providers))
|
|
1222
|
+
if (isRecord(raw) && isRecord(raw.providers)) {
|
|
1223
|
+
providerRegistry = raw;
|
|
1220
1224
|
providers = { ...raw.providers };
|
|
1225
|
+
}
|
|
1221
1226
|
}
|
|
1222
1227
|
catch {
|
|
1223
1228
|
providers = {};
|
|
@@ -1313,7 +1318,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1313
1318
|
summary.filesChanged += 1;
|
|
1314
1319
|
}
|
|
1315
1320
|
if (Object.keys(providers).length > 0) {
|
|
1316
|
-
const nextText = jsonText({ $schema_version: 1, providers });
|
|
1321
|
+
const nextText = jsonText({ $schema_version: 1, ...providerRegistry, providers });
|
|
1317
1322
|
if (nextText !== providersBefore) {
|
|
1318
1323
|
changes.push({ file: providersFile, kind: 'agent-only-model', before: providersBefore, after: nextText });
|
|
1319
1324
|
details.push({ file: 'providers.json', removed: [] });
|
|
@@ -1415,6 +1420,65 @@ function planProviderServiceTypeMigration(home) {
|
|
|
1415
1420
|
}
|
|
1416
1421
|
return { home, changes, summary, details };
|
|
1417
1422
|
}
|
|
1423
|
+
export function runProviderIdentitySchemaMigration(options = {}) {
|
|
1424
|
+
const id = 'provider-domain-id-v1';
|
|
1425
|
+
const home = path.resolve(options.home || resolvePaths().root);
|
|
1426
|
+
const release = acquireLock(home, id);
|
|
1427
|
+
try {
|
|
1428
|
+
assertDaemonStopped(home);
|
|
1429
|
+
recoverJournal(home, id);
|
|
1430
|
+
const plan = planProviderIdentityMigration(home);
|
|
1431
|
+
const backup = options.apply ? applyMigration(plan, id) : null;
|
|
1432
|
+
return { ok: true, mode: options.apply ? 'applied' : 'dry-run',
|
|
1433
|
+
home, changedFiles: plan.changes.length, backup, summary: plan.summary, pending: plan.pending };
|
|
1434
|
+
}
|
|
1435
|
+
finally {
|
|
1436
|
+
release();
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
export async function ensureProviderIdentityMigrationOnStartup() {
|
|
1440
|
+
try {
|
|
1441
|
+
const result = runProviderIdentitySchemaMigration({ apply: true });
|
|
1442
|
+
return result.changedFiles === 0 && result.pending.length === 0 ? null : result;
|
|
1443
|
+
}
|
|
1444
|
+
catch (error) {
|
|
1445
|
+
throw new ConfigError('PROVIDER_IDENTITY_MIGRATION_FAILED', 'Automatic Provider identity migration failed; resolve conflicting domains or connection settings before restarting', { cause: error });
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
export function commitProviderSyncMigration(plan) {
|
|
1449
|
+
const id = 'provider-domain-id-v1';
|
|
1450
|
+
const releaseMigration = acquireLock(plan.home, id);
|
|
1451
|
+
const releases = [];
|
|
1452
|
+
try {
|
|
1453
|
+
if (fs.existsSync(journalPath(plan.home, id))) {
|
|
1454
|
+
throw Object.assign(new Error('An unfinished Provider migration requires startup recovery'), { code: 'CONFLICT' });
|
|
1455
|
+
}
|
|
1456
|
+
const expected = new Map(plan.expected.map(item => [item.file, item.before]));
|
|
1457
|
+
for (const item of plan.changes)
|
|
1458
|
+
expected.set(item.file, item.before);
|
|
1459
|
+
const home = path.resolve(plan.home);
|
|
1460
|
+
for (const file of [...expected.keys()].sort()) {
|
|
1461
|
+
const relative = path.relative(home, file);
|
|
1462
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative))
|
|
1463
|
+
throw new Error('Unsafe Provider sync path');
|
|
1464
|
+
for (let current = path.resolve(file); current !== home; current = path.dirname(current)) {
|
|
1465
|
+
if (fs.existsSync(current) && fs.lstatSync(current).isSymbolicLink())
|
|
1466
|
+
throw new Error('Provider sync does not follow symlinks');
|
|
1467
|
+
}
|
|
1468
|
+
releases.push(acquireConfigMutationLock(file));
|
|
1469
|
+
const actual = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
|
|
1470
|
+
if (actual !== expected.get(file)) {
|
|
1471
|
+
throw Object.assign(new Error('Configuration changed during Provider sync; retry after reviewing the current configuration'), { code: 'CONFLICT' });
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
return applyMigration(plan, id);
|
|
1475
|
+
}
|
|
1476
|
+
finally {
|
|
1477
|
+
for (const release of releases.reverse())
|
|
1478
|
+
release();
|
|
1479
|
+
releaseMigration();
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1418
1482
|
export function runProviderServiceTypeSchemaMigration(options = {}) {
|
|
1419
1483
|
const id = 'provider-service-type-v1';
|
|
1420
1484
|
const home = path.resolve(options.home || resolvePaths().root);
|
|
@@ -588,7 +588,7 @@ async function withInitializationClient(aid, action) {
|
|
|
588
588
|
// An entered bind can have remote effects. Its adapter may only mark an
|
|
589
589
|
// audited read-only preflight as not started; all other failures stay unknown.
|
|
590
590
|
actionStarted = true;
|
|
591
|
-
return await action(client);
|
|
591
|
+
return await action(client, store);
|
|
592
592
|
}
|
|
593
593
|
catch (error) {
|
|
594
594
|
if (!actionStarted) {
|
|
@@ -614,7 +614,9 @@ async function withInitializationClient(aid, action) {
|
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
616
|
export async function bindInitializationOwner(aid, ownerAid) {
|
|
617
|
-
return withInitializationClient(aid, async (client) => {
|
|
617
|
+
return withInitializationClient(aid, async (client, store) => {
|
|
618
|
+
const { assertHumanAgentOwner } = await import('../aun/aid/agentmd.js');
|
|
619
|
+
await assertHumanAgentOwner(ownerAid, { store });
|
|
618
620
|
try {
|
|
619
621
|
return await client.bindOwneraid(ownerAid);
|
|
620
622
|
}
|
|
@@ -8,7 +8,7 @@ import { ownerResolver, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AG
|
|
|
8
8
|
import { getOperationMeta } from './operation-catalog.js';
|
|
9
9
|
import { constrainRuntimePermissionMode, resolveRuntimePermissionMode } from '../role/runtime-policy.js';
|
|
10
10
|
import { buildAuthorizationEventKey } from '../audit/event-key.js';
|
|
11
|
-
import {
|
|
11
|
+
import { prepareSameOwnerProof, sameOwnerQualification, requiresSameOwnerProof } from '../relation/same-owner-proof.js';
|
|
12
12
|
export function isCrossAgentTriggerOperationAllowed(input) {
|
|
13
13
|
return input.control || input.daemonOwner === true || input.taskAgentAid === input.targetAgentAid;
|
|
14
14
|
}
|
|
@@ -44,7 +44,7 @@ export function buildAuthSubject(input) {
|
|
|
44
44
|
}));
|
|
45
45
|
const internalContactContext = roleDetail.source === 'internal-contact-default'
|
|
46
46
|
|| (input.channelType === 'aun' && chatType === 'private' && input.selfAid && actorId
|
|
47
|
-
&& (
|
|
47
|
+
&& (sameOwnerQualification(input.selfAid, actorId) === 'matched' || requiresSameOwnerProof(input.selfAid, actorId)));
|
|
48
48
|
const suppliedRole = !internalContactContext && input.identity?.role && input.identity.role !== 'none' ? input.identity.role : undefined;
|
|
49
49
|
const role = suppliedRole ?? roleDetail.effectiveRole ?? 'none';
|
|
50
50
|
const processRole = isFullAccessRun
|
|
@@ -122,7 +122,7 @@ export async function authorizeFreshOperation(params) {
|
|
|
122
122
|
|| configCommand?.dangerous || subject.processRole === 'fullaccess-run';
|
|
123
123
|
try {
|
|
124
124
|
if (subject.channelType === 'aun' && subject.chatType === 'private') {
|
|
125
|
-
await
|
|
125
|
+
await prepareSameOwnerProof(subject.selfAid, subject.actorId);
|
|
126
126
|
}
|
|
127
127
|
await refreshOwnershipForAuthorization(subject.selfAid, {
|
|
128
128
|
force: force || forceAgentMdEditor,
|
|
@@ -153,6 +153,8 @@ export async function authorizeFreshOperation(params) {
|
|
|
153
153
|
chatType: subject.chatType, conversationId: subject.conversationId,
|
|
154
154
|
fromControlChannel: subject.fromControlChannel,
|
|
155
155
|
identity: subject.roleSource === 'internal-contact-default' || (subject.role === 'owner' && subject.principalId)
|
|
156
|
+
|| (subject.channelType === 'aun' && subject.principalId
|
|
157
|
+
&& ownerResolver.owner(subject.selfAid) === subject.principalId)
|
|
156
158
|
? undefined : subject.identity,
|
|
157
159
|
});
|
|
158
160
|
if (subject.processRole === 'fullaccess-run') {
|