evolcore 0.0.47 → 0.0.49
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 +90 -1
- package/bin/ec-build.mjs +86 -0
- package/dist/agent-template/jobs.js +12 -4
- package/dist/agent-template/runtime.js +143 -40
- 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 +36 -17
- 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/msg/p2p.js +2 -1
- package/dist/aun/service-proxy.js +4 -2
- package/dist/build-identity.json +1 -0
- package/dist/channels/aun.js +722 -295
- 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 +13 -2
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/index.js +9 -9
- 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/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/provider-command.js +74 -13
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +62 -17
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/stats.js +3 -3
- package/dist/cli/team-workspace-command.js +56 -2
- 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-field-policy.js +71 -1
- package/dist/config/config-manager.js +13 -7
- 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 +67 -12
- package/dist/config/providers-management.js +477 -51
- package/dist/config/resolved-config-op.js +3 -2
- 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 +36 -26
- package/dist/core/auth/operation-authorizer.js +25 -0
- package/dist/core/auth/operation-catalog.js +37 -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/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +126 -87
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +67 -150
- package/dist/core/command/menu-protocol.js +31 -1
- package/dist/core/command/provider-menu.js +13 -3
- package/dist/core/command/remote-shell.js +565 -0
- 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 +64 -8
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +20 -3
- 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 +3 -1
- package/dist/core/message/aun-ipc-sender.js +279 -107
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +41 -2
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +140 -370
- package/dist/core/message/message-log.js +29 -0
- package/dist/core/message/message-queue.js +119 -15
- package/dist/core/message/message-utils.js +8 -0
- package/dist/core/message/response-engine.js +580 -134
- package/dist/core/message/send-routing.js +5 -1
- package/dist/core/model/catalog-service.js +31 -11
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-capabilities.js +22 -4
- package/dist/core/model/model-catalog.js +1 -0
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +328 -50
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/protected-paths.js +6 -6
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +36 -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 +13 -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/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +12 -9
- package/dist/directory/owner-directory-cache.js +64 -28
- package/dist/directory/owner-directory-markdown.js +14 -2
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-query-operation.js +29 -3
- package/dist/directory/owner-directory-remarks.js +11 -3
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +112 -29
- 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 +36 -6
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +29 -3
- package/dist/event-center/runtime.js +106 -11
- package/dist/event-center/script-runner.js +5 -5
- package/dist/index.js +96 -59
- package/dist/ipc.js +38 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +63 -0
- package/dist/outputs/protocol.js +103 -0
- package/dist/outputs/service.js +266 -0
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +43 -13
- package/dist/services/index.js +114 -5
- package/dist/services/ipc-operation.js +88 -15
- package/dist/services/pack-manager.js +13 -1
- package/dist/services/router.js +21 -6
- package/dist/services/script-runner.js +5 -4
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +1 -1
- package/dist/stats/budget.js +2 -2
- package/dist/stats/db.js +19 -0
- package/dist/stats/index.js +1 -1
- package/dist/stats/{price-resolver.js → model-resolver.js} +304 -23
- package/dist/stats/normalizer.js +2 -0
- package/dist/stats/query.js +35 -27
- package/dist/stats/quota-query.js +95 -0
- 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 +21 -3
- package/dist/trigger/validation.js +22 -0
- package/dist/utils/atomic-write.js +22 -8
- 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/host-info.js +100 -1
- package/dist/utils/msg-diag.js +1 -0
- package/dist/utils/npm-ops.js +43 -8
- 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 +4 -2
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +16 -1
- package/kits/docs/evolcore/directory.md +30 -12
- package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
- package/kits/docs/evolcore/model.md +10 -0
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/peer.md +19 -65
- package/kits/docs/evolcore/provider.md +124 -4
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +83 -0
- package/kits/docs/evolcore/services.md +6 -6
- package/kits/docs/evolcore/stats.md +2 -0
- 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 +12 -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/agent-config.schema.20.json +24 -0
- package/kits/schemas/contact-book.schema.4.json +52 -0
- package/kits/schemas/providers.schema.3.json +200 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ability/references/calling.md +1 -1
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- 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 +270 -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/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/baseagent.md +6 -0
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- 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 +7 -5
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +6 -4
- package/scripts/agent-template/inspect.mjs +50 -11
- package/scripts/agent-template/shared/common.mjs +11 -6
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +62 -11
- package/scripts/agent-template/shared/template-package.mjs +189 -21
- package/scripts/agent-template/shared/template-runtime.mjs +54 -6
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +52 -14
- 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,266 @@
|
|
|
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 { currentOutputOwner, authorizeOutput } from './authorization.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 { authorizeOutput, currentOutputOwner } from './authorization.js';
|
|
55
|
+
export class OutputService {
|
|
56
|
+
aid;
|
|
57
|
+
options;
|
|
58
|
+
store;
|
|
59
|
+
index;
|
|
60
|
+
projections = new Map();
|
|
61
|
+
cached = new Map();
|
|
62
|
+
flights = new Map();
|
|
63
|
+
closed = false;
|
|
64
|
+
async authorize(message) {
|
|
65
|
+
if (this.closed)
|
|
66
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Output service is closed');
|
|
67
|
+
if (!message.encrypted)
|
|
68
|
+
throw new DataRootError('ENCRYPTION_REQUIRED', 'Output queries require encryption');
|
|
69
|
+
return (this.options.authorize ?? authorizeOutput)(this.aid, message.fromAid);
|
|
70
|
+
}
|
|
71
|
+
constructor(aid, options = {}) {
|
|
72
|
+
this.aid = aid;
|
|
73
|
+
this.options = options;
|
|
74
|
+
this.store = new OutputStore(options.root ?? agentOutputDir);
|
|
75
|
+
// One bounded fixed-output watcher per active router. It must keep observing
|
|
76
|
+
// during an idle open panel; reads cannot be used as a business keepalive.
|
|
77
|
+
this.index = new TeamWorkspaceItemsIndex(this.store, 'agent-output-items-v1', 0);
|
|
78
|
+
this.index.onCommitted((aid, revision, items, _truncated, healthy) => this.commit(aid, revision, items, healthy));
|
|
79
|
+
}
|
|
80
|
+
projection(aid) {
|
|
81
|
+
let state = this.projections.get(aid);
|
|
82
|
+
if (!state) {
|
|
83
|
+
state = { epoch: crypto.randomBytes(12).toString('hex'), seq: 0, revision: '', versions: new Map(), log: [] };
|
|
84
|
+
this.projections.set(aid, state);
|
|
85
|
+
}
|
|
86
|
+
return state;
|
|
87
|
+
}
|
|
88
|
+
commit(aid, revision, items, healthy) {
|
|
89
|
+
const state = this.projection(aid);
|
|
90
|
+
if (state.revision === revision && state.watcherHealthy === healthy)
|
|
91
|
+
return;
|
|
92
|
+
const versions = new Map(items.map(item => [outputId(item.path), item.signature]));
|
|
93
|
+
const upserts = [...versions].filter(([id, value]) => state.versions.get(id) !== value).map(([id]) => id);
|
|
94
|
+
const deletes = [...state.versions.keys()].filter(id => !versions.has(id));
|
|
95
|
+
state.seq++;
|
|
96
|
+
state.revision = revision;
|
|
97
|
+
state.watcherHealthy = healthy;
|
|
98
|
+
state.versions = versions;
|
|
99
|
+
state.log.push(upserts.length + deletes.length > 2048
|
|
100
|
+
? { seq: state.seq, revision, upserts: [], deletes: [], reset: true }
|
|
101
|
+
: { seq: state.seq, revision, upserts, deletes });
|
|
102
|
+
while (state.log.length > 64 || state.log.length > 1 && state.log.reduce((n, row) => n + row.upserts.length + row.deletes.length, 0) > 2048)
|
|
103
|
+
state.log.shift();
|
|
104
|
+
const data = { sourceAid: aid, revision, cursor: `${state.epoch}.${state.seq}`, event: OUTPUT_EVENT };
|
|
105
|
+
this.options.notify?.(data);
|
|
106
|
+
outputChangePublisher?.(aid, data);
|
|
107
|
+
}
|
|
108
|
+
async handle(message) {
|
|
109
|
+
if (this.closed)
|
|
110
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Output service is closed');
|
|
111
|
+
if (!isOutputType(message.type))
|
|
112
|
+
throw new DataRootError('UNKNOWN_TYPE', 'Unknown output query');
|
|
113
|
+
const generation = await this.authorize(message);
|
|
114
|
+
const ensure = () => {
|
|
115
|
+
if (this.closed || !(this.options.current ?? currentOutputOwner)(this.aid, message.fromAid, generation)) {
|
|
116
|
+
this.cached.clear();
|
|
117
|
+
throw new DataRootError('OUTPUT_FORBIDDEN', 'Output authorization changed');
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
ensure();
|
|
121
|
+
const args = message.payload.data;
|
|
122
|
+
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
123
|
+
throw new DataRootError('INVALID_ARGUMENT', 'data must be an object');
|
|
124
|
+
const data = args;
|
|
125
|
+
const action = message.type.split('.').at(-1);
|
|
126
|
+
const allowed = {
|
|
127
|
+
snapshot: ['protocolVersion', 'knownRevision', 'limit', 'waitForIndex'], list: ['protocolVersion', 'kind', 'pageCursor', 'limit'],
|
|
128
|
+
detail: ['protocolVersion', 'id'], changes: ['protocolVersion', 'cursor'],
|
|
129
|
+
};
|
|
130
|
+
if (data.protocolVersion !== 1 || Object.keys(data).some(key => !allowed[action].includes(key))) {
|
|
131
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Unsupported output query parameters');
|
|
132
|
+
}
|
|
133
|
+
if (data.knownRevision !== undefined && (typeof data.knownRevision !== 'string'
|
|
134
|
+
|| data.knownRevision.length > 128))
|
|
135
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid known revision');
|
|
136
|
+
if (data.waitForIndex !== undefined && typeof data.waitForIndex !== 'boolean')
|
|
137
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid index wait policy');
|
|
138
|
+
if (action === 'changes' && (typeof data.cursor !== 'string' || data.cursor.length > 128)) {
|
|
139
|
+
throw new DataRootError('INVALID_ARGUMENT', 'A bounded change cursor is required');
|
|
140
|
+
}
|
|
141
|
+
const fingerprint = JSON.stringify([message.type, data]);
|
|
142
|
+
const key = `${generation}:${message.fromAid}:${message.requestId}`;
|
|
143
|
+
const saved = this.cached.get(key);
|
|
144
|
+
if (saved && saved.until > Date.now()) {
|
|
145
|
+
if (saved.fingerprint !== fingerprint)
|
|
146
|
+
throw new DataRootError('REQUEST_ID_CONFLICT', 'request_id was reused');
|
|
147
|
+
return saved.result;
|
|
148
|
+
}
|
|
149
|
+
const flight = this.flights.get(key);
|
|
150
|
+
if (flight && flight.fingerprint !== fingerprint)
|
|
151
|
+
throw new DataRootError('REQUEST_ID_CONFLICT', 'request_id was reused');
|
|
152
|
+
if (!flight && this.flights.size >= 3)
|
|
153
|
+
throw new DataRootError('RATE_LIMITED', 'Output query concurrency exceeded');
|
|
154
|
+
const result = flight?.result ?? this.query(action, data);
|
|
155
|
+
if (!flight)
|
|
156
|
+
this.flights.set(key, { fingerprint, result });
|
|
157
|
+
try {
|
|
158
|
+
const value = await result;
|
|
159
|
+
ensure();
|
|
160
|
+
this.cached.set(key, { until: Date.now() + 30_000, fingerprint, result: value });
|
|
161
|
+
while (this.cached.size > 32)
|
|
162
|
+
this.cached.delete(this.cached.keys().next().value);
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
this.flights.delete(key);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async query(action, data) {
|
|
170
|
+
const state = this.store.require(this.aid);
|
|
171
|
+
const projection = this.projection(this.aid);
|
|
172
|
+
let offset = 0;
|
|
173
|
+
let revision;
|
|
174
|
+
let kind;
|
|
175
|
+
if (data.limit !== undefined && (!Number.isSafeInteger(data.limit) || Number(data.limit) < 1 || Number(data.limit) > 20))
|
|
176
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid page limit');
|
|
177
|
+
if (data.kind !== undefined && !['document', 'image', 'media', 'archive', 'file'].includes(String(data.kind)))
|
|
178
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid kind');
|
|
179
|
+
kind = data.kind;
|
|
180
|
+
if (data.pageCursor !== undefined) {
|
|
181
|
+
if (typeof data.pageCursor !== 'string' || data.pageCursor.length > 512)
|
|
182
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid page cursor');
|
|
183
|
+
try {
|
|
184
|
+
const cursor = JSON.parse(Buffer.from(data.pageCursor, 'base64url').toString());
|
|
185
|
+
if (cursor.epoch !== projection.epoch || cursor.kind !== kind
|
|
186
|
+
|| !Number.isSafeInteger(cursor.offset) || cursor.offset < 0 || cursor.offset > 10000
|
|
187
|
+
|| typeof cursor.revision !== 'string' || !/^[a-f0-9]{24}$/.test(cursor.revision)
|
|
188
|
+
|| Object.keys(cursor).some(key => !['epoch', 'kind', 'offset', 'revision'].includes(key)))
|
|
189
|
+
throw new Error();
|
|
190
|
+
offset = cursor.offset;
|
|
191
|
+
revision = cursor.revision;
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
throw new DataRootError('INDEX_CHANGED', 'Restart output pagination');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
let ids;
|
|
198
|
+
let deletes = [];
|
|
199
|
+
let reset = false;
|
|
200
|
+
let deltaSeq;
|
|
201
|
+
if (action === 'changes') {
|
|
202
|
+
await this.index.queryFiltered(this.aid, state, { path: 'output', limit: 1 }, () => false);
|
|
203
|
+
const match = typeof data.cursor === 'string' && /^([a-f0-9]{24})\.(\d+)$/.exec(data.cursor);
|
|
204
|
+
const seq = match ? Number(match[2]) : -1;
|
|
205
|
+
reset = !match || match[1] !== projection.epoch || seq > projection.seq || seq < (projection.log[0]?.seq ?? 1) - 1;
|
|
206
|
+
const delta = projection.log.filter(row => row.seq > seq);
|
|
207
|
+
deltaSeq = projection.seq;
|
|
208
|
+
if (delta.some(row => row.reset))
|
|
209
|
+
reset = true;
|
|
210
|
+
ids = new Set(delta.flatMap(row => row.upserts));
|
|
211
|
+
deletes = [...new Set(delta.flatMap(row => row.deletes))].filter(id => !projection.versions.has(id));
|
|
212
|
+
for (const id of deletes)
|
|
213
|
+
ids.delete(id);
|
|
214
|
+
if (ids.size > 20 || deletes.length > 100)
|
|
215
|
+
reset = true;
|
|
216
|
+
if (reset) {
|
|
217
|
+
ids.clear();
|
|
218
|
+
deletes = [];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (action === 'detail') {
|
|
222
|
+
if (typeof data.id !== 'string' || !/^[a-f0-9]{32}$/.test(data.id))
|
|
223
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid artifact id');
|
|
224
|
+
ids = new Set([data.id]);
|
|
225
|
+
}
|
|
226
|
+
const page = await this.index.queryFiltered(this.aid, state, {
|
|
227
|
+
path: 'output', offset, limit: data.limit ?? 20, ...(revision ? { indexRevision: revision } : {}),
|
|
228
|
+
}, item => (!kind || outputKind(item.path) === kind) && (!ids || ids.has(outputId(item.path))), action === 'snapshot' && data.waitForIndex !== true && (this.options.notifications?.() ?? hasOutputNotifications(this.aid)));
|
|
229
|
+
if (deltaSeq !== undefined && deltaSeq !== projection.seq) {
|
|
230
|
+
throw new DataRootError('INDEX_CHANGED', 'Output changed while preparing delta; restart snapshot');
|
|
231
|
+
}
|
|
232
|
+
if (action === 'detail' && !page.items.length)
|
|
233
|
+
throw new DataRootError('NOT_FOUND', 'Output was removed or renamed');
|
|
234
|
+
const response = {
|
|
235
|
+
protocol: 'evol.outputs', protocolVersion: 1, sourceAid: this.aid, space: 'agent-output',
|
|
236
|
+
revision: page.indexRevision, cursor: `${projection.epoch}.${projection.seq}`, generatedAt: Date.now(),
|
|
237
|
+
coverage: page.truncated || !page.watcherHealthy || page.indexState === 'building' ? 'partial' : 'complete',
|
|
238
|
+
indexState: page.indexState, truncated: page.truncated,
|
|
239
|
+
notifications: (this.options.notifications?.() ?? hasOutputNotifications(this.aid)) ? { busAid: this.aid, event: OUTPUT_EVENT } : null,
|
|
240
|
+
items: page.items.map(item => outputItem(item, projection.versions.get(outputId(item.path)) ?? `${item.size}:${item.mtime}`)), nextCursor: null,
|
|
241
|
+
...(action === 'changes' ? { reset, deletes } : {}),
|
|
242
|
+
};
|
|
243
|
+
const items = response.items;
|
|
244
|
+
while (items.length > 1 && Buffer.byteLength(JSON.stringify(response)) > 46 * 1024)
|
|
245
|
+
items.pop();
|
|
246
|
+
if (action === 'changes' && (page.hasMore || items.length < page.items.length)) {
|
|
247
|
+
// A delta has no page cursor contract. Never advance its change cursor
|
|
248
|
+
// past a discarded upsert; ask the client for a new bounded baseline.
|
|
249
|
+
response.reset = true;
|
|
250
|
+
response.items = [];
|
|
251
|
+
response.deletes = [];
|
|
252
|
+
return response;
|
|
253
|
+
}
|
|
254
|
+
const next = offset + items.length;
|
|
255
|
+
if (page.hasMore || items.length < page.items.length)
|
|
256
|
+
response.nextCursor = Buffer.from(JSON.stringify({
|
|
257
|
+
epoch: projection.epoch, revision: page.indexRevision, offset: next, ...(kind ? { kind } : {}),
|
|
258
|
+
})).toString('base64url');
|
|
259
|
+
if (action === 'snapshot' && data.knownRevision === page.indexRevision && page.indexState === 'ready') {
|
|
260
|
+
response.notModified = true;
|
|
261
|
+
response.items = [];
|
|
262
|
+
}
|
|
263
|
+
return response;
|
|
264
|
+
}
|
|
265
|
+
async close() { this.closed = true; this.cached.clear(); await this.index.close(); }
|
|
266
|
+
}
|
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
|
package/dist/services/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { IdempotencyStore } from './idempotency.js';
|
|
|
12
12
|
import { readLocalSelfIdentity } from './identity.js';
|
|
13
13
|
import { writeServicesIndex } from './index-generator.js';
|
|
14
14
|
import { servicePackLedger as packLedger, routerLedger, ServiceLedger } from '../core/pack-ledger.js';
|
|
15
|
+
import { scheduleServicesAclHarden } from '../core/permission/services-path-acl.js';
|
|
15
16
|
import { ServiceMessageLog } from './message-log.js';
|
|
16
17
|
import { buildPackState, loadPackDir, loadPacks } from './pack-manager.js';
|
|
17
18
|
import { DEFAULT_ROUTER_CONFIG, loadRouterConfig, RateLimiter } from './router.js';
|
|
@@ -19,7 +20,14 @@ import { RateWindow } from '../core/rate-window.js';
|
|
|
19
20
|
import { ServiceScriptRunner } from './script-runner.js';
|
|
20
21
|
import { buildErrorReply, buildSilentReply, buildSuccessReply, replyFromOutcome, isReservedServiceType, matchesListen, RESERVED_TYPES, } from './service-payload.js';
|
|
21
22
|
import { errorMessage } from './types.js';
|
|
22
|
-
|
|
23
|
+
import { isOutputType } from '../outputs/protocol.js';
|
|
24
|
+
import { outputRequestSchema, outputResponseSchema } from '../outputs/protocol.js';
|
|
25
|
+
import { OutputService } from '../outputs/service.js';
|
|
26
|
+
import { isOutputCardsType, outputCardsRequestSchema, outputCardsResponseSchema, OutputCardsService, OUTPUT_CARDS_TYPES } from '../outputs/cards.js';
|
|
27
|
+
import { DataRootError } from '../core/command/team-workspace-store.js';
|
|
28
|
+
import { isWorkbenchType, WORKBENCH_TYPES, workbenchRequestSchema, workbenchResponseSchema } from '../workbench/protocol.js';
|
|
29
|
+
import { WorkbenchService } from '../workbench/service.js';
|
|
30
|
+
export { classifyServicePayloadType, parseServiceType, isReservedServiceType, isProjectionServiceResult, RESERVED_TYPES } from './service-payload.js';
|
|
23
31
|
export { readLocalSelfIdentity } from './identity.js';
|
|
24
32
|
/**
|
|
25
33
|
* 未准入调用的回复预算。
|
|
@@ -56,6 +64,9 @@ export class ServiceRouter {
|
|
|
56
64
|
/** fromAid → 上次告知未准入的时间;窗口内重复调用静默。 */
|
|
57
65
|
unauthorizedNotified = new Map();
|
|
58
66
|
started = false;
|
|
67
|
+
outputService;
|
|
68
|
+
outputCardsService;
|
|
69
|
+
workbenchService;
|
|
59
70
|
constructor(servicesDir, deps, limits,
|
|
60
71
|
/**
|
|
61
72
|
* 只读快照模式:不写索引、不写台账。
|
|
@@ -72,6 +83,9 @@ export class ServiceRouter {
|
|
|
72
83
|
this.packs = buildPackState([], [], this.identity);
|
|
73
84
|
this.scriptRunner = new ServiceScriptRunner(deps);
|
|
74
85
|
this.dispatcher = new ServiceDispatcher(this.scriptRunner, limits);
|
|
86
|
+
this.outputService = deps.outputService ?? new OutputService(deps.aid);
|
|
87
|
+
this.outputCardsService = new OutputCardsService(deps.aid);
|
|
88
|
+
this.workbenchService = deps.workbenchService ?? new WorkbenchService(deps.aid, { offline: readonlySnapshot });
|
|
75
89
|
}
|
|
76
90
|
/** 首次加载:读 services-config.json + 扫描包。identity 必须已就绪。重复调用只更新 identity。 */
|
|
77
91
|
ensureStarted(identity) {
|
|
@@ -80,6 +94,14 @@ export class ServiceRouter {
|
|
|
80
94
|
return;
|
|
81
95
|
this.reload();
|
|
82
96
|
this.started = true;
|
|
97
|
+
// ACL 兜底层自愈:存量包(加固逻辑上线前装的、或目录从别的机器拷贝来的)在这里收敛,
|
|
98
|
+
// 新包由 `pack add` 当场处理。用户不需要知道 ACL 存在。
|
|
99
|
+
//
|
|
100
|
+
// 异步 + 进程内去重:调度立即返回(实测 0ms),加固在后台子进程里跑,
|
|
101
|
+
// 不阻塞启动、不阻塞包执行。只读快照(offline router)不参与,查询不该改磁盘状态。
|
|
102
|
+
if (!this.readonlySnapshot) {
|
|
103
|
+
scheduleServicesAclHarden(this.servicesDir, message => logger.warn(`[Services] ${message}`));
|
|
104
|
+
}
|
|
83
105
|
}
|
|
84
106
|
/** 重新加载 services-config.json 与全部包(ec services reload / 热重载用)。 */
|
|
85
107
|
reload() {
|
|
@@ -204,6 +226,30 @@ export class ServiceRouter {
|
|
|
204
226
|
this.rejectLedger('BLOCKED', type, message);
|
|
205
227
|
return buildSilentReply(type, message.requestId);
|
|
206
228
|
}
|
|
229
|
+
if (isOutputType(type) || isOutputCardsType(type) || isWorkbenchType(type)) {
|
|
230
|
+
if (options.admission === 'not_authorized')
|
|
231
|
+
return this.unauthorizedReply(type, message, 'business');
|
|
232
|
+
const rule = this.callRuleFor(type);
|
|
233
|
+
if (rule?.deny.includes(message.fromAid))
|
|
234
|
+
return this.unauthorizedReply(type, message, 'business');
|
|
235
|
+
const limit = this.limiter.consume('service', message.fromAid);
|
|
236
|
+
if (!limit.allow)
|
|
237
|
+
return buildErrorReply(type, message.requestId, 'RATE_LIMITED', 'Output query rate exceeded');
|
|
238
|
+
try {
|
|
239
|
+
const data = isWorkbenchType(type)
|
|
240
|
+
? await this.workbenchService.handle(message)
|
|
241
|
+
: isOutputCardsType(type)
|
|
242
|
+
? await this.outputCardsService.handle(message)
|
|
243
|
+
: await this.outputService.handle(message);
|
|
244
|
+
return buildSuccessReply(type, message.requestId, data);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
if (error instanceof DataRootError) {
|
|
248
|
+
return buildErrorReply(type, message.requestId, error.code, error.message, error.data);
|
|
249
|
+
}
|
|
250
|
+
return buildErrorReply(type, message.requestId, isWorkbenchType(type) ? 'WORKBENCH_UNAVAILABLE' : 'OUTPUT_UNAVAILABLE', errorMessage(error));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
207
253
|
// 保留字:整条 type 精确相等才算,两段形式。内置查询已在内部按准入分级。
|
|
208
254
|
if (isReservedServiceType(type)) {
|
|
209
255
|
return this.handleBuiltin(type, message, options);
|
|
@@ -375,7 +421,7 @@ export class ServiceRouter {
|
|
|
375
421
|
* - `describe` / `schema` / `skill`(带 service)会带出 pack、脚本路径、timeout,
|
|
376
422
|
* 未准入一律走统一拒绝,与业务调用的回包完全一致,不构成"这个 type 存不存在"的信道。
|
|
377
423
|
*/
|
|
378
|
-
handleBuiltin(type, message, options) {
|
|
424
|
+
async handleBuiltin(type, message, options) {
|
|
379
425
|
// handleRequest 已在更外层挡掉 blocked;这里再挡一次是给直调本方法的测试兜底。
|
|
380
426
|
if (options.admission === 'blocked')
|
|
381
427
|
return buildSilentReply(type, message.requestId);
|
|
@@ -402,17 +448,41 @@ export class ServiceRouter {
|
|
|
402
448
|
}
|
|
403
449
|
return this.unauthorizedReply(type, message, 'builtin');
|
|
404
450
|
}
|
|
451
|
+
let outputAuthorized = false;
|
|
452
|
+
try {
|
|
453
|
+
await this.outputService.authorize(message);
|
|
454
|
+
outputAuthorized = true;
|
|
455
|
+
}
|
|
456
|
+
catch { /* no private capability disclosure */ }
|
|
457
|
+
const outputs = outputAuthorized ? this.outputDescriptions() : [];
|
|
458
|
+
let workbenchAuthorized = false;
|
|
459
|
+
try {
|
|
460
|
+
await this.workbenchService.authorize(message);
|
|
461
|
+
workbenchAuthorized = true;
|
|
462
|
+
}
|
|
463
|
+
catch { /* private capabilities */ }
|
|
464
|
+
const native = [...outputs, ...(workbenchAuthorized ? this.workbenchDescriptions() : [])];
|
|
465
|
+
const requestedService = readStringField(message.payload, 'service');
|
|
466
|
+
if (requestedService && (isOutputType(requestedService) || isOutputCardsType(requestedService)) && !outputAuthorized) {
|
|
467
|
+
return buildErrorReply(type, message.requestId, 'OUTPUT_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
468
|
+
}
|
|
469
|
+
if (requestedService && isWorkbenchType(requestedService) && !workbenchAuthorized) {
|
|
470
|
+
return buildErrorReply(type, message.requestId, 'WORKBENCH_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
471
|
+
}
|
|
405
472
|
switch (type) {
|
|
406
473
|
case 'services.list':
|
|
407
474
|
return buildSuccessReply(type, message.requestId, {
|
|
408
|
-
services: this.describeAll(),
|
|
475
|
+
services: [...this.describeAll(), ...native],
|
|
409
476
|
builtin: [...RESERVED_TYPES],
|
|
410
477
|
});
|
|
411
478
|
case 'services.describe': {
|
|
412
479
|
const target = readStringField(message.payload, 'service');
|
|
413
480
|
// 不带 service 时退化为清单:与 `ec services describe <aid>` 的语义一致。
|
|
414
481
|
if (!target)
|
|
415
|
-
return buildSuccessReply(type, message.requestId, { services: this.describeAll(), builtin: [...RESERVED_TYPES] });
|
|
482
|
+
return buildSuccessReply(type, message.requestId, { services: [...this.describeAll(), ...native], builtin: [...RESERVED_TYPES] });
|
|
483
|
+
const output = native.find(item => Array.isArray(item.types) && item.types.includes(target));
|
|
484
|
+
if (output)
|
|
485
|
+
return buildSuccessReply(type, message.requestId, output);
|
|
416
486
|
const described = this.describeOne(target);
|
|
417
487
|
if (!described)
|
|
418
488
|
return buildErrorReply(type, message.requestId, 'UNKNOWN_TYPE', `no service accepts ${target}`);
|
|
@@ -422,6 +492,18 @@ export class ServiceRouter {
|
|
|
422
492
|
const target = readStringField(message.payload, 'service');
|
|
423
493
|
if (!target)
|
|
424
494
|
return buildErrorReply(type, message.requestId, 'INVALID_ARGUMENT', 'services.schema requires data.service (a services.* type)');
|
|
495
|
+
if (isWorkbenchType(target))
|
|
496
|
+
return buildSuccessReply(type, message.requestId, {
|
|
497
|
+
type: target, schema: workbenchRequestSchema(target), responseDataSchema: workbenchResponseSchema(target),
|
|
498
|
+
});
|
|
499
|
+
if (isOutputCardsType(target))
|
|
500
|
+
return buildSuccessReply(type, message.requestId, {
|
|
501
|
+
type: target, schema: outputCardsRequestSchema(target), responseDataSchema: outputCardsResponseSchema(),
|
|
502
|
+
});
|
|
503
|
+
if (isOutputType(target))
|
|
504
|
+
return buildSuccessReply(type, message.requestId, {
|
|
505
|
+
type: target, schema: outputRequestSchema(target), responseDataSchema: outputResponseSchema(),
|
|
506
|
+
});
|
|
425
507
|
const described = this.describeOne(target);
|
|
426
508
|
if (!described)
|
|
427
509
|
return buildErrorReply(type, message.requestId, 'UNKNOWN_TYPE', `no service accepts ${target}`);
|
|
@@ -431,6 +513,15 @@ export class ServiceRouter {
|
|
|
431
513
|
const target = readStringField(message.payload, 'service');
|
|
432
514
|
if (!target)
|
|
433
515
|
return buildErrorReply(type, message.requestId, 'INVALID_ARGUMENT', 'services.skill requires data.service');
|
|
516
|
+
if (isWorkbenchType(target))
|
|
517
|
+
return buildSuccessReply(type, message.requestId, { type: target,
|
|
518
|
+
skill: 'Read-only Owner-private workbench. Requires encrypted AUN and the current verified protocol Owner. Send protocolVersion:1. Snapshot includes current tasks and retained past executions only; no future schedules. Subscribe to team.workbench.changed on the same Bus and read changes when invalidated. Results are bounded; follow history nextCursor, reset on INDEX_CHANGED. Never poll. Task details use the existing Activity command with taskId.' });
|
|
519
|
+
if (isOutputCardsType(target))
|
|
520
|
+
return buildSuccessReply(type, message.requestId, { type: target,
|
|
521
|
+
skill: 'Owner-authorized output card projection. Cards are declaration-only metadata linked to real files in this Agent output. Use services.outputs.cards.snapshot/list/detail/changes, follow nextCursor, and reset on INDEX_CHANGED. Never poll. Publish or remove cards with ec team cards after referenced files are complete.' });
|
|
522
|
+
if (isOutputType(target))
|
|
523
|
+
return buildSuccessReply(type, message.requestId, { type: target,
|
|
524
|
+
skill: 'Read-only fixed Agent output. Requires encrypted AUN and current verified protocol Owner. Send protocolVersion:1 and the schema-defined data fields. Results are bounded; follow nextCursor and reset on INDEX_CHANGED. No periodic reads.' });
|
|
434
525
|
const described = this.describeOne(target);
|
|
435
526
|
if (!described)
|
|
436
527
|
return buildErrorReply(type, message.requestId, 'UNKNOWN_TYPE', `no service accepts ${target}`);
|
|
@@ -539,10 +630,28 @@ export class ServiceRouter {
|
|
|
539
630
|
*/
|
|
540
631
|
close() {
|
|
541
632
|
this.dispatcher.close();
|
|
633
|
+
void this.outputService.close();
|
|
634
|
+
this.outputCardsService.close();
|
|
635
|
+
this.workbenchService.close();
|
|
636
|
+
}
|
|
637
|
+
outputDescriptions() {
|
|
638
|
+
return [{
|
|
639
|
+
pack: 'builtin.outputs', name: 'Agent output projection',
|
|
640
|
+
description: 'Owner-authorized read-only Agent output snapshots and changes',
|
|
641
|
+
types: ['services.outputs.snapshot', 'services.outputs.list', 'services.outputs.detail', 'services.outputs.changes', ...OUTPUT_CARDS_TYPES],
|
|
642
|
+
unmatched: 'silent', reply: true,
|
|
643
|
+
}];
|
|
644
|
+
}
|
|
645
|
+
workbenchDescriptions() {
|
|
646
|
+
return [{ pack: 'builtin.workbench', name: 'Team workbench projection',
|
|
647
|
+
description: 'Owner-authorized current tasks, retained execution history and event-driven changes',
|
|
648
|
+
types: WORKBENCH_TYPES, unmatched: 'silent', reply: true }];
|
|
542
649
|
}
|
|
543
650
|
}
|
|
544
651
|
function readStringField(payload, key) {
|
|
545
|
-
const
|
|
652
|
+
const data = payload.data;
|
|
653
|
+
const value = payload[key] ?? (data && typeof data === 'object' && !Array.isArray(data)
|
|
654
|
+
? data[key] : undefined);
|
|
546
655
|
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
547
656
|
}
|
|
548
657
|
/**
|