evolcore 0.0.47 → 0.0.48
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 +56 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +139 -39
- package/dist/agent-template/service.js +66 -13
- package/dist/agents/baseagent.js +60 -20
- package/dist/agents/claude-runner.js +34 -17
- package/dist/agents/codex-runner.js +31 -16
- package/dist/agents/ecagent-runner.js +7 -4
- package/dist/agents/gemini-runner.js +5 -2
- package/dist/agents/runner-types.js +5 -21
- package/dist/aun/aid/agentmd.js +5 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +81 -24
- package/dist/channels/daemon.js +9 -25
- package/dist/cli/aun-commands.js +86 -51
- package/dist/cli/code-stats.js +19 -8
- package/dist/cli/command-log.js +1 -1
- package/dist/cli/daemon-commands.js +44 -43
- package/dist/cli/directory.js +7 -1
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +2 -8
- package/dist/cli/init-channel.js +4 -6
- package/dist/cli/init.js +72 -50
- package/dist/cli/invoke-command.js +1 -1
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/role.js +61 -17
- package/dist/cli/stats.js +3 -3
- package/dist/cli/thread-command.js +16 -51
- package/dist/config/boot-log.js +3 -9
- package/dist/config/builtin-roles.js +5 -7
- package/dist/config/config-manager.js +2 -6
- package/dist/config/daemon-services.js +30 -3
- package/dist/config/gateway-config.js +2 -2
- package/dist/config/invoke-ipc-service.js +6 -4
- package/dist/config/peer-bind-code.js +3 -4
- package/dist/config/peer-book-store.js +62 -229
- package/dist/config/peer-book.js +26 -27
- package/dist/config/peer-role-resolver.js +16 -1
- package/dist/config/provider-identity-migration.js +4 -1
- package/dist/config/provider-ipc-service.js +56 -11
- package/dist/config/provider-menu-request.js +24 -5
- package/dist/config/provider-templates.js +127 -0
- package/dist/config/providers-config.js +59 -8
- package/dist/config/providers-management.js +467 -49
- package/dist/config/role-command-service.js +248 -1
- package/dist/config/schema-migration.js +105 -4
- package/dist/core/agent-application-service.js +6 -1
- package/dist/core/agent-runtime.js +4 -0
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +2 -1
- package/dist/core/auth/delegation-authorization.js +3 -0
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +28 -64
- package/dist/core/capability/providers/codex-capability-provider.js +7 -8
- package/dist/core/channel-loader.js +18 -0
- package/dist/core/command/agent-control.js +32 -0
- package/dist/core/command/command-handler.js +81 -85
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +61 -149
- package/dist/core/command/menu-protocol.js +7 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/role-menu.js +47 -23
- package/dist/core/command/slash-handler.js +26 -43
- package/dist/core/command/team-workspace-items.js +81 -12
- package/dist/core/command/team-workspace-team.js +9 -71
- package/dist/core/command/topic-slash.js +9 -30
- package/dist/core/daemon-bootstrap.js +8 -1
- package/dist/core/daemon-control.js +7 -7
- package/dist/core/evolagent-registry.js +14 -1
- package/dist/core/file-integrity/store.js +2 -0
- package/dist/core/handoff/runtime.js +37 -1
- package/dist/core/inference/text-inference.js +3 -1
- package/dist/core/initialization/service.js +11 -6
- package/dist/core/interaction-router.js +3 -0
- package/dist/core/invoke/executors/text.js +72 -19
- package/dist/core/ipc-registration.js +2 -1
- package/dist/core/message/aun-ipc-sender.js +165 -55
- package/dist/core/message/im-renderer.js +1 -1
- package/dist/core/message/message-bridge.js +51 -334
- package/dist/core/message/message-log.js +5 -0
- package/dist/core/message/message-queue.js +22 -0
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +429 -116
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/ownership/owner-resolver.js +328 -50
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/relation/peer-identity.js +23 -1
- package/dist/core/relation/same-owner-proof.js +81 -112
- package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
- package/dist/core/session/session-file-health.js +13 -7
- package/dist/core/session/session-fs-store.js +91 -35
- package/dist/core/session/session-manager.js +68 -24
- package/dist/core/session/session-mapper.js +14 -34
- package/dist/core/session/session-transcript.js +5 -1
- package/dist/core/task/task-activity-store.js +84 -0
- package/dist/core/task/task-recovery-service.js +12 -0
- package/dist/core/thread/command-parser.js +7 -12
- package/dist/core/thread/thread-context-storage.js +3 -2
- package/dist/core/thread/thread-operation.js +2 -13
- package/dist/core/thread/thread-service.js +15 -46
- package/dist/directory/owner-directory-admission.js +1 -1
- package/dist/directory/owner-directory-cache.js +45 -28
- package/dist/directory/owner-directory-markdown.js +13 -1
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/eck/message-renderer.js +84 -24
- package/dist/ecweb/basic-settings-service.js +3 -1
- package/dist/ecweb/message-context-service.js +1 -1
- package/dist/ecweb/pairing.js +4 -3
- package/dist/ecweb/providers-service.js +26 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -8
- package/dist/ecweb/runtime/proxy-access.js +74 -0
- package/dist/ecweb/runtime/supervisor.js +4 -2
- package/dist/event-center/registry.js +13 -2
- package/dist/event-center/runtime.js +103 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +92 -59
- package/dist/ipc.js +13 -2
- package/dist/outputs/events.js +62 -0
- package/dist/outputs/protocol.js +102 -0
- package/dist/outputs/service.js +279 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +89 -4
- package/dist/services/ipc-operation.js +4 -15
- package/dist/services/pack-manager.js +12 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/role-budget.js +5 -2
- package/dist/stats/writer.js +10 -6
- package/dist/trigger/audit.js +7 -0
- package/dist/trigger/authorization.js +105 -11
- package/dist/trigger/feedback.js +10 -0
- package/dist/trigger/history.js +37 -11
- package/dist/trigger/ipc-service.js +12 -1
- package/dist/trigger/manager.js +1 -0
- package/dist/trigger/scheduler.js +7 -5
- package/dist/trigger/script-executor.js +2 -1
- package/dist/trigger/script-sandbox.js +9 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/cross-platform.js +73 -26
- package/dist/utils/error-dict.json +94 -4
- package/dist/utils/error-utils.js +27 -4
- package/dist/utils/evolcore-version.js +36 -65
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/process-introspect.js +12 -7
- package/dist/utils/process-tree.js +50 -2
- package/dist/utils/windows-shell-trust.js +2 -0
- package/dist/workbench/protocol.js +80 -0
- package/dist/workbench/service.js +359 -0
- package/ecagent/dist/types.d.ts +6 -2
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -2
- package/kits/docs/evolcore/config.md +12 -0
- package/kits/docs/evolcore/directory.md +22 -3
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +123 -3
- package/kits/docs/evolcore/role.md +80 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/team-workspace.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +14 -15
- package/kits/docs/evolcore/tool-authorization.md +5 -0
- package/kits/docs/evolcore/trigger.md +10 -0
- package/kits/eck_message_manifest.json +12 -0
- package/kits/provider-templates.json +1213 -0
- package/kits/rules/04-relation.md +3 -3
- package/kits/schemas/_meta.json +14 -2
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/ec-group/SKILL.md +2 -2
- package/kits/skills/ec-identity/SKILL.md +19 -72
- package/kits/skills/ec-provider/SKILL.md +221 -0
- package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +34 -21
- package/kits/templates/message-fragments/group-batch-item.md +1 -1
- package/kits/templates/message-fragments/group-batch.md +1 -1
- package/kits/templates/message-fragments/inject-default.md +1 -1
- package/kits/templates/message-fragments/interrupt-insert.md +1 -0
- package/kits/templates/message-fragments/item-group.md +1 -1
- package/kits/templates/message-fragments/item-private.md +1 -1
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/message-fragments/trigger-session.md +1 -1
- package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
- package/kits/templates/roles/admin.json +2 -19
- package/kits/templates/roles/member.json +0 -3
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +3 -3
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +1 -1
- package/kits/templates/system-fragments/thread.md +6 -5
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +4 -1
- package/scripts/agent-template/shared/common.mjs +2 -3
- package/scripts/agent-template/shared/template-contract.mjs +2 -1
- package/scripts/agent-template/shared/template-package.mjs +9 -2
- package/scripts/agent-template/shared/template-runtime.mjs +20 -5
- package/scripts/agent-template/team-pack.mjs +6 -3
- package/dist/cli/peer.js +0 -127
- package/dist/config/peer-operation-service.js +0 -132
- package/dist/config/peer-request-service.js +0 -532
- package/dist/core/command/connect-menu.js +0 -624
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseDocument } from 'yaml';
|
|
4
|
+
export const OUTPUT_EVENT = 'team.outputs.changed';
|
|
5
|
+
export const OUTPUT_TYPES = ['snapshot', 'list', 'detail', 'changes'].map(action => `services.outputs.${action}`);
|
|
6
|
+
export const isOutputType = (type) => OUTPUT_TYPES.includes(type);
|
|
7
|
+
export const outputId = (relative) => crypto.createHash('sha256').update(relative).digest('hex').slice(0, 32);
|
|
8
|
+
export const outputVersion = (value) => crypto.createHash('sha256').update(value).digest('hex').slice(0, 24);
|
|
9
|
+
export function outputRequestSchema(type) {
|
|
10
|
+
const action = type.split('.').at(-1);
|
|
11
|
+
const properties = { protocolVersion: { const: 1 } };
|
|
12
|
+
const required = ['protocolVersion'];
|
|
13
|
+
if (action === 'snapshot')
|
|
14
|
+
Object.assign(properties, { knownRevision: { type: 'string', maxLength: 128 }, waitForIndex: { type: 'boolean' }, limit: { type: 'integer', minimum: 1, maximum: 20 } });
|
|
15
|
+
if (action === 'list')
|
|
16
|
+
Object.assign(properties, { kind: { enum: ['document', 'image', 'media', 'archive', 'file'] }, pageCursor: { type: 'string', maxLength: 512 }, limit: { type: 'integer', minimum: 1, maximum: 20 } });
|
|
17
|
+
if (action === 'detail') {
|
|
18
|
+
properties.id = { type: 'string', pattern: '^[a-f0-9]{32}$' };
|
|
19
|
+
required.push('id');
|
|
20
|
+
}
|
|
21
|
+
if (action === 'changes') {
|
|
22
|
+
properties.cursor = { type: 'string', maxLength: 128 };
|
|
23
|
+
required.push('cursor');
|
|
24
|
+
}
|
|
25
|
+
return { type: 'object', additionalProperties: false, required: ['type', 'request_id', 'data'], properties: {
|
|
26
|
+
type: { const: type }, request_id: { type: 'string', minLength: 1, maxLength: 128 },
|
|
27
|
+
data: { type: 'object', additionalProperties: false, required, properties },
|
|
28
|
+
} };
|
|
29
|
+
}
|
|
30
|
+
/** Schema for the data field of every successful outputs.*.result. */
|
|
31
|
+
export function outputResponseSchema() {
|
|
32
|
+
const hex = (length) => ({ type: 'string', pattern: `^[a-f0-9]{${length}}$` });
|
|
33
|
+
return {
|
|
34
|
+
type: 'object', additionalProperties: false,
|
|
35
|
+
required: ['protocol', 'protocolVersion', 'sourceAid', 'space', 'revision', 'cursor', 'generatedAt',
|
|
36
|
+
'coverage', 'indexState', 'truncated', 'notifications', 'items', 'nextCursor'],
|
|
37
|
+
properties: {
|
|
38
|
+
protocol: { const: 'evol.outputs' }, protocolVersion: { const: 1 },
|
|
39
|
+
sourceAid: { type: 'string', minLength: 3, maxLength: 256 }, space: { const: 'agent-output' },
|
|
40
|
+
revision: hex(24), cursor: { type: 'string', pattern: '^[a-f0-9]{24}\\.\\d+$', maxLength: 128 },
|
|
41
|
+
generatedAt: { type: 'integer', minimum: 0 }, coverage: { enum: ['complete', 'partial'] },
|
|
42
|
+
indexState: { enum: ['ready', 'building'] }, truncated: { type: 'boolean' },
|
|
43
|
+
notifications: { anyOf: [{ type: 'null' }, { type: 'object', additionalProperties: false,
|
|
44
|
+
required: ['busAid', 'event'], properties: {
|
|
45
|
+
busAid: { type: 'string' }, event: { const: OUTPUT_EVENT },
|
|
46
|
+
} }] },
|
|
47
|
+
items: { type: 'array', maxItems: 20, items: { type: 'object', additionalProperties: false,
|
|
48
|
+
required: ['id', 'version', 'title', 'kind', 'modifiedAt', 'size', 'summary', 'openRef'], properties: {
|
|
49
|
+
id: hex(32), version: hex(24), title: { type: 'string', maxLength: 256 },
|
|
50
|
+
kind: { enum: ['document', 'image', 'media', 'archive', 'file'] },
|
|
51
|
+
modifiedAt: { type: 'integer', minimum: 0 }, size: { type: 'integer', minimum: 0 },
|
|
52
|
+
summary: { type: 'string', maxLength: 1024 },
|
|
53
|
+
openRef: { type: 'object', additionalProperties: false, required: ['path'], properties: {
|
|
54
|
+
path: { type: 'string', maxLength: 2048, pattern: '^output/[^\\\\:\\u0000-\\u001f\\u007f]+$' },
|
|
55
|
+
} },
|
|
56
|
+
} } },
|
|
57
|
+
nextCursor: { anyOf: [{ type: 'null' }, { type: 'string', maxLength: 512 }] },
|
|
58
|
+
reset: { type: 'boolean' }, notModified: { type: 'boolean' },
|
|
59
|
+
deletes: { type: 'array', maxItems: 100, uniqueItems: true, items: hex(32) },
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function outputKind(relative) {
|
|
64
|
+
const ext = path.posix.extname(relative).toLowerCase();
|
|
65
|
+
if (['.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.heic'].includes(ext))
|
|
66
|
+
return 'image';
|
|
67
|
+
if (['.mp4', '.webm', '.mov', '.mp3', '.wav', '.m4a', '.ogg'].includes(ext))
|
|
68
|
+
return 'media';
|
|
69
|
+
if (['.zip', '.7z', '.tar', '.gz'].includes(ext))
|
|
70
|
+
return 'archive';
|
|
71
|
+
if (['.md', '.markdown', '.txt', '.pdf', '.html', '.docx', '.xlsx', '.csv', '.json'].includes(ext))
|
|
72
|
+
return 'document';
|
|
73
|
+
return 'file';
|
|
74
|
+
}
|
|
75
|
+
export function outputItem(item, signature) {
|
|
76
|
+
let title = item.name;
|
|
77
|
+
let summary = '';
|
|
78
|
+
const source = item.previewSource ?? '';
|
|
79
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/.exec(source);
|
|
80
|
+
if (match) {
|
|
81
|
+
try {
|
|
82
|
+
const doc = parseDocument(match[1], { uniqueKeys: true });
|
|
83
|
+
const fields = doc.toJS({ maxAliasCount: 0 });
|
|
84
|
+
if (!doc.errors.length && fields && typeof fields === 'object') {
|
|
85
|
+
if (typeof fields.title === 'string')
|
|
86
|
+
title = fields.title.slice(0, 200);
|
|
87
|
+
if (typeof fields.summary === 'string')
|
|
88
|
+
summary = fields.summary.slice(0, 768);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch { /* legacy documents still have a bounded body */ }
|
|
92
|
+
if (title === item.name)
|
|
93
|
+
title = /^#\s+(.+)$/m.exec(match[2])?.[1]?.slice(0, 200) ?? title;
|
|
94
|
+
if (!summary)
|
|
95
|
+
summary = match[2].replace(/^#+\s+.*/m, '').replace(/[`*_>#]/g, '').trim().slice(0, 768);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
id: outputId(item.path), version: outputVersion(signature),
|
|
99
|
+
title, kind: outputKind(item.path), modifiedAt: item.mtime, size: item.size, summary,
|
|
100
|
+
openRef: { path: item.path },
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { agentOutputDir } from '../paths.js';
|
|
5
|
+
import { TeamWorkspaceStore, DataRootError } from '../core/command/team-workspace-store.js';
|
|
6
|
+
import { TeamWorkspaceItemsIndex } from '../core/command/team-workspace-items.js';
|
|
7
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
8
|
+
import { isOutputType, outputId, outputItem, outputKind, OUTPUT_EVENT } from './protocol.js';
|
|
9
|
+
let outputChangePublisher;
|
|
10
|
+
let outputNotificationsAvailable = () => false;
|
|
11
|
+
export function hasOutputNotifications(aid) { return outputNotificationsAvailable(aid); }
|
|
12
|
+
export function setOutputChangePublisher(publisher, available = () => false) {
|
|
13
|
+
outputChangePublisher = publisher;
|
|
14
|
+
outputNotificationsAvailable = available;
|
|
15
|
+
}
|
|
16
|
+
/** An ephemeral adapter: no Team binding, initialization or navigation writes. */
|
|
17
|
+
class OutputStore extends TeamWorkspaceStore {
|
|
18
|
+
resolveRoot;
|
|
19
|
+
constructor(resolveRoot) {
|
|
20
|
+
super();
|
|
21
|
+
this.resolveRoot = resolveRoot;
|
|
22
|
+
}
|
|
23
|
+
require(aid) {
|
|
24
|
+
const root = this.resolveRoot(aid);
|
|
25
|
+
const workspaceRoot = path.dirname(root);
|
|
26
|
+
let real;
|
|
27
|
+
try {
|
|
28
|
+
real = fs.realpathSync(root);
|
|
29
|
+
if (!fs.statSync(real).isDirectory())
|
|
30
|
+
throw new Error();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Agent output directory is unavailable');
|
|
34
|
+
}
|
|
35
|
+
// The fixed directory itself cannot redirect into another Agent or host path.
|
|
36
|
+
const canonical = (value) => process.platform === 'win32' ? path.resolve(value).toLowerCase() : path.resolve(value);
|
|
37
|
+
if (canonical(real) !== canonical(root)) {
|
|
38
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Agent output root cannot be a link');
|
|
39
|
+
}
|
|
40
|
+
let workspaceReal;
|
|
41
|
+
try {
|
|
42
|
+
workspaceReal = fs.realpathSync(workspaceRoot);
|
|
43
|
+
if (!fs.statSync(workspaceReal).isDirectory())
|
|
44
|
+
throw new Error();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Agent data directory is unavailable');
|
|
48
|
+
}
|
|
49
|
+
return { version: 1, workspaceId: `outputs:${aid}`, ownerAid: '', rootPath: workspaceReal,
|
|
50
|
+
outputRootPath: real, navigationRevision: 1,
|
|
51
|
+
entries: [{ id: 'output', title: 'Output', path: 'output', kind: 'directory', order: 0 }] };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function authorizeOutput(aid, from) {
|
|
55
|
+
const view = await ownerResolver.refresh(aid, { maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, source: 'outputs.read', allowTransient: false });
|
|
56
|
+
if (view.authorizationStatus !== 'verified' || view.ownerAid !== from || view.refreshFailure?.fallbackUsed
|
|
57
|
+
|| (view.validUntil ?? 0) <= Date.now()) {
|
|
58
|
+
throw new DataRootError('OUTPUT_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
59
|
+
}
|
|
60
|
+
return `${view.ownerAid}:${view.revision}`;
|
|
61
|
+
}
|
|
62
|
+
export function currentOutputOwner(aid, from, generation) {
|
|
63
|
+
const view = ownerResolver.snapshot(aid);
|
|
64
|
+
return view.authorizationStatus === 'verified' && !view.refreshFailure?.fallbackUsed
|
|
65
|
+
&& (view.validUntil ?? 0) > Date.now()
|
|
66
|
+
&& view.ownerAid === from && `${view.ownerAid}:${view.revision}` === generation;
|
|
67
|
+
}
|
|
68
|
+
export class OutputService {
|
|
69
|
+
aid;
|
|
70
|
+
options;
|
|
71
|
+
store;
|
|
72
|
+
index;
|
|
73
|
+
projections = new Map();
|
|
74
|
+
cached = new Map();
|
|
75
|
+
flights = new Map();
|
|
76
|
+
closed = false;
|
|
77
|
+
async authorize(message) {
|
|
78
|
+
if (this.closed)
|
|
79
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Output service is closed');
|
|
80
|
+
if (!message.encrypted)
|
|
81
|
+
throw new DataRootError('ENCRYPTION_REQUIRED', 'Output queries require encryption');
|
|
82
|
+
return (this.options.authorize ?? authorizeOutput)(this.aid, message.fromAid);
|
|
83
|
+
}
|
|
84
|
+
constructor(aid, options = {}) {
|
|
85
|
+
this.aid = aid;
|
|
86
|
+
this.options = options;
|
|
87
|
+
this.store = new OutputStore(options.root ?? agentOutputDir);
|
|
88
|
+
// One bounded fixed-output watcher per active router. It must keep observing
|
|
89
|
+
// during an idle open panel; reads cannot be used as a business keepalive.
|
|
90
|
+
this.index = new TeamWorkspaceItemsIndex(this.store, 'agent-output-items-v1', 0);
|
|
91
|
+
this.index.onCommitted((aid, revision, items, _truncated, healthy) => this.commit(aid, revision, items, healthy));
|
|
92
|
+
}
|
|
93
|
+
projection(aid) {
|
|
94
|
+
let state = this.projections.get(aid);
|
|
95
|
+
if (!state) {
|
|
96
|
+
state = { epoch: crypto.randomBytes(12).toString('hex'), seq: 0, revision: '', versions: new Map(), log: [] };
|
|
97
|
+
this.projections.set(aid, state);
|
|
98
|
+
}
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
commit(aid, revision, items, healthy) {
|
|
102
|
+
const state = this.projection(aid);
|
|
103
|
+
if (state.revision === revision && state.watcherHealthy === healthy)
|
|
104
|
+
return;
|
|
105
|
+
const versions = new Map(items.map(item => [outputId(item.path), item.signature]));
|
|
106
|
+
const upserts = [...versions].filter(([id, value]) => state.versions.get(id) !== value).map(([id]) => id);
|
|
107
|
+
const deletes = [...state.versions.keys()].filter(id => !versions.has(id));
|
|
108
|
+
state.seq++;
|
|
109
|
+
state.revision = revision;
|
|
110
|
+
state.watcherHealthy = healthy;
|
|
111
|
+
state.versions = versions;
|
|
112
|
+
state.log.push(upserts.length + deletes.length > 2048
|
|
113
|
+
? { seq: state.seq, revision, upserts: [], deletes: [], reset: true }
|
|
114
|
+
: { seq: state.seq, revision, upserts, deletes });
|
|
115
|
+
while (state.log.length > 64 || state.log.length > 1 && state.log.reduce((n, row) => n + row.upserts.length + row.deletes.length, 0) > 2048)
|
|
116
|
+
state.log.shift();
|
|
117
|
+
const data = { sourceAid: aid, revision, cursor: `${state.epoch}.${state.seq}`, event: OUTPUT_EVENT };
|
|
118
|
+
this.options.notify?.(data);
|
|
119
|
+
outputChangePublisher?.(aid, data);
|
|
120
|
+
}
|
|
121
|
+
async handle(message) {
|
|
122
|
+
if (this.closed)
|
|
123
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Output service is closed');
|
|
124
|
+
if (!isOutputType(message.type))
|
|
125
|
+
throw new DataRootError('UNKNOWN_TYPE', 'Unknown output query');
|
|
126
|
+
const generation = await this.authorize(message);
|
|
127
|
+
const ensure = () => {
|
|
128
|
+
if (this.closed || !(this.options.current ?? currentOutputOwner)(this.aid, message.fromAid, generation)) {
|
|
129
|
+
this.cached.clear();
|
|
130
|
+
throw new DataRootError('OUTPUT_FORBIDDEN', 'Output authorization changed');
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
ensure();
|
|
134
|
+
const args = message.payload.data;
|
|
135
|
+
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
136
|
+
throw new DataRootError('INVALID_ARGUMENT', 'data must be an object');
|
|
137
|
+
const data = args;
|
|
138
|
+
const action = message.type.split('.').at(-1);
|
|
139
|
+
const allowed = {
|
|
140
|
+
snapshot: ['protocolVersion', 'knownRevision', 'limit', 'waitForIndex'], list: ['protocolVersion', 'kind', 'pageCursor', 'limit'],
|
|
141
|
+
detail: ['protocolVersion', 'id'], changes: ['protocolVersion', 'cursor'],
|
|
142
|
+
};
|
|
143
|
+
if (data.protocolVersion !== 1 || Object.keys(data).some(key => !allowed[action].includes(key))) {
|
|
144
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Unsupported output query parameters');
|
|
145
|
+
}
|
|
146
|
+
if (data.knownRevision !== undefined && (typeof data.knownRevision !== 'string'
|
|
147
|
+
|| data.knownRevision.length > 128))
|
|
148
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid known revision');
|
|
149
|
+
if (data.waitForIndex !== undefined && typeof data.waitForIndex !== 'boolean')
|
|
150
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid index wait policy');
|
|
151
|
+
if (action === 'changes' && (typeof data.cursor !== 'string' || data.cursor.length > 128)) {
|
|
152
|
+
throw new DataRootError('INVALID_ARGUMENT', 'A bounded change cursor is required');
|
|
153
|
+
}
|
|
154
|
+
const fingerprint = JSON.stringify([message.type, data]);
|
|
155
|
+
const key = `${generation}:${message.fromAid}:${message.requestId}`;
|
|
156
|
+
const saved = this.cached.get(key);
|
|
157
|
+
if (saved && saved.until > Date.now()) {
|
|
158
|
+
if (saved.fingerprint !== fingerprint)
|
|
159
|
+
throw new DataRootError('REQUEST_ID_CONFLICT', 'request_id was reused');
|
|
160
|
+
return saved.result;
|
|
161
|
+
}
|
|
162
|
+
const flight = this.flights.get(key);
|
|
163
|
+
if (flight && flight.fingerprint !== fingerprint)
|
|
164
|
+
throw new DataRootError('REQUEST_ID_CONFLICT', 'request_id was reused');
|
|
165
|
+
if (!flight && this.flights.size >= 3)
|
|
166
|
+
throw new DataRootError('RATE_LIMITED', 'Output query concurrency exceeded');
|
|
167
|
+
const result = flight?.result ?? this.query(action, data);
|
|
168
|
+
if (!flight)
|
|
169
|
+
this.flights.set(key, { fingerprint, result });
|
|
170
|
+
try {
|
|
171
|
+
const value = await result;
|
|
172
|
+
ensure();
|
|
173
|
+
this.cached.set(key, { until: Date.now() + 30_000, fingerprint, result: value });
|
|
174
|
+
while (this.cached.size > 32)
|
|
175
|
+
this.cached.delete(this.cached.keys().next().value);
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
this.flights.delete(key);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async query(action, data) {
|
|
183
|
+
const state = this.store.require(this.aid);
|
|
184
|
+
const projection = this.projection(this.aid);
|
|
185
|
+
let offset = 0;
|
|
186
|
+
let revision;
|
|
187
|
+
let kind;
|
|
188
|
+
if (data.limit !== undefined && (!Number.isSafeInteger(data.limit) || Number(data.limit) < 1 || Number(data.limit) > 20))
|
|
189
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid page limit');
|
|
190
|
+
if (data.kind !== undefined && !['document', 'image', 'media', 'archive', 'file'].includes(String(data.kind)))
|
|
191
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid kind');
|
|
192
|
+
kind = data.kind;
|
|
193
|
+
if (data.pageCursor !== undefined) {
|
|
194
|
+
if (typeof data.pageCursor !== 'string' || data.pageCursor.length > 512)
|
|
195
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid page cursor');
|
|
196
|
+
try {
|
|
197
|
+
const cursor = JSON.parse(Buffer.from(data.pageCursor, 'base64url').toString());
|
|
198
|
+
if (cursor.epoch !== projection.epoch || cursor.kind !== kind
|
|
199
|
+
|| !Number.isSafeInteger(cursor.offset) || cursor.offset < 0 || cursor.offset > 10000
|
|
200
|
+
|| typeof cursor.revision !== 'string' || !/^[a-f0-9]{24}$/.test(cursor.revision)
|
|
201
|
+
|| Object.keys(cursor).some(key => !['epoch', 'kind', 'offset', 'revision'].includes(key)))
|
|
202
|
+
throw new Error();
|
|
203
|
+
offset = cursor.offset;
|
|
204
|
+
revision = cursor.revision;
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
throw new DataRootError('INDEX_CHANGED', 'Restart output pagination');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let ids;
|
|
211
|
+
let deletes = [];
|
|
212
|
+
let reset = false;
|
|
213
|
+
let deltaSeq;
|
|
214
|
+
if (action === 'changes') {
|
|
215
|
+
await this.index.queryFiltered(this.aid, state, { path: 'output', limit: 1 }, () => false);
|
|
216
|
+
const match = typeof data.cursor === 'string' && /^([a-f0-9]{24})\.(\d+)$/.exec(data.cursor);
|
|
217
|
+
const seq = match ? Number(match[2]) : -1;
|
|
218
|
+
reset = !match || match[1] !== projection.epoch || seq > projection.seq || seq < (projection.log[0]?.seq ?? 1) - 1;
|
|
219
|
+
const delta = projection.log.filter(row => row.seq > seq);
|
|
220
|
+
deltaSeq = projection.seq;
|
|
221
|
+
if (delta.some(row => row.reset))
|
|
222
|
+
reset = true;
|
|
223
|
+
ids = new Set(delta.flatMap(row => row.upserts));
|
|
224
|
+
deletes = [...new Set(delta.flatMap(row => row.deletes))].filter(id => !projection.versions.has(id));
|
|
225
|
+
for (const id of deletes)
|
|
226
|
+
ids.delete(id);
|
|
227
|
+
if (ids.size > 20 || deletes.length > 100)
|
|
228
|
+
reset = true;
|
|
229
|
+
if (reset) {
|
|
230
|
+
ids.clear();
|
|
231
|
+
deletes = [];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (action === 'detail') {
|
|
235
|
+
if (typeof data.id !== 'string' || !/^[a-f0-9]{32}$/.test(data.id))
|
|
236
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid artifact id');
|
|
237
|
+
ids = new Set([data.id]);
|
|
238
|
+
}
|
|
239
|
+
const page = await this.index.queryFiltered(this.aid, state, {
|
|
240
|
+
path: 'output', offset, limit: data.limit ?? 20, ...(revision ? { indexRevision: revision } : {}),
|
|
241
|
+
}, item => (!kind || outputKind(item.path) === kind) && (!ids || ids.has(outputId(item.path))), action === 'snapshot' && data.waitForIndex !== true && (this.options.notifications?.() ?? hasOutputNotifications(this.aid)));
|
|
242
|
+
if (deltaSeq !== undefined && deltaSeq !== projection.seq) {
|
|
243
|
+
throw new DataRootError('INDEX_CHANGED', 'Output changed while preparing delta; restart snapshot');
|
|
244
|
+
}
|
|
245
|
+
if (action === 'detail' && !page.items.length)
|
|
246
|
+
throw new DataRootError('NOT_FOUND', 'Output was removed or renamed');
|
|
247
|
+
const response = {
|
|
248
|
+
protocol: 'evol.outputs', protocolVersion: 1, sourceAid: this.aid, space: 'agent-output',
|
|
249
|
+
revision: page.indexRevision, cursor: `${projection.epoch}.${projection.seq}`, generatedAt: Date.now(),
|
|
250
|
+
coverage: page.truncated || !page.watcherHealthy || page.indexState === 'building' ? 'partial' : 'complete',
|
|
251
|
+
indexState: page.indexState, truncated: page.truncated,
|
|
252
|
+
notifications: (this.options.notifications?.() ?? hasOutputNotifications(this.aid)) ? { busAid: this.aid, event: OUTPUT_EVENT } : null,
|
|
253
|
+
items: page.items.map(item => outputItem(item, projection.versions.get(outputId(item.path)) ?? `${item.size}:${item.mtime}`)), nextCursor: null,
|
|
254
|
+
...(action === 'changes' ? { reset, deletes } : {}),
|
|
255
|
+
};
|
|
256
|
+
const items = response.items;
|
|
257
|
+
while (items.length > 1 && Buffer.byteLength(JSON.stringify(response)) > 46 * 1024)
|
|
258
|
+
items.pop();
|
|
259
|
+
if (action === 'changes' && (page.hasMore || items.length < page.items.length)) {
|
|
260
|
+
// A delta has no page cursor contract. Never advance its change cursor
|
|
261
|
+
// past a discarded upsert; ask the client for a new bounded baseline.
|
|
262
|
+
response.reset = true;
|
|
263
|
+
response.items = [];
|
|
264
|
+
response.deletes = [];
|
|
265
|
+
return response;
|
|
266
|
+
}
|
|
267
|
+
const next = offset + items.length;
|
|
268
|
+
if (page.hasMore || items.length < page.items.length)
|
|
269
|
+
response.nextCursor = Buffer.from(JSON.stringify({
|
|
270
|
+
epoch: projection.epoch, revision: page.indexRevision, offset: next, ...(kind ? { kind } : {}),
|
|
271
|
+
})).toString('base64url');
|
|
272
|
+
if (action === 'snapshot' && data.knownRevision === page.indexRevision && page.indexState === 'ready') {
|
|
273
|
+
response.notModified = true;
|
|
274
|
+
response.items = [];
|
|
275
|
+
}
|
|
276
|
+
return response;
|
|
277
|
+
}
|
|
278
|
+
async close() { this.closed = true; this.cached.clear(); await this.index.close(); }
|
|
279
|
+
}
|
package/dist/paths.js
CHANGED
|
@@ -509,6 +509,9 @@ export function integrityDir() {
|
|
|
509
509
|
export function integrityDbPath() {
|
|
510
510
|
return path.join(integrityDir(), 'file-integrity.db');
|
|
511
511
|
}
|
|
512
|
+
export function ownershipCachePath() {
|
|
513
|
+
return path.join(resolveRoot(), 'data', 'ownership-cache.json');
|
|
514
|
+
}
|
|
512
515
|
export function integritySnapshotDir() {
|
|
513
516
|
return path.join(integrityDir(), 'snapshots');
|
|
514
517
|
}
|
package/dist/proxy/manager.js
CHANGED
|
@@ -2,7 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import chokidar from 'chokidar';
|
|
5
|
-
import { DEFAULT_ECWEB_PORT, SERVICE_STARTUP_TIMEOUT_MS, serviceRuntimeMode } from '../config/daemon-services.js';
|
|
5
|
+
import { DEFAULT_ECWEB_PORT, SERVICE_STARTUP_TIMEOUT_MS, resolveDaemonServices, serviceRuntimeMode } from '../config/daemon-services.js';
|
|
6
6
|
import { ConfigTarget, mutateConfig, onConfigWrite } from '../config/config-manager.js';
|
|
7
7
|
import { loadDaemonConfig } from '../config-store.js';
|
|
8
8
|
import { resolvePaths } from '../paths.js';
|
|
@@ -11,6 +11,21 @@ import { logger as defaultLogger } from '../utils/logger.js';
|
|
|
11
11
|
import { probeServiceRoot } from '../aun/service-proxy.js';
|
|
12
12
|
import { readServiceProxyEndpoint, startServiceProxy } from '../aun/service-proxy.js';
|
|
13
13
|
import { ServiceSupervisor } from './service-supervisor.js';
|
|
14
|
+
/** Read the latest saved services whenever status is requested. */
|
|
15
|
+
export function readServiceProxySnapshot(transport) {
|
|
16
|
+
return {
|
|
17
|
+
source: 'daemon-config',
|
|
18
|
+
transport,
|
|
19
|
+
items: resolveDaemonServices(loadDaemonConfig().services).filter(service => !!service.proxy || service.name === 'ecweb').map(service => ({
|
|
20
|
+
name: service.name,
|
|
21
|
+
serviceEnabled: service.enabled === true,
|
|
22
|
+
proxyEnabled: service.proxy?.enabled === true,
|
|
23
|
+
source: service.proxy?.source ?? null,
|
|
24
|
+
serviceType: service.proxy?.serviceType ?? null,
|
|
25
|
+
visibility: service.proxy?.visibility ?? null,
|
|
26
|
+
})),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
14
29
|
const MUTATIONS = new Set([
|
|
15
30
|
'build', 'update', 'apply', 'publish', 'unpublish', 'remove', 'start', 'stop',
|
|
16
31
|
'restart', 'reload', 'reset-failure',
|
|
@@ -122,7 +137,7 @@ export class ServiceProxyManager {
|
|
|
122
137
|
this.instanceWatcher = chokidar.watch(resolvePaths().instanceDir, { ignoreInitial: true, depth: 0 });
|
|
123
138
|
this.instanceWatcher.on('all', (_event, filePath) => {
|
|
124
139
|
const basename = path.basename(filePath);
|
|
125
|
-
const configured = loadDaemonConfig().services
|
|
140
|
+
const configured = resolveDaemonServices(loadDaemonConfig().services);
|
|
126
141
|
if (!configured.some(service => service.proxy?.enabled === true
|
|
127
142
|
&& service.proxy.source === 'instance'
|
|
128
143
|
&& basename.startsWith(service.name + '-')))
|
|
@@ -149,7 +164,7 @@ export class ServiceProxyManager {
|
|
|
149
164
|
});
|
|
150
165
|
this.applyQueue = this.applyQueue.then(async () => {
|
|
151
166
|
if (!this.stopped)
|
|
152
|
-
await this.supervisor.start(loadDaemonConfig().services
|
|
167
|
+
await this.supervisor.start(resolveDaemonServices(loadDaemonConfig().services));
|
|
153
168
|
});
|
|
154
169
|
await this.scheduleApply();
|
|
155
170
|
}
|
|
@@ -183,6 +198,12 @@ export class ServiceProxyManager {
|
|
|
183
198
|
}).finally(() => { this.stopPromise = undefined; });
|
|
184
199
|
return this.stopPromise;
|
|
185
200
|
}
|
|
201
|
+
transportSnapshot() {
|
|
202
|
+
return {
|
|
203
|
+
...this.proxyTransport,
|
|
204
|
+
registeredServices: Object.keys(this.activeProxy?.endpoints ?? {}),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
186
207
|
async execute(request) {
|
|
187
208
|
if (!request || typeof request !== 'object' || !request.operation) {
|
|
188
209
|
throw Object.assign(new Error('operation is required'), { code: 'INVALID_ARGUMENT' });
|
|
@@ -226,7 +247,7 @@ export class ServiceProxyManager {
|
|
|
226
247
|
}
|
|
227
248
|
async executeRead(request) {
|
|
228
249
|
const config = loadDaemonConfig();
|
|
229
|
-
const services = config.services
|
|
250
|
+
const services = resolveDaemonServices(config.services);
|
|
230
251
|
const service = request.name ? findService(services, request.name) : undefined;
|
|
231
252
|
if (request.name && !service && request.operation !== 'job') {
|
|
232
253
|
throw Object.assign(new Error('service not found: ' + request.name), { code: 'NOT_FOUND' });
|
|
@@ -283,14 +304,17 @@ export class ServiceProxyManager {
|
|
|
283
304
|
throw Object.assign(new Error('unsupported read operation: ' + request.operation), { code: 'NOT_SUPPORTED' });
|
|
284
305
|
}
|
|
285
306
|
dryRun(request) {
|
|
286
|
-
const services = loadDaemonConfig().services
|
|
287
|
-
const
|
|
307
|
+
const services = resolveDaemonServices(loadDaemonConfig().services);
|
|
308
|
+
const name = request.operation === 'build' ? request.service?.name : request.name;
|
|
309
|
+
const current = name ? findService(services, name) : undefined;
|
|
288
310
|
if (request.operation === 'build' && request.service) {
|
|
289
311
|
if (current && request.ifRev !== serviceRevision(current))
|
|
290
312
|
throw Object.assign(new Error('config revision changed'), { code: 'CONFLICT', data: { currentRev: serviceRevision(current) } });
|
|
291
313
|
if (!current && request.ifRev !== 'absent')
|
|
292
314
|
throw Object.assign(new Error('new services require ifRev=absent'), { code: 'CONFLICT', data: { currentRev: 'absent' } });
|
|
293
|
-
|
|
315
|
+
const updated = request.service.name === 'ecweb'
|
|
316
|
+
? findService(resolveDaemonServices([request.service]), 'ecweb') : request.service;
|
|
317
|
+
return { ok: true, dryRun: true, changed: !current || stable(current) !== stable(updated), configRev: serviceRevision(updated), plan: 'save service definition and apply' };
|
|
294
318
|
}
|
|
295
319
|
if (!current)
|
|
296
320
|
throw Object.assign(new Error('service not found: ' + request.name), { code: 'NOT_FOUND' });
|
|
@@ -332,13 +356,15 @@ export class ServiceProxyManager {
|
|
|
332
356
|
await this.scheduleApply();
|
|
333
357
|
return { ok: true, ...result, operationId, jobId: operationId, state: 'completed' };
|
|
334
358
|
}
|
|
335
|
-
const current = findService(loadDaemonConfig().services
|
|
359
|
+
const current = findService(resolveDaemonServices(loadDaemonConfig().services), name);
|
|
336
360
|
if (!current)
|
|
337
361
|
throw Object.assign(new Error('service not found: ' + name), { code: 'NOT_FOUND' });
|
|
338
362
|
if (request.ifRev !== serviceRevision(current)) {
|
|
339
363
|
throw Object.assign(new Error('config revision changed'), { code: 'CONFLICT', data: { currentRev: serviceRevision(current) } });
|
|
340
364
|
}
|
|
341
365
|
if (request.operation === 'remove') {
|
|
366
|
+
if (name === 'ecweb')
|
|
367
|
+
throw Object.assign(new Error('ECWeb is built in; stop or unpublish it instead'), { code: 'BUILTIN_SERVICE' });
|
|
342
368
|
if (current.enabled || current.proxy?.enabled)
|
|
343
369
|
throw Object.assign(new Error('unpublish and stop the service before removal'), { code: 'SERVICE_BUSY' });
|
|
344
370
|
const result = this.mutateService(name, request.ifRev, () => undefined);
|
|
@@ -413,7 +439,8 @@ export class ServiceProxyManager {
|
|
|
413
439
|
mutateService(name, ifRev, mutate, allowCreate = false) {
|
|
414
440
|
const result = mutateConfig(ConfigTarget.Process, undefined, config => {
|
|
415
441
|
const services = Array.isArray(config.services) ? config.services : [];
|
|
416
|
-
const
|
|
442
|
+
const stored = findService(services, name);
|
|
443
|
+
const current = findService(resolveDaemonServices(services), name);
|
|
417
444
|
const currentRev = serviceRevision(current);
|
|
418
445
|
if (ifRev !== currentRev) {
|
|
419
446
|
throw Object.assign(new Error('config revision changed'), { code: 'CONFLICT', data: { currentRev } });
|
|
@@ -423,11 +450,12 @@ export class ServiceProxyManager {
|
|
|
423
450
|
}
|
|
424
451
|
const updated = mutate(current);
|
|
425
452
|
config.services = updated
|
|
426
|
-
?
|
|
453
|
+
? stored ? services.map(item => item.name === name ? updated : item) : [...services, updated]
|
|
427
454
|
: services.filter(item => item.name !== name);
|
|
428
455
|
return updated;
|
|
429
456
|
});
|
|
430
|
-
const service = result.value
|
|
457
|
+
const service = result.value?.name === 'ecweb'
|
|
458
|
+
? findService(resolveDaemonServices([result.value]), 'ecweb') : result.value;
|
|
431
459
|
return { changed: result.changed, configRev: serviceRevision(service), ...(service ? { service: this.describe(service) } : {}) };
|
|
432
460
|
}
|
|
433
461
|
async scheduleApply() {
|
|
@@ -437,7 +465,7 @@ export class ServiceProxyManager {
|
|
|
437
465
|
async applyFromConfig() {
|
|
438
466
|
if (this.stopped)
|
|
439
467
|
return;
|
|
440
|
-
const services = loadDaemonConfig().services
|
|
468
|
+
const services = resolveDaemonServices(loadDaemonConfig().services);
|
|
441
469
|
const ecweb = findService(services, 'ecweb');
|
|
442
470
|
await this.options.ecwebSupervisor?.configure({
|
|
443
471
|
enabled: ecweb?.enabled === true,
|
|
@@ -449,7 +477,9 @@ export class ServiceProxyManager {
|
|
|
449
477
|
await this.supervisor.reconcile(services);
|
|
450
478
|
if (this.stopped)
|
|
451
479
|
return;
|
|
452
|
-
const desired =
|
|
480
|
+
const desired = this.options.providerAid && this.options.controlChannel
|
|
481
|
+
? services.filter(service => service.enabled === true && service.proxy?.enabled === true)
|
|
482
|
+
: [];
|
|
453
483
|
const publication = desired.map(service => ({ name: service.name, proxy: service.proxy }));
|
|
454
484
|
const configSignature = hash(desired.map(service => ({ name: service.name, proxy: service.proxy, port: service.port })));
|
|
455
485
|
// A pending handle is already discovering endpoints. Its ready callback
|