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
package/dist/services/index.js
CHANGED
|
@@ -19,6 +19,12 @@ import { RateWindow } from '../core/rate-window.js';
|
|
|
19
19
|
import { ServiceScriptRunner } from './script-runner.js';
|
|
20
20
|
import { buildErrorReply, buildSilentReply, buildSuccessReply, replyFromOutcome, isReservedServiceType, matchesListen, RESERVED_TYPES, } from './service-payload.js';
|
|
21
21
|
import { errorMessage } from './types.js';
|
|
22
|
+
import { isOutputType } from '../outputs/protocol.js';
|
|
23
|
+
import { outputRequestSchema, outputResponseSchema } from '../outputs/protocol.js';
|
|
24
|
+
import { OutputService } from '../outputs/service.js';
|
|
25
|
+
import { DataRootError } from '../core/command/team-workspace-store.js';
|
|
26
|
+
import { isWorkbenchType, WORKBENCH_TYPES, workbenchRequestSchema, workbenchResponseSchema } from '../workbench/protocol.js';
|
|
27
|
+
import { WorkbenchService } from '../workbench/service.js';
|
|
22
28
|
export { classifyServicePayloadType, parseServiceType, isReservedServiceType, RESERVED_TYPES } from './service-payload.js';
|
|
23
29
|
export { readLocalSelfIdentity } from './identity.js';
|
|
24
30
|
/**
|
|
@@ -56,6 +62,8 @@ export class ServiceRouter {
|
|
|
56
62
|
/** fromAid → 上次告知未准入的时间;窗口内重复调用静默。 */
|
|
57
63
|
unauthorizedNotified = new Map();
|
|
58
64
|
started = false;
|
|
65
|
+
outputService;
|
|
66
|
+
workbenchService;
|
|
59
67
|
constructor(servicesDir, deps, limits,
|
|
60
68
|
/**
|
|
61
69
|
* 只读快照模式:不写索引、不写台账。
|
|
@@ -72,6 +80,8 @@ export class ServiceRouter {
|
|
|
72
80
|
this.packs = buildPackState([], [], this.identity);
|
|
73
81
|
this.scriptRunner = new ServiceScriptRunner(deps);
|
|
74
82
|
this.dispatcher = new ServiceDispatcher(this.scriptRunner, limits);
|
|
83
|
+
this.outputService = deps.outputService ?? new OutputService(deps.aid);
|
|
84
|
+
this.workbenchService = deps.workbenchService ?? new WorkbenchService(deps.aid, { offline: readonlySnapshot });
|
|
75
85
|
}
|
|
76
86
|
/** 首次加载:读 services-config.json + 扫描包。identity 必须已就绪。重复调用只更新 identity。 */
|
|
77
87
|
ensureStarted(identity) {
|
|
@@ -204,6 +214,26 @@ export class ServiceRouter {
|
|
|
204
214
|
this.rejectLedger('BLOCKED', type, message);
|
|
205
215
|
return buildSilentReply(type, message.requestId);
|
|
206
216
|
}
|
|
217
|
+
if (isOutputType(type) || isWorkbenchType(type)) {
|
|
218
|
+
if (options.admission === 'not_authorized')
|
|
219
|
+
return this.unauthorizedReply(type, message, 'business');
|
|
220
|
+
const rule = this.callRuleFor(type);
|
|
221
|
+
if (rule?.deny.includes(message.fromAid))
|
|
222
|
+
return this.unauthorizedReply(type, message, 'business');
|
|
223
|
+
const limit = this.limiter.consume('service', message.fromAid);
|
|
224
|
+
if (!limit.allow)
|
|
225
|
+
return buildErrorReply(type, message.requestId, 'RATE_LIMITED', 'Output query rate exceeded');
|
|
226
|
+
try {
|
|
227
|
+
const data = await (isWorkbenchType(type) ? this.workbenchService : this.outputService).handle(message);
|
|
228
|
+
return buildSuccessReply(type, message.requestId, data);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (error instanceof DataRootError) {
|
|
232
|
+
return buildErrorReply(type, message.requestId, error.code, error.message, error.data);
|
|
233
|
+
}
|
|
234
|
+
return buildErrorReply(type, message.requestId, isWorkbenchType(type) ? 'WORKBENCH_UNAVAILABLE' : 'OUTPUT_UNAVAILABLE', errorMessage(error));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
207
237
|
// 保留字:整条 type 精确相等才算,两段形式。内置查询已在内部按准入分级。
|
|
208
238
|
if (isReservedServiceType(type)) {
|
|
209
239
|
return this.handleBuiltin(type, message, options);
|
|
@@ -375,7 +405,7 @@ export class ServiceRouter {
|
|
|
375
405
|
* - `describe` / `schema` / `skill`(带 service)会带出 pack、脚本路径、timeout,
|
|
376
406
|
* 未准入一律走统一拒绝,与业务调用的回包完全一致,不构成"这个 type 存不存在"的信道。
|
|
377
407
|
*/
|
|
378
|
-
handleBuiltin(type, message, options) {
|
|
408
|
+
async handleBuiltin(type, message, options) {
|
|
379
409
|
// handleRequest 已在更外层挡掉 blocked;这里再挡一次是给直调本方法的测试兜底。
|
|
380
410
|
if (options.admission === 'blocked')
|
|
381
411
|
return buildSilentReply(type, message.requestId);
|
|
@@ -402,17 +432,41 @@ export class ServiceRouter {
|
|
|
402
432
|
}
|
|
403
433
|
return this.unauthorizedReply(type, message, 'builtin');
|
|
404
434
|
}
|
|
435
|
+
let outputAuthorized = false;
|
|
436
|
+
try {
|
|
437
|
+
await this.outputService.authorize(message);
|
|
438
|
+
outputAuthorized = true;
|
|
439
|
+
}
|
|
440
|
+
catch { /* no private capability disclosure */ }
|
|
441
|
+
const outputs = outputAuthorized ? this.outputDescriptions() : [];
|
|
442
|
+
let workbenchAuthorized = false;
|
|
443
|
+
try {
|
|
444
|
+
await this.workbenchService.authorize(message);
|
|
445
|
+
workbenchAuthorized = true;
|
|
446
|
+
}
|
|
447
|
+
catch { /* private capabilities */ }
|
|
448
|
+
const native = [...outputs, ...(workbenchAuthorized ? this.workbenchDescriptions() : [])];
|
|
449
|
+
const requestedService = readStringField(message.payload, 'service');
|
|
450
|
+
if (requestedService && isOutputType(requestedService) && !outputAuthorized) {
|
|
451
|
+
return buildErrorReply(type, message.requestId, 'OUTPUT_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
452
|
+
}
|
|
453
|
+
if (requestedService && isWorkbenchType(requestedService) && !workbenchAuthorized) {
|
|
454
|
+
return buildErrorReply(type, message.requestId, 'WORKBENCH_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
455
|
+
}
|
|
405
456
|
switch (type) {
|
|
406
457
|
case 'services.list':
|
|
407
458
|
return buildSuccessReply(type, message.requestId, {
|
|
408
|
-
services: this.describeAll(),
|
|
459
|
+
services: [...this.describeAll(), ...native],
|
|
409
460
|
builtin: [...RESERVED_TYPES],
|
|
410
461
|
});
|
|
411
462
|
case 'services.describe': {
|
|
412
463
|
const target = readStringField(message.payload, 'service');
|
|
413
464
|
// 不带 service 时退化为清单:与 `ec services describe <aid>` 的语义一致。
|
|
414
465
|
if (!target)
|
|
415
|
-
return buildSuccessReply(type, message.requestId, { services: this.describeAll(), builtin: [...RESERVED_TYPES] });
|
|
466
|
+
return buildSuccessReply(type, message.requestId, { services: [...this.describeAll(), ...native], builtin: [...RESERVED_TYPES] });
|
|
467
|
+
const output = native.find(item => Array.isArray(item.types) && item.types.includes(target));
|
|
468
|
+
if (output)
|
|
469
|
+
return buildSuccessReply(type, message.requestId, output);
|
|
416
470
|
const described = this.describeOne(target);
|
|
417
471
|
if (!described)
|
|
418
472
|
return buildErrorReply(type, message.requestId, 'UNKNOWN_TYPE', `no service accepts ${target}`);
|
|
@@ -422,6 +476,14 @@ export class ServiceRouter {
|
|
|
422
476
|
const target = readStringField(message.payload, 'service');
|
|
423
477
|
if (!target)
|
|
424
478
|
return buildErrorReply(type, message.requestId, 'INVALID_ARGUMENT', 'services.schema requires data.service (a services.* type)');
|
|
479
|
+
if (isWorkbenchType(target))
|
|
480
|
+
return buildSuccessReply(type, message.requestId, {
|
|
481
|
+
type: target, schema: workbenchRequestSchema(target), responseDataSchema: workbenchResponseSchema(target),
|
|
482
|
+
});
|
|
483
|
+
if (isOutputType(target))
|
|
484
|
+
return buildSuccessReply(type, message.requestId, {
|
|
485
|
+
type: target, schema: outputRequestSchema(target), responseDataSchema: outputResponseSchema(),
|
|
486
|
+
});
|
|
425
487
|
const described = this.describeOne(target);
|
|
426
488
|
if (!described)
|
|
427
489
|
return buildErrorReply(type, message.requestId, 'UNKNOWN_TYPE', `no service accepts ${target}`);
|
|
@@ -431,6 +493,12 @@ export class ServiceRouter {
|
|
|
431
493
|
const target = readStringField(message.payload, 'service');
|
|
432
494
|
if (!target)
|
|
433
495
|
return buildErrorReply(type, message.requestId, 'INVALID_ARGUMENT', 'services.skill requires data.service');
|
|
496
|
+
if (isWorkbenchType(target))
|
|
497
|
+
return buildSuccessReply(type, message.requestId, { type: target,
|
|
498
|
+
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.' });
|
|
499
|
+
if (isOutputType(target))
|
|
500
|
+
return buildSuccessReply(type, message.requestId, { type: target,
|
|
501
|
+
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
502
|
const described = this.describeOne(target);
|
|
435
503
|
if (!described)
|
|
436
504
|
return buildErrorReply(type, message.requestId, 'UNKNOWN_TYPE', `no service accepts ${target}`);
|
|
@@ -539,10 +607,27 @@ export class ServiceRouter {
|
|
|
539
607
|
*/
|
|
540
608
|
close() {
|
|
541
609
|
this.dispatcher.close();
|
|
610
|
+
void this.outputService.close();
|
|
611
|
+
this.workbenchService.close();
|
|
612
|
+
}
|
|
613
|
+
outputDescriptions() {
|
|
614
|
+
return [{
|
|
615
|
+
pack: 'builtin.outputs', name: 'Agent output projection',
|
|
616
|
+
description: 'Owner-authorized read-only Agent output snapshots and changes',
|
|
617
|
+
types: ['services.outputs.snapshot', 'services.outputs.list', 'services.outputs.detail', 'services.outputs.changes'],
|
|
618
|
+
unmatched: 'silent', reply: true,
|
|
619
|
+
}];
|
|
620
|
+
}
|
|
621
|
+
workbenchDescriptions() {
|
|
622
|
+
return [{ pack: 'builtin.workbench', name: 'Team workbench projection',
|
|
623
|
+
description: 'Owner-authorized current tasks, retained execution history and event-driven changes',
|
|
624
|
+
types: WORKBENCH_TYPES, unmatched: 'silent', reply: true }];
|
|
542
625
|
}
|
|
543
626
|
}
|
|
544
627
|
function readStringField(payload, key) {
|
|
545
|
-
const
|
|
628
|
+
const data = payload.data;
|
|
629
|
+
const value = payload[key] ?? (data && typeof data === 'object' && !Array.isArray(data)
|
|
630
|
+
? data[key] : undefined);
|
|
546
631
|
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
547
632
|
}
|
|
548
633
|
/**
|
|
@@ -14,7 +14,7 @@ import { agentServicesDir, resolveRoot } from '../paths.js';
|
|
|
14
14
|
import { classifyProtectedPath } from '../core/permission/protected-paths.js';
|
|
15
15
|
import { ServiceLedger } from '../core/pack-ledger.js';
|
|
16
16
|
import { ServiceMessageLog } from './message-log.js';
|
|
17
|
-
import { SERVICES_CONFIG_JSON, loadRouterConfig, ServiceRulesStore } from './router.js';
|
|
17
|
+
import { DEFAULT_ROUTER_CONFIG, SERVICES_CONFIG_JSON, loadRouterConfig, ServiceRulesStore } from './router.js';
|
|
18
18
|
import { PACK_JSON } from './pack-manager.js';
|
|
19
19
|
import { readLocalSelfIdentity } from './identity.js';
|
|
20
20
|
import { createOfflineServiceRouter, listServiceRouterAids, peekServiceRouter, } from './index.js';
|
|
@@ -388,25 +388,14 @@ async function execute(deps, parsed) {
|
|
|
388
388
|
manifestFile: PACK_JSON,
|
|
389
389
|
legacyManifestFile: 'service.json',
|
|
390
390
|
});
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
// 不能自动开:总闸是"这个 AID 是否对外提供服务的整机决策",需要
|
|
394
|
-
// daemonOwner + fullaccess 显式执行 `ec services enable`。装包只是把文件
|
|
395
|
-
// 放到位(owner/admin 即可),自动开机等于让装包顺带绕过那道闸。
|
|
396
|
-
//
|
|
397
|
-
// 仍然落盘而不是留空:`loadRouterConfig` 对缺失文件返回缺省 enabled=false,
|
|
398
|
-
// 行为一样,但文件存在才可发现——否则用户只会看到"服务不通"。
|
|
391
|
+
// 首次装包沿用 Agent 的默认开启策略。已有配置(包括显式关闭)原样保留,
|
|
392
|
+
// 装包不能顺带修改总闸;请求仍经过准入、权限、限流与沙箱检查。
|
|
399
393
|
const routerPath = path.join(servicesDirForPack, SERVICES_CONFIG_JSON);
|
|
400
394
|
let createdRouter = false;
|
|
401
395
|
if (!fs.existsSync(routerPath)) {
|
|
402
396
|
fs.mkdirSync(servicesDirForPack, { recursive: true });
|
|
403
397
|
fs.writeFileSync(routerPath, `${JSON.stringify({
|
|
404
|
-
|
|
405
|
-
enabled: false,
|
|
406
|
-
rateLimit: {
|
|
407
|
-
builtin: { perMinute: 20, perHour: 200 },
|
|
408
|
-
service: { perMinute: 50, perHour: 1000 },
|
|
409
|
-
},
|
|
398
|
+
...DEFAULT_ROUTER_CONFIG,
|
|
410
399
|
}, null, 2)}
|
|
411
400
|
`, 'utf8');
|
|
412
401
|
createdRouter = true;
|
|
@@ -157,7 +157,18 @@ export function buildPackState(packs, invalidPacks, identity) {
|
|
|
157
157
|
const candidates = packs.filter(pack => pack.enabled);
|
|
158
158
|
const skippedPacks = [];
|
|
159
159
|
const activeCandidates = [];
|
|
160
|
+
const reservedOutputInvalid = [];
|
|
160
161
|
for (const pack of candidates) {
|
|
162
|
+
const reserved = pack.listen.filter(entry => entry.type === 'services.outputs.snapshot' || entry.type === 'services.outputs.list'
|
|
163
|
+
|| entry.type === 'services.outputs.detail' || entry.type === 'services.outputs.changes'
|
|
164
|
+
|| entry.type === 'services.outputs.*' || entry.type.startsWith('services.workbench.'));
|
|
165
|
+
if (reserved.length) {
|
|
166
|
+
reservedOutputInvalid.push({
|
|
167
|
+
id: pack.id,
|
|
168
|
+
errors: [`reserved native output/workbench service type cannot be declared: ${reserved.map(entry => entry.type).join(', ')}`],
|
|
169
|
+
});
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
161
172
|
if (requiresSatisfied(pack.requires, identity))
|
|
162
173
|
activeCandidates.push(pack);
|
|
163
174
|
else
|
|
@@ -233,7 +244,7 @@ export function buildPackState(packs, invalidPacks, identity) {
|
|
|
233
244
|
activePacks,
|
|
234
245
|
skippedPacks,
|
|
235
246
|
disabledPacks,
|
|
236
|
-
invalidPacks: [...invalidPacks, ...conflictInvalid],
|
|
247
|
+
invalidPacks: [...invalidPacks, ...reservedOutputInvalid, ...conflictInvalid],
|
|
237
248
|
conflicts,
|
|
238
249
|
overlaps,
|
|
239
250
|
routeIndex,
|
package/dist/services/router.js
CHANGED
|
@@ -15,14 +15,25 @@ import { RESERVED_TYPES } from './service-payload.js';
|
|
|
15
15
|
export const SERVICES_CONFIG_JSON = 'services-config.json';
|
|
16
16
|
export const DEFAULT_ROUTER_CONFIG = {
|
|
17
17
|
v: 1,
|
|
18
|
-
enabled:
|
|
18
|
+
enabled: true,
|
|
19
19
|
rateLimit: {
|
|
20
20
|
builtin: { perMinute: 20, perHour: 200 },
|
|
21
21
|
service: { perMinute: 50, perHour: 1000 },
|
|
22
22
|
},
|
|
23
23
|
rules: {},
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
function defaultConfig(enabled = true) {
|
|
26
|
+
return {
|
|
27
|
+
...DEFAULT_ROUTER_CONFIG,
|
|
28
|
+
enabled,
|
|
29
|
+
rateLimit: {
|
|
30
|
+
builtin: { ...DEFAULT_ROUTER_CONFIG.rateLimit.builtin },
|
|
31
|
+
service: { ...DEFAULT_ROUTER_CONFIG.rateLimit.service },
|
|
32
|
+
},
|
|
33
|
+
rules: {},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** 缺少配置时默认开启;显式关闭和非法/不可读配置仍关闭。 */
|
|
26
37
|
export function loadRouterConfig(servicesDir) {
|
|
27
38
|
// 旧名 router.json 一次性迁移成 services-config.json。
|
|
28
39
|
migrateLegacyFileName(servicesDir, 'router.json', SERVICES_CONFIG_JSON, 'services config');
|
|
@@ -31,8 +42,12 @@ export function loadRouterConfig(servicesDir) {
|
|
|
31
42
|
try {
|
|
32
43
|
rawText = fs.readFileSync(filePath, 'utf8');
|
|
33
44
|
}
|
|
34
|
-
catch {
|
|
35
|
-
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === 'ENOENT') {
|
|
47
|
+
return { config: defaultConfig(), exists: false, errors: [] };
|
|
48
|
+
}
|
|
49
|
+
return { config: defaultConfig(false), exists: true,
|
|
50
|
+
errors: [`Cannot read ${SERVICES_CONFIG_JSON}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
36
51
|
}
|
|
37
52
|
let raw;
|
|
38
53
|
try {
|
|
@@ -40,14 +55,14 @@ export function loadRouterConfig(servicesDir) {
|
|
|
40
55
|
}
|
|
41
56
|
catch (error) {
|
|
42
57
|
return {
|
|
43
|
-
config:
|
|
58
|
+
config: defaultConfig(false),
|
|
44
59
|
exists: true,
|
|
45
60
|
errors: [`${SERVICES_CONFIG_JSON} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`],
|
|
46
61
|
};
|
|
47
62
|
}
|
|
48
63
|
const validated = validateRouterConfig(raw);
|
|
49
64
|
if (!validated.ok)
|
|
50
|
-
return { config:
|
|
65
|
+
return { config: defaultConfig(false), exists: true, errors: validated.errors };
|
|
51
66
|
return { config: validated.value, exists: true, errors: [] };
|
|
52
67
|
}
|
|
53
68
|
/**
|
|
@@ -75,7 +75,9 @@ export class ServiceScriptRunner {
|
|
|
75
75
|
const scriptPath = path.join(pack.paths.scriptsDir, handler.script.slice(SCRIPTS_DIR.length + 1));
|
|
76
76
|
const scriptArgs = handler.args ?? [];
|
|
77
77
|
cmd = [executable, scriptPath, ...scriptArgs].join(' ');
|
|
78
|
-
|
|
78
|
+
const built = this.buildLaunch(pack, handler, message, executable, scriptPath, scriptArgs);
|
|
79
|
+
// Unsandboxed launches have no directory preparation or new authorization gap.
|
|
80
|
+
launch = built instanceof Promise ? await built : built;
|
|
79
81
|
if (launch.prepare) {
|
|
80
82
|
try {
|
|
81
83
|
// 探针必须设上限:沙箱 provisioning 挂住时这里会无限等待,dispatcher 的
|
|
@@ -177,15 +179,14 @@ export class ServiceScriptRunner {
|
|
|
177
179
|
permissionMode: effective,
|
|
178
180
|
};
|
|
179
181
|
const trigger = this.syntheticTrigger(pack, handler, executable);
|
|
180
|
-
|
|
182
|
+
return buildTriggerScriptLaunch({
|
|
181
183
|
trigger,
|
|
182
184
|
triggerDir: pack.dir,
|
|
183
185
|
scriptPath,
|
|
184
186
|
scriptArgs,
|
|
185
187
|
projectPath,
|
|
186
188
|
executionAuthorization: authorization,
|
|
187
|
-
});
|
|
188
|
-
return { ...launch, env: { ...launch.env, ...ecEnv } };
|
|
189
|
+
}).then(launch => ({ ...launch, env: { ...launch.env, ...ecEnv } }));
|
|
189
190
|
}
|
|
190
191
|
buildEcEnv(pack, message) {
|
|
191
192
|
return {
|
package/dist/stats/budget.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import { calcCost } from './
|
|
6
|
+
import { calcCost } from './model-resolver.js';
|
|
7
7
|
import { openReadonlyDb, getDbPath } from './db.js';
|
|
8
8
|
function loadBudgets(evolcoreHome) {
|
|
9
9
|
const file = path.join(evolcoreHome, 'data', 'stats', 'budgets.json');
|
package/dist/stats/db.js
CHANGED
|
@@ -136,6 +136,8 @@ function _initTables(db) {
|
|
|
136
136
|
peer_type TEXT,
|
|
137
137
|
session_id TEXT,
|
|
138
138
|
model TEXT NOT NULL,
|
|
139
|
+
provider_id TEXT,
|
|
140
|
+
base_url TEXT,
|
|
139
141
|
billing_fn TEXT NOT NULL,
|
|
140
142
|
input_tokens INTEGER NOT NULL DEFAULT 0,
|
|
141
143
|
output_tokens INTEGER NOT NULL DEFAULT 0,
|
|
@@ -254,6 +256,8 @@ function _initTables(db) {
|
|
|
254
256
|
peer_key TEXT NOT NULL,
|
|
255
257
|
call_index INTEGER NOT NULL,
|
|
256
258
|
model TEXT NOT NULL,
|
|
259
|
+
provider_id TEXT,
|
|
260
|
+
base_url TEXT,
|
|
257
261
|
source TEXT NOT NULL DEFAULT 'request',
|
|
258
262
|
provider_thread_id TEXT,
|
|
259
263
|
request_id TEXT,
|
|
@@ -306,6 +310,15 @@ function _initTables(db) {
|
|
|
306
310
|
if (!cols.some(c => c.name === 'role')) {
|
|
307
311
|
db.exec(`ALTER TABLE usage_events ADD COLUMN role TEXT NOT NULL DEFAULT ''`);
|
|
308
312
|
}
|
|
313
|
+
// provider 维度:区分一次调用实际走的端点(官方 / 中转 / 本地代理)。
|
|
314
|
+
// 历史行为 NULL,表示“未记录”,报告按此标注。
|
|
315
|
+
if (!cols.some(c => c.name === 'provider_id')) {
|
|
316
|
+
db.exec(`ALTER TABLE usage_events ADD COLUMN provider_id TEXT`);
|
|
317
|
+
}
|
|
318
|
+
if (!cols.some(c => c.name === 'base_url')) {
|
|
319
|
+
db.exec(`ALTER TABLE usage_events ADD COLUMN base_url TEXT`);
|
|
320
|
+
}
|
|
321
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_ue_provider_ts ON usage_events(provider_id, ts)`);
|
|
309
322
|
db.exec(`CREATE INDEX IF NOT EXISTS idx_ue_role_budget ON usage_events(agent_aid, role, usage_subject_key, ts)`);
|
|
310
323
|
}
|
|
311
324
|
catch (e) {
|
|
@@ -341,6 +354,12 @@ function _initTables(db) {
|
|
|
341
354
|
if (!cols.some(c => c.name === 'auto_compact_tokens')) {
|
|
342
355
|
db.exec(`ALTER TABLE model_calls ADD COLUMN auto_compact_tokens INTEGER`);
|
|
343
356
|
}
|
|
357
|
+
if (!cols.some(c => c.name === 'provider_id')) {
|
|
358
|
+
db.exec(`ALTER TABLE model_calls ADD COLUMN provider_id TEXT`);
|
|
359
|
+
}
|
|
360
|
+
if (!cols.some(c => c.name === 'base_url')) {
|
|
361
|
+
db.exec(`ALTER TABLE model_calls ADD COLUMN base_url TEXT`);
|
|
362
|
+
}
|
|
344
363
|
}
|
|
345
364
|
catch (e) {
|
|
346
365
|
logger.warn(`[StatsDB] model_calls context window 迁移检测失败: ${e}`);
|
package/dist/stats/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export { getDb, openReadonlyDb, getStatsDir, getDbPath, closeStatsDb, archiveOldData, listArchivePaths, rebuildDailyRollup } from './db.js';
|
|
5
5
|
export { normalizeUsage } from './normalizer.js';
|
|
6
6
|
export { initializeStatsPersistence, insertUsageEvent, insertContextBreakdown, insertMessageEvent, insertActivityEvent, insertModelCalls } from './writer.js';
|
|
7
|
-
export { calcCost, resolvePriceRow, resolveCanonicalModel, registerBillingFn } from './
|
|
7
|
+
export { calcCost, resolvePriceRow, resolveCanonicalModel, registerBillingFn } from './model-resolver.js';
|
|
8
8
|
export { queryAggregated, queryTodaySummary, queryStatusActivity, queryStatusActivityByAgent, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryMessageTodaySummary, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls, queryTaskSummary } from './query.js';
|
|
9
9
|
export { getBudgetStatus } from './budget.js';
|
|
10
10
|
export { getRoleBudgetStatus, formatUsageSubjectKey } from './role-budget.js';
|