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
|
@@ -11,6 +11,7 @@ import { ensureInitialRoleRegistry } from '../config/role-service.js';
|
|
|
11
11
|
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
12
12
|
import { getOwners, getPrimaryOwner, ownerResolver } from './ownership/owner-resolver.js';
|
|
13
13
|
import { configuredOwnerList } from '../config/owner-config.js';
|
|
14
|
+
import { assertTemplateInstallationReady } from '../agent-template/jobs.js';
|
|
14
15
|
// ── Channel Fingerprint ───────────────────────────────────────────────────
|
|
15
16
|
// 用于检测多 agent 之间复用同一外部凭证的冲突(appId、aid、token 等)。
|
|
16
17
|
// 格式:{type}:{primaryKey}
|
|
@@ -299,10 +300,11 @@ export class EvolAgentRegistry {
|
|
|
299
300
|
logger.info(`[EvolAgentRegistry] Hot-loaded agent: ${aid}`);
|
|
300
301
|
return agent;
|
|
301
302
|
}
|
|
302
|
-
async reload(aidOrName, hooks) {
|
|
303
|
+
async reload(aidOrName, hooks, options = {}) {
|
|
303
304
|
const oldAgent = this.agents.get(aidOrName);
|
|
304
305
|
if (!oldAgent)
|
|
305
306
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
307
|
+
assertTemplateInstallationReady(oldAgent.aid, options.recoveryJobId);
|
|
306
308
|
await hooks.beforeAgentOperation?.(oldAgent.aid);
|
|
307
309
|
const expandedRaw = loadAgent(oldAgent.aid);
|
|
308
310
|
if (!expandedRaw)
|
|
@@ -316,6 +318,16 @@ export class EvolAgentRegistry {
|
|
|
316
318
|
const raw = readConfig(ConfigTarget.Agent, { self: oldAgent.aid }, { cache: true }) ?? expandedRaw;
|
|
317
319
|
ownerResolver.setAgentConfiguredOwners(oldAgent.aid, configuredOwnerList(raw));
|
|
318
320
|
const merged = resolveEffective({ self: raw.aid }, {});
|
|
321
|
+
if (oldAgent.status === 'disabled' && raw.enabled === false
|
|
322
|
+
|| (options.preserveStopped && oldAgent.status === 'stopped' || options.restoreStopped) && raw.enabled !== false) {
|
|
323
|
+
oldAgent.swapConfig(raw, merged);
|
|
324
|
+
oldAgent.invalidatePersonaCache();
|
|
325
|
+
if (options.restoreStopped && raw.enabled !== false) {
|
|
326
|
+
oldAgent.status = 'stopped';
|
|
327
|
+
this.manuallyStopped.add(oldAgent.aid);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
319
331
|
if (oldAgent.status === 'disabled' && raw.enabled !== false) {
|
|
320
332
|
oldAgent.swapConfig(raw, merged);
|
|
321
333
|
const hotLoad = globalThis.__evolcore_hotLoadAgent;
|
|
@@ -567,6 +579,7 @@ export class EvolAgentRegistry {
|
|
|
567
579
|
}
|
|
568
580
|
async startAgent(aidOrName, hooks) {
|
|
569
581
|
assertAgentAidAvailable(aidOrName);
|
|
582
|
+
assertTemplateInstallationReady(aidOrName);
|
|
570
583
|
const agent = this.agents.get(aidOrName);
|
|
571
584
|
if (!agent)
|
|
572
585
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
@@ -192,6 +192,8 @@ function verifyLocked(filePath, key, opts) {
|
|
|
192
192
|
const db = getDb();
|
|
193
193
|
const row = db.prepare('SELECT sha256, package_version FROM file_integrity WHERE file_path = ?').get(key);
|
|
194
194
|
if (!row) {
|
|
195
|
+
if (opts?.requireRegistered)
|
|
196
|
+
return { status: 'tampered', actual, restorable: false };
|
|
195
197
|
// 用已读字节登记,避免二次读文件时内容已变
|
|
196
198
|
persistBytes(key, bytes, undefined, fs.statSync(filePath).mtime, packageVersion);
|
|
197
199
|
logger.info(`[file-integrity] auto-registered path=${key} sha256=${short(actual)}`);
|
|
@@ -9,7 +9,7 @@ import { recordCausationSpan } from '../causation/audit.js';
|
|
|
9
9
|
import { logger } from '../../utils/logger.js';
|
|
10
10
|
import { setImmediate as yieldToIo } from 'node:timers/promises';
|
|
11
11
|
import { replyContextFromSession } from '../message/message-utils.js';
|
|
12
|
-
import { sessionTopicThreadId } from '../thread/topic-id.js';
|
|
12
|
+
import { safeFormatMainTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
|
|
13
13
|
const HANDOFF_STALE_WARN_MS = 12 * 60 * 60 * 1000;
|
|
14
14
|
const HANDOFF_RETENTION_MS = 72 * 60 * 60 * 1000;
|
|
15
15
|
const HANDOFF_LARGE_AGGREGATE_COUNT = 10;
|
|
@@ -92,12 +92,48 @@ export class HandoffRuntime {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
const targetChatType = input.targetChatType;
|
|
95
|
+
const expectedTarget = input.expectedTarget;
|
|
96
|
+
if (expectedTarget) {
|
|
97
|
+
const targetChannelKeyType = tryParseChannelKey(targetChannelKey)?.type;
|
|
98
|
+
const expectedMainThread = safeFormatMainTopicId(input.selfAid, expectedTarget.channelId);
|
|
99
|
+
const threadMatches = expectedTarget.threadId
|
|
100
|
+
? input.thread === expectedTarget.threadId
|
|
101
|
+
: !input.thread || input.thread === expectedMainThread;
|
|
102
|
+
if (input.to !== expectedTarget.channelId || targetChatType !== expectedTarget.chatType
|
|
103
|
+
|| targetChannelType !== expectedTarget.channelType || targetChannelKeyType !== expectedTarget.channelType
|
|
104
|
+
|| !threadMatches) {
|
|
105
|
+
throw Object.assign(new Error('Handoff request does not match the verified send route'), {
|
|
106
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (expectedTarget.sessionId) {
|
|
110
|
+
const indexedTarget = await this.sessionManager.getSessionById(expectedTarget.sessionId);
|
|
111
|
+
if (!indexedTarget || indexedTarget.selfAID !== input.selfAid
|
|
112
|
+
|| indexedTarget.channelType !== expectedTarget.channelType
|
|
113
|
+
|| indexedTarget.channelId !== expectedTarget.channelId
|
|
114
|
+
|| indexedTarget.chatType !== expectedTarget.chatType
|
|
115
|
+
|| sessionTopicThreadId(indexedTarget) !== expectedTarget.threadId) {
|
|
116
|
+
throw Object.assign(new Error('Indexed handoff session does not match the verified send route'), {
|
|
117
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
95
122
|
const target = await this.sessionManager.getOrCreateSession(targetChannelKey, input.to, origin.projectPath, input.thread, {
|
|
96
123
|
channelKey: targetChannelKey,
|
|
97
124
|
peerId: input.to,
|
|
98
125
|
...(targetChatType === 'group' ? { groupId: input.to } : {}),
|
|
99
126
|
}, undefined, input.to, targetChatType, origin.baseagent, input.selfAid, targetChannelType, targetChatType === 'group' ? 'group' : 'agent');
|
|
100
127
|
throwIfAborted(input.signal);
|
|
128
|
+
const expected = input.expectedTarget;
|
|
129
|
+
if (expected && ((expected.sessionId && target.id !== expected.sessionId)
|
|
130
|
+
|| target.selfAID !== input.selfAid
|
|
131
|
+
|| target.channelType !== expected.channelType || target.channelId !== expected.channelId
|
|
132
|
+
|| target.chatType !== expected.chatType || sessionTopicThreadId(target) !== expected.threadId)) {
|
|
133
|
+
throw Object.assign(new Error('Resolved handoff session does not match the verified send route'), {
|
|
134
|
+
code: 'AUN_OUTBOUND_ROUTE_MISMATCH',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
101
137
|
if (target.id === origin.id) {
|
|
102
138
|
if (input.handoffContext !== undefined)
|
|
103
139
|
throw new Error('handoff context requires a different target session');
|
|
@@ -5,7 +5,7 @@ import { appendRequestPath, appendV1RequestPath } from '../../agents/request-ide
|
|
|
5
5
|
import { assertExplicitProviderModelAllowed, resolveServiceSelection } from '../../config/providers.js';
|
|
6
6
|
import { eligibleServiceFallbackModels } from '../model/model-fallback.js';
|
|
7
7
|
import { RetryScheduler } from '../message/retry-scheduler.js';
|
|
8
|
-
import { classifyError, ErrorType } from '../../utils/error-utils.js';
|
|
8
|
+
import { classifyError, errorQuestionRule, ErrorType } from '../../utils/error-utils.js';
|
|
9
9
|
import { resolveProjectDefaultPath } from '../../utils/project-path.js';
|
|
10
10
|
/** 决策判定用的系统提示词:把 state 与问题一起喂给通用模型,要求只回 JSON。 */
|
|
11
11
|
const DECISION_SYSTEM_PROMPT = 'Evaluate the provided state against each question and its criteria. '
|
|
@@ -75,6 +75,8 @@ async function completeServiceRequest(input) {
|
|
|
75
75
|
input.request.signal?.throwIfAborted();
|
|
76
76
|
if (error?.name === 'AbortError')
|
|
77
77
|
throw error;
|
|
78
|
+
if (errorQuestionRule(error))
|
|
79
|
+
throw error;
|
|
78
80
|
if (classifyError(error) !== ErrorType.MODEL_UNAVAILABLE && error?.status !== 404)
|
|
79
81
|
throw error;
|
|
80
82
|
if (!scheduler) {
|
|
@@ -68,12 +68,14 @@ function qrSvg(payload) {
|
|
|
68
68
|
export class EcwebInitializationService {
|
|
69
69
|
deps;
|
|
70
70
|
agentInitializer;
|
|
71
|
+
runtimeControlAid;
|
|
71
72
|
ownerRecoveryAt = new Map();
|
|
72
73
|
queue = Promise.resolve();
|
|
73
74
|
constructor(deps = {}) {
|
|
74
75
|
this.deps = deps;
|
|
75
76
|
}
|
|
76
77
|
setAgentInitializer(service) { this.agentInitializer = service; }
|
|
78
|
+
setRuntimeControlAid(aid) { this.runtimeControlAid = () => aid; }
|
|
77
79
|
exclusive(action) {
|
|
78
80
|
const result = this.queue.then(action);
|
|
79
81
|
this.queue = result.catch(() => undefined);
|
|
@@ -94,9 +96,10 @@ export class EcwebInitializationService {
|
|
|
94
96
|
fs.chmodSync(file, 0o600);
|
|
95
97
|
}
|
|
96
98
|
read(workflowId) {
|
|
97
|
-
const aid = this.deps.controlAid ? this.deps.controlAid()
|
|
99
|
+
const aid = this.deps.controlAid ? this.deps.controlAid()
|
|
100
|
+
: this.runtimeControlAid ? this.runtimeControlAid() : loadDaemonConfig().aid;
|
|
98
101
|
if (!aid || !isValidAid(aid))
|
|
99
|
-
fail('CONTROL_AID_NOT_READY', '
|
|
102
|
+
fail('CONTROL_AID_NOT_READY', '主机身份待准备,请在本机运行 ec init --web,准备身份并重启后继续', 409);
|
|
100
103
|
let state;
|
|
101
104
|
try {
|
|
102
105
|
state = atomicReadJson(this.file(workflowId));
|
|
@@ -125,7 +128,7 @@ export class EcwebInitializationService {
|
|
|
125
128
|
if (this.deps.refreshOwner)
|
|
126
129
|
return this.deps.refreshOwner(aid, { force });
|
|
127
130
|
const { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } = await import('../ownership/owner-resolver.js');
|
|
128
|
-
return ownerResolver.refresh(aid, { force, maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient:
|
|
131
|
+
return ownerResolver.refresh(aid, { force, maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false, source });
|
|
129
132
|
}
|
|
130
133
|
async bind(aid, owner) {
|
|
131
134
|
if (this.deps.bindOwner)
|
|
@@ -211,7 +214,7 @@ export class EcwebInitializationService {
|
|
|
211
214
|
}
|
|
212
215
|
return defaults;
|
|
213
216
|
}
|
|
214
|
-
async view(state) {
|
|
217
|
+
async view(state, forceOwnership = false) {
|
|
215
218
|
if (state.creation && !state.agent) {
|
|
216
219
|
const { aid, name, project } = state.creation.plan;
|
|
217
220
|
state.agent = { aid, name, project };
|
|
@@ -242,7 +245,9 @@ export class EcwebInitializationService {
|
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
247
|
const bindingPending = !!state.binding?.ownerAid && ['pending', 'unknown'].includes(state.binding.status);
|
|
245
|
-
|
|
248
|
+
// Stable display polls can reuse valid consensus; pending binds need a fresh
|
|
249
|
+
// observation, and mutations retain their separate forced authorization.
|
|
250
|
+
const ownership = await this.ownership(state.controlAid, forceOwnership || bindingPending, bindingPending ? 'initialization.binding' : 'initialization.view');
|
|
246
251
|
const ownerAid = this.applyVerifiedOwner(state, ownership);
|
|
247
252
|
const pending = bindingPending || ['requesting', 'submitted'].includes(ownership.requestStatus ?? '')
|
|
248
253
|
|| (ownership.task?.operation === 'bind' && ownership.task.status === 'pending');
|
|
@@ -432,7 +437,7 @@ export class EcwebInitializationService {
|
|
|
432
437
|
return { status: 200, body: { success: true, data: await this.view(state) } };
|
|
433
438
|
}
|
|
434
439
|
if (input.method === 'POST' && (pathname === '/api/init/binding-sessions' || pathname === '/api/init/binding-sessions/refresh')) {
|
|
435
|
-
const data = await this.view(state);
|
|
440
|
+
const data = await this.view(state, true);
|
|
436
441
|
const ownership = data.ownership;
|
|
437
442
|
if (ownership.status === 'bound')
|
|
438
443
|
return { status: 200, body: { success: true, data } };
|
|
@@ -48,6 +48,7 @@ export class InteractionRouter {
|
|
|
48
48
|
const pending = {
|
|
49
49
|
blocking: opts?.blocking !== false,
|
|
50
50
|
retainOnRejected: opts?.retainOnRejected === true,
|
|
51
|
+
requireEncrypted: opts?.requireEncrypted === true,
|
|
51
52
|
callback,
|
|
52
53
|
sessionId,
|
|
53
54
|
initiatorId: opts?.initiatorId,
|
|
@@ -85,6 +86,8 @@ export class InteractionRouter {
|
|
|
85
86
|
const handler = this.handlers.get(response.id);
|
|
86
87
|
if (!handler)
|
|
87
88
|
return false;
|
|
89
|
+
if (handler.requireEncrypted && response.encrypted !== true)
|
|
90
|
+
return false;
|
|
88
91
|
// Initiator 校验(集中式 backstop):非发起者的操作直接丢弃,不消费 handler、不解除等待,
|
|
89
92
|
// 让真正的发起者仍可继续操作。身份只信渠道传入的已认证 operatorId(来自消息信封,非 payload 自报)。
|
|
90
93
|
// 渠道层若已自行校验(如飞书的 reject toast),此处不会重复命中(operatorId 已匹配)。
|
|
@@ -13,7 +13,7 @@ async function fetchOnce(url, init, options) {
|
|
|
13
13
|
const timeout = AbortSignal.timeout(options.timeoutMs);
|
|
14
14
|
const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
|
|
15
15
|
try {
|
|
16
|
-
return await fetch(url, { ...init, signal });
|
|
16
|
+
return await fetch(url, { ...init, signal, redirect: 'error' });
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
19
|
if (error?.name === 'AbortError' && options.signal?.aborted) {
|
|
@@ -51,6 +51,12 @@ function stringArray(value) {
|
|
|
51
51
|
return undefined;
|
|
52
52
|
return value.filter((item) => !!item && typeof item === 'object');
|
|
53
53
|
}
|
|
54
|
+
function requestHeaders(defaults, overrides) {
|
|
55
|
+
const headers = new Headers(defaults);
|
|
56
|
+
for (const [name, value] of Object.entries(overrides ?? {}))
|
|
57
|
+
headers.set(name, value);
|
|
58
|
+
return headers;
|
|
59
|
+
}
|
|
54
60
|
/** claude / anthropic:`POST /v1/messages`。 */
|
|
55
61
|
export const anthropicExecutor = {
|
|
56
62
|
id: 'builtin:claude',
|
|
@@ -61,12 +67,11 @@ export const anthropicExecutor = {
|
|
|
61
67
|
const endpoint = appendV1RequestPath(context.provider.baseUrl, 'messages');
|
|
62
68
|
const response = await fetchOnce(appendRequestQueryParams(endpoint, context.provider.queryParams), {
|
|
63
69
|
method: 'POST',
|
|
64
|
-
headers: {
|
|
70
|
+
headers: requestHeaders({
|
|
65
71
|
'Content-Type': 'application/json',
|
|
66
72
|
'anthropic-version': '2023-06-01',
|
|
67
73
|
...(context.provider.apiKey ? { 'x-api-key': context.provider.apiKey } : {}),
|
|
68
|
-
|
|
69
|
-
},
|
|
74
|
+
}, context.provider.headers),
|
|
70
75
|
body: JSON.stringify({
|
|
71
76
|
model: context.model,
|
|
72
77
|
max_tokens: typeof input.max_tokens === 'number' ? input.max_tokens : 1024,
|
|
@@ -77,7 +82,7 @@ export const anthropicExecutor = {
|
|
|
77
82
|
}, options);
|
|
78
83
|
if (!response.ok)
|
|
79
84
|
throw await parseFailure(response);
|
|
80
|
-
return { output: await response.json(), latencyMs: 0 };
|
|
85
|
+
return { output: await response.json(), status: response.status, latencyMs: 0 };
|
|
81
86
|
},
|
|
82
87
|
};
|
|
83
88
|
/** codex / openai-responses:`POST /v1/responses`。 */
|
|
@@ -90,11 +95,10 @@ export const openaiResponsesExecutor = {
|
|
|
90
95
|
const endpoint = appendRequestPath(context.provider.baseUrl, 'responses');
|
|
91
96
|
const response = await fetchOnce(appendRequestQueryParams(endpoint, context.provider.queryParams), {
|
|
92
97
|
method: 'POST',
|
|
93
|
-
headers: {
|
|
98
|
+
headers: requestHeaders({
|
|
94
99
|
'Content-Type': 'application/json',
|
|
95
100
|
...(context.provider.apiKey ? { Authorization: `Bearer ${context.provider.apiKey}` } : {}),
|
|
96
|
-
|
|
97
|
-
},
|
|
101
|
+
}, context.provider.headers),
|
|
98
102
|
body: JSON.stringify({
|
|
99
103
|
model: context.model,
|
|
100
104
|
...(input.instructions !== undefined ? { instructions: input.instructions } : {}),
|
|
@@ -106,7 +110,7 @@ export const openaiResponsesExecutor = {
|
|
|
106
110
|
}, options);
|
|
107
111
|
if (!response.ok)
|
|
108
112
|
throw await parseFailure(response);
|
|
109
|
-
return { output: await response.json(), latencyMs: 0 };
|
|
113
|
+
return { output: await response.json(), status: response.status, latencyMs: 0 };
|
|
110
114
|
},
|
|
111
115
|
};
|
|
112
116
|
/** openai-compatible:`POST /v1/chat/completions`。 */
|
|
@@ -119,11 +123,10 @@ export const openaiCompatibleExecutor = {
|
|
|
119
123
|
const endpoint = appendRequestPath(context.provider.baseUrl, 'chat/completions');
|
|
120
124
|
const response = await fetchOnce(appendRequestQueryParams(endpoint, context.provider.queryParams), {
|
|
121
125
|
method: 'POST',
|
|
122
|
-
headers: {
|
|
126
|
+
headers: requestHeaders({
|
|
123
127
|
'Content-Type': 'application/json',
|
|
124
128
|
...(context.provider.apiKey ? { Authorization: `Bearer ${context.provider.apiKey}` } : {}),
|
|
125
|
-
|
|
126
|
-
},
|
|
129
|
+
}, context.provider.headers),
|
|
127
130
|
body: JSON.stringify({
|
|
128
131
|
model: context.model,
|
|
129
132
|
messages: input.messages ?? [{ role: 'user', content: String(input.input ?? input.prompt ?? '') }],
|
|
@@ -133,7 +136,7 @@ export const openaiCompatibleExecutor = {
|
|
|
133
136
|
}, options);
|
|
134
137
|
if (!response.ok)
|
|
135
138
|
throw await parseFailure(response);
|
|
136
|
-
return { output: await response.json(), latencyMs: 0 };
|
|
139
|
+
return { output: await response.json(), status: response.status, latencyMs: 0 };
|
|
137
140
|
},
|
|
138
141
|
};
|
|
139
142
|
/** systemone:`POST {baseUrl}` + `{model, state, questions}`。 */
|
|
@@ -170,23 +173,25 @@ export const geminiExecutor = {
|
|
|
170
173
|
async invoke(context, options) {
|
|
171
174
|
const input = asRecord(context.input);
|
|
172
175
|
const base = context.provider.baseUrl.replace(/\/+$/u, '');
|
|
173
|
-
const
|
|
176
|
+
const versioned = /\/v1(?:beta|alpha)?$/u.test(new URL(base).pathname) ? base : `${base}/v1beta`;
|
|
177
|
+
const resource = `${versioned}/models/${encodeURIComponent(context.model.replace(/^models\//u, ''))}:generateContent`;
|
|
174
178
|
const contents = stringArray(input.contents) ?? [{
|
|
175
179
|
role: 'user',
|
|
176
180
|
parts: [{ text: String(input.input ?? input.prompt ?? '') }],
|
|
177
181
|
}];
|
|
178
182
|
const response = await fetchOnce(appendRequestQueryParams(resource, context.provider.queryParams), {
|
|
179
183
|
method: 'POST',
|
|
180
|
-
headers: {
|
|
184
|
+
headers: requestHeaders({
|
|
181
185
|
'Content-Type': 'application/json',
|
|
182
186
|
...(context.provider.apiKey ? { 'x-goog-api-key': context.provider.apiKey } : {}),
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
}, context.provider.headers),
|
|
188
|
+
body: JSON.stringify({ contents,
|
|
189
|
+
...(input.generationConfig && typeof input.generationConfig === 'object'
|
|
190
|
+
? { generationConfig: input.generationConfig } : {}) }),
|
|
186
191
|
}, options);
|
|
187
192
|
if (!response.ok)
|
|
188
193
|
throw await parseFailure(response);
|
|
189
|
-
return { output: await response.json(), latencyMs: 0 };
|
|
194
|
+
return { output: await response.json(), status: response.status, latencyMs: 0 };
|
|
190
195
|
},
|
|
191
196
|
};
|
|
192
197
|
export const TEXT_EXECUTORS = [
|
|
@@ -196,3 +201,51 @@ export const TEXT_EXECUTORS = [
|
|
|
196
201
|
systemoneExecutor,
|
|
197
202
|
geminiExecutor,
|
|
198
203
|
];
|
|
204
|
+
/** A single bounded inference; no catalog, history, fallback, tools or automatic retry. */
|
|
205
|
+
export async function probeTextModel(provider, model, timeoutMs = 30_000) {
|
|
206
|
+
const started = Date.now();
|
|
207
|
+
const finish = (result) => ({
|
|
208
|
+
...result, latencyMs: Date.now() - started,
|
|
209
|
+
});
|
|
210
|
+
if (!model?.trim() || !Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 120_000) {
|
|
211
|
+
return finish({ ok: false, code: 'INVALID_ARGUMENT', error: 'An explicit model and timeout of 1–120000 ms are required' });
|
|
212
|
+
}
|
|
213
|
+
const executor = TEXT_EXECUTORS.find(item => item.id !== 'builtin:systemone'
|
|
214
|
+
&& item.handles.includes(provider.style.trim().toLowerCase()));
|
|
215
|
+
if (!executor)
|
|
216
|
+
return finish({ ok: false, code: 'STYLE_UNSUPPORTED', error: 'This text protocol cannot be probed' });
|
|
217
|
+
const prompt = 'Reply only OK. No explanation.';
|
|
218
|
+
try {
|
|
219
|
+
const result = await executor.invoke({ provider, model, input: {
|
|
220
|
+
input: prompt, messages: [{ role: 'user', content: prompt }],
|
|
221
|
+
max_tokens: 64, max_output_tokens: 64, generationConfig: { maxOutputTokens: 64, candidateCount: 1 },
|
|
222
|
+
} }, { timeoutMs, retries: 0 });
|
|
223
|
+
const output = result.output;
|
|
224
|
+
let text;
|
|
225
|
+
if (executor === anthropicExecutor)
|
|
226
|
+
text = output?.content?.filter((part) => part.type === 'text').map((part) => part.text).join('');
|
|
227
|
+
else if (executor === openaiResponsesExecutor) {
|
|
228
|
+
if (output?.status && output.status !== 'completed')
|
|
229
|
+
return finish({ ok: false, status: result.status,
|
|
230
|
+
code: 'MODEL_RESPONSE_INCOMPLETE', error: 'The model did not complete the probe' });
|
|
231
|
+
text = output?.output_text ?? output?.output?.filter((item) => item.type === 'message')
|
|
232
|
+
.flatMap((item) => item.content ?? []).filter((part) => part.type === 'output_text')
|
|
233
|
+
.map((part) => part.text).join('');
|
|
234
|
+
}
|
|
235
|
+
else if (executor === geminiExecutor)
|
|
236
|
+
text = output?.candidates?.[0]?.content?.parts
|
|
237
|
+
?.filter((part) => part.thought !== true).map((part) => part.text ?? '').join('');
|
|
238
|
+
else
|
|
239
|
+
text = output?.choices?.[0]?.message?.content;
|
|
240
|
+
if (output?.error || typeof text !== 'string' || !text.trim() || text.length > 256) {
|
|
241
|
+
return finish({ ok: false, status: result.status, code: 'MODEL_RESPONSE_INVALID', error: 'The model returned no usable text' });
|
|
242
|
+
}
|
|
243
|
+
return finish({ ok: true, status: result.status });
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
const status = error instanceof InvokeError ? error.data?.status : undefined;
|
|
247
|
+
// Do not echo upstream bodies or network errors: they may contain credentials or signed URLs.
|
|
248
|
+
return finish({ ok: false, status, code: error instanceof InvokeError ? error.code : 'MODEL_PROBE_FAILED',
|
|
249
|
+
error: status ? `Model probe returned HTTP ${status}` : 'Model probe failed or timed out' });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -31,6 +31,7 @@ import { parseManagedDaemonLogArgv, queryDiagnosticLogs } from './command/daemon
|
|
|
31
31
|
import { createDelegationAuthorizer, createDelegatedProviderOperationExecutor, createDelegatedUpgradeOperationExecutor, createDelegatedInvokeOperationExecutor } from './auth/delegation-authorization.js';
|
|
32
32
|
export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDelegationRegistry, sessionManager, statsCollector, aidStatsCollector, responseEngine, messageQueue, agentMap, getConfiguredBaseagents, commandHandler, channelInstances, eventBus, handoffRuntime, reloadCoordinator, agentApplicationService, agentInitializationService, enqueueConsolidation, getRelationRoute, isConsolidationPending, completeAgentBootstrap, contactBinds, bindService, diagService, getProcessOwners, getControlAidState, daemonAid, triggerControlToken, triggerSchedulers, eventCenter, daemonTriggerOwner, primaryAgent, triggerAuthorization, }) {
|
|
33
33
|
ecwebInitializationService.setAgentInitializer(agentInitializationService);
|
|
34
|
+
ecwebInitializationService.setRuntimeControlAid(daemonAid);
|
|
34
35
|
const authorizeManagedAgentOperation = createDelegationAuthorizer({
|
|
35
36
|
agentDelegationRegistry,
|
|
36
37
|
sessionManager,
|
|
@@ -665,7 +666,7 @@ export function registerCommandIpcProviders({ lifecycle, ipcServer, agentRegistr
|
|
|
665
666
|
lifecycle?.defer(unregisterMenu, 'ipc:menu.exec');
|
|
666
667
|
ipcServer.setConfigOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash, requestId) => cmdHandler.handleConfigOperation(argv, sessionId, delegationToken, delegationCommandHash, requestId));
|
|
667
668
|
ipcServer.setPeerOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleContactOperation(argv, sessionId, delegationToken, delegationCommandHash));
|
|
668
|
-
ipcServer.setRoleOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash));
|
|
669
|
+
ipcServer.setRoleOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash, localControl) => cmdHandler.handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash, localControl));
|
|
669
670
|
ipcServer.setDirectoryOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleDirectoryOperation(argv, sessionId, delegationToken, delegationCommandHash));
|
|
670
671
|
ipcServer.setAidOperationExecutor((argv, sessionId, delegationToken, delegationCommandHash, requestId) => cmdHandler.handleAidOperation(argv, sessionId, delegationToken, delegationCommandHash, requestId));
|
|
671
672
|
ipcServer.setAidOwnershipExecutor((argv, sessionId, delegationToken, delegationCommandHash) => cmdHandler.handleOwnershipOperation(argv, sessionId, delegationToken, delegationCommandHash));
|