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
package/dist/cli/directory.js
CHANGED
|
@@ -3,7 +3,7 @@ import { daemonUnavailableMessage, getArgValue, isHelpFlag, queryDaemon, wantsHe
|
|
|
3
3
|
import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
4
4
|
import { DirectoryQueryError, executeDirectoryQueryCommand, resolveDirectoryQueryCommand, } from '../directory/owner-directory-query-operation.js';
|
|
5
5
|
import { executeDirectoryRequestCommand, resolveDirectoryRequestCommand, } from '../directory/owner-directory-request-operation.js';
|
|
6
|
-
const QUERY_ACTIONS = new Set(['list', 'info', 'refresh', 'blocked']);
|
|
6
|
+
const QUERY_ACTIONS = new Set(['list', 'info', 'refresh', 'blocked', 'block', 'unblock']);
|
|
7
7
|
/**
|
|
8
8
|
* `ec directory ...`
|
|
9
9
|
*
|
|
@@ -74,7 +74,12 @@ function output(result, json) {
|
|
|
74
74
|
}
|
|
75
75
|
switch (result.action) {
|
|
76
76
|
case 'request': {
|
|
77
|
-
|
|
77
|
+
if (result.status === 'queued') {
|
|
78
|
+
console.log(`✓ 已将加密 friend.invite.v1 加好友申请排入发送队列,目标=${result.targetAid} outbox_id=${result.outbox_id ?? '-'}`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.log(`✓ 已向 ${result.targetAid} 发送加密 friend.invite.v1 加好友申请,message_id=${result.message_id ?? '-'}`);
|
|
82
|
+
}
|
|
78
83
|
console.log('发送成功只表示申请已提交;请等待 Evol App 处理并同步联系人名录,再重试原消息。');
|
|
79
84
|
return;
|
|
80
85
|
}
|
|
@@ -119,6 +124,10 @@ function output(result, json) {
|
|
|
119
124
|
: '没有可用连接,未拉取;本地名录已按当前备注重算');
|
|
120
125
|
return;
|
|
121
126
|
}
|
|
127
|
+
case 'block':
|
|
128
|
+
case 'unblock':
|
|
129
|
+
console.log(result.changed ? '✓ 本 Agent 的黑名单已更新' : '无需变更');
|
|
130
|
+
return;
|
|
122
131
|
case 'blocked': {
|
|
123
132
|
if (result.entries.length === 0)
|
|
124
133
|
console.log('(没有被拉黑的主体)');
|
|
@@ -185,6 +194,8 @@ function printHelp() {
|
|
|
185
194
|
ec directory info <contact-aid|名字> [--limit <n>]
|
|
186
195
|
ec directory refresh
|
|
187
196
|
ec directory blocked
|
|
197
|
+
ec directory block <target-aid>
|
|
198
|
+
ec directory unblock <target-aid>
|
|
188
199
|
ec directory request <target-aid> [--note <申请介绍>]
|
|
189
200
|
|
|
190
201
|
request:向目标发送 app-v1 friend.invite.v1 加好友申请;介绍默认为“你好,我想添加你为联系人。”。
|
|
@@ -152,8 +152,11 @@ export function buildDownstreamArgv(route, text, passthrough) {
|
|
|
152
152
|
// 所以按普通私聊发出,会话随这条消息建立,也就不建复查。
|
|
153
153
|
if (route.crossTopic && route.threadId && !route.firstContact) {
|
|
154
154
|
argv.push('--thread', route.threadId);
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
// 进入本分支后 `checkEveryMs === undefined` 只可能是显式 `--check-every none`:
|
|
156
|
+
// 未指定时 resolveSendRoute 已补默认周期,firstContact 又进不了本分支。
|
|
157
|
+
// 必须把 `none` 透传下去——漏传会让下游 `resolveManagedSendArgv` 看到
|
|
158
|
+
// 「有 --thread 没 --check-every」,直接报 Cross-thread sends require …。
|
|
159
|
+
argv.push('--check-every', route.checkEveryMs ? formatDuration(route.checkEveryMs) : 'none');
|
|
157
160
|
}
|
|
158
161
|
argv.push(route.encryptResolved ? '--encrypt' : '--no-encrypt');
|
|
159
162
|
// 保留网关正文的字面量语义,包括经 `--` 传入的 --encrypt 等文本。
|
package/dist/cli/index.js
CHANGED
|
@@ -62,9 +62,8 @@ AUN:
|
|
|
62
62
|
rpc 调用底层 AUN RPC
|
|
63
63
|
menu-client 向远程 daemon 发送标准 Menu 请求
|
|
64
64
|
diag 邀请远程诊断 Agent,或 stop 撤销诊断授权
|
|
65
|
-
peer 联系人黑名单与已登记对端查询
|
|
66
65
|
directory 名录查询与发起加好友申请
|
|
67
|
-
role
|
|
66
|
+
role 角色配额/限额设置、关系角色提升申请与审批
|
|
68
67
|
net AUN 网络链路诊断
|
|
69
68
|
|
|
70
69
|
配置与诊断:
|
|
@@ -73,6 +72,7 @@ AUN:
|
|
|
73
72
|
invoke 统一模型调用:按 provider 的 style 路由到内置执行器
|
|
74
73
|
ability 按 AID 管理能力插件、运行、发布和作业
|
|
75
74
|
stats Token 用量与费用统计
|
|
75
|
+
quota 查询 Agent 和对端的生效限额、已用与剩余额度
|
|
76
76
|
skill EC 技能管理:加载、安装、启停与索引刷新
|
|
77
77
|
diagnose 检查启动环境
|
|
78
78
|
version 显示组件版本
|
|
@@ -109,7 +109,7 @@ export const KNOWN_TOP_LEVEL_COMMANDS = new Set([
|
|
|
109
109
|
'agent', 'aid', 'rpc', 'diag', 'menu-client',
|
|
110
110
|
'storage', 'fs', 'msg', 'thread', 'events', 'services',
|
|
111
111
|
'session', 'getmeta', 'group', 'model', 'skill', 'response',
|
|
112
|
-
'config', 'peer', 'directory', 'role', 'stats',
|
|
112
|
+
'config', 'peer', 'directory', 'role', 'stats', 'quota',
|
|
113
113
|
'provider', 'invoke', 'ability',
|
|
114
114
|
// 版本三个别名在 switch 之前统一处理(含只在早期分支出现的 -V)。
|
|
115
115
|
'version', '-v', '-V', '--version',
|
|
@@ -241,7 +241,7 @@ export async function main(args) {
|
|
|
241
241
|
--owner <aid> 必填。控制 AID 创建后的 Owner 邀约目标,不等待审批
|
|
242
242
|
--baseagent <claude|codex|gemini|ecagent> 可选。默认从 PATH 检测,ecagent 需显式选择
|
|
243
243
|
--projectpath <abs-path> 可选。默认项目目录(必须绝对路径,自动创建)
|
|
244
|
-
--ecweb
|
|
244
|
+
--ecweb 兼容选项。检查 EC Web 安装;默认随 ec start 启动
|
|
245
245
|
--auto-start Windows/macOS 上启用 EvolCore 登录自启动
|
|
246
246
|
--no-auto-start Windows/macOS 上禁用 EvolCore 登录自启动
|
|
247
247
|
--format json 可选但推荐。stdout 输出 init.result JSON
|
|
@@ -677,11 +677,6 @@ export async function main(args) {
|
|
|
677
677
|
await cmdConfig(strippedArgs.slice(1));
|
|
678
678
|
break;
|
|
679
679
|
}
|
|
680
|
-
case 'peer': {
|
|
681
|
-
const { cmdPeer } = await import('./peer.js');
|
|
682
|
-
await cmdPeer(strippedArgs.slice(1));
|
|
683
|
-
break;
|
|
684
|
-
}
|
|
685
680
|
case 'directory': {
|
|
686
681
|
const { cmdDirectory } = await import('./directory.js');
|
|
687
682
|
await cmdDirectory(strippedArgs.slice(1));
|
|
@@ -697,6 +692,11 @@ export async function main(args) {
|
|
|
697
692
|
await handleStats(strippedArgs.slice(1));
|
|
698
693
|
break;
|
|
699
694
|
}
|
|
695
|
+
case 'quota': {
|
|
696
|
+
const { cmdQuota } = await import('./quota.js');
|
|
697
|
+
await cmdQuota(strippedArgs.slice(1));
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
700
|
case 'version':
|
|
701
701
|
case '-v':
|
|
702
702
|
case '--version': {
|
package/dist/cli/init-channel.js
CHANGED
|
@@ -19,7 +19,7 @@ import { ipcQuery } from '../ipc.js';
|
|
|
19
19
|
import { cmdStart } from './daemon-commands.js';
|
|
20
20
|
import * as platform from '../utils/cross-platform.js';
|
|
21
21
|
import { cleanupInstances } from '../utils/instance-registry.js';
|
|
22
|
-
import { bindPeerAlias,
|
|
22
|
+
import { bindPeerAlias, isPeerBindingEligible } from '../config/peer-book.js';
|
|
23
23
|
import { listStaticAgentAdmins } from '../config/peer-role-resolver.js';
|
|
24
24
|
import { askInit, InitCancelledError, isInitCancelledError, setupInitRawKeyListener, waitForInitDelay, } from './init-cancel.js';
|
|
25
25
|
function ask(rl, question) {
|
|
@@ -1408,7 +1408,6 @@ async function confirmOverwriteChannel(rl, displayName, channelName) {
|
|
|
1408
1408
|
}
|
|
1409
1409
|
async function pickContactForChannelBinding(rl, agentConfig, channelType) {
|
|
1410
1410
|
const candidates = preferredContactBindingCandidates(agentConfig);
|
|
1411
|
-
const contacts = getPeerSnapshot(agentConfig.aid).contacts;
|
|
1412
1411
|
console.log(`\n请选择 ${channelType} 账号要绑定到的联系人 AID:`);
|
|
1413
1412
|
candidates.forEach((candidate, index) => {
|
|
1414
1413
|
console.log(` ${index + 1}. ${candidate.primaryId} (${candidate.label})`);
|
|
@@ -1425,7 +1424,7 @@ async function pickContactForChannelBinding(rl, agentConfig, channelType) {
|
|
|
1425
1424
|
}
|
|
1426
1425
|
if (selected === manualChoice) {
|
|
1427
1426
|
const primaryId = (await ask(rl, '请输入要绑定的联系人 AID: ')).trim();
|
|
1428
|
-
if (isValidAid(primaryId) &&
|
|
1427
|
+
if (isValidAid(primaryId) && isPeerBindingEligible(agentConfig.aid, primaryId))
|
|
1429
1428
|
return { primaryId, label: 'contact' };
|
|
1430
1429
|
if (isValidAid(primaryId)) {
|
|
1431
1430
|
console.log('该 AID 不是当前 Agent 的联系人,请先添加联系人或将其设为 Owner。');
|
|
@@ -1438,11 +1437,10 @@ async function pickContactForChannelBinding(rl, agentConfig, channelType) {
|
|
|
1438
1437
|
}
|
|
1439
1438
|
}
|
|
1440
1439
|
function preferredContactBindingCandidates(agentConfig) {
|
|
1441
|
-
const contacts = getPeerSnapshot(agentConfig.aid).contacts;
|
|
1442
1440
|
const labels = new Map();
|
|
1443
1441
|
const add = (value, label) => {
|
|
1444
1442
|
const aid = String(value || '').trim();
|
|
1445
|
-
if (!isValidAid(aid) || !
|
|
1443
|
+
if (!isValidAid(aid) || !isPeerBindingEligible(agentConfig.aid, aid))
|
|
1446
1444
|
return;
|
|
1447
1445
|
let set = labels.get(aid);
|
|
1448
1446
|
if (!set) {
|
|
@@ -1465,7 +1463,7 @@ function bindQrActorToContact(aid, binding, channelType, actorId, channelKey) {
|
|
|
1465
1463
|
return;
|
|
1466
1464
|
const normalizedActor = firstNonEmpty(actorId);
|
|
1467
1465
|
if (!normalizedActor) {
|
|
1468
|
-
console.log(` ⚠ ${channelType} 扫码流程未返回可绑定的用户 ID,未写入
|
|
1466
|
+
console.log(` ⚠ ${channelType} 扫码流程未返回可绑定的用户 ID,未写入 peers.json`);
|
|
1469
1467
|
return;
|
|
1470
1468
|
}
|
|
1471
1469
|
try {
|
package/dist/cli/init.js
CHANGED
|
@@ -8,7 +8,9 @@ import { scanInstances } from '../utils/instance-registry.js';
|
|
|
8
8
|
import { saveDefaultsSafe, loadDaemonConfig, saveDaemonConfig } from '../config-store.js';
|
|
9
9
|
import { currentVersion } from '../config/schema-registry.js';
|
|
10
10
|
import { DEFAULT_ECWEB_PORT, ecwebService, setEcwebEnabled } from '../config/daemon-services.js';
|
|
11
|
-
import {
|
|
11
|
+
import { buildEcwebPairingUrl, fetchRemotePairingCode } from '../ecweb/pairing.js';
|
|
12
|
+
import { waitForEcwebProxyAccess } from '../ecweb/runtime/proxy-access.js';
|
|
13
|
+
import { ipcQuery } from '../ipc.js';
|
|
12
14
|
import { ensureControlAgentMd, generateControlAid, hasLocalControlIdentity, missingControlIdentityMessage, resolveControlAidDomain, submitControlAidRegistration, } from '../aun/aid/control-aid.js';
|
|
13
15
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
14
16
|
/**
|
|
@@ -23,7 +25,7 @@ async function probeCodexAvailability() {
|
|
|
23
25
|
}
|
|
24
26
|
import { resolveCodexCliPath, resolveCodexPowerShellShimPath, } from '../agents/baseagent.js';
|
|
25
27
|
import { assertProjectPathReference, defaultProjectsRoot, hasProjectPathEnvironmentReference } from '../utils/project-path.js';
|
|
26
|
-
import { WEB_CLI_BIN, WEB_PACKAGE_LATEST } from '../product.js';
|
|
28
|
+
import { WEB_CLI_BIN, WEB_PACKAGE_NAME, WEB_PACKAGE_LATEST } from '../product.js';
|
|
27
29
|
import { autostartInstalled, autostartPlatformLabel, configureAutostart } from '../utils/autostart.js';
|
|
28
30
|
import { askInit, printInitCancelHint } from './init-cancel.js';
|
|
29
31
|
import { AUTO_BASEAGENT_CANDIDATES, BASEAGENT_CANDIDATES, detectAvailableBaseagents, detectBaseagentDetails, } from '../agents/baseagent-availability.js';
|
|
@@ -175,7 +177,7 @@ export async function importProvidersForCliInit(available, options = {}) {
|
|
|
175
177
|
for (const item of warnings) {
|
|
176
178
|
const hint = item.baseagent === 'ecagent'
|
|
177
179
|
? '请在内部配置中为内置 ecagent 选择可用 Provider。'
|
|
178
|
-
: '可使用 ec provider
|
|
180
|
+
: '可使用 ec provider templates 查看内置模板,再用 ec provider create --template <id> 配置;也可在 ECWEB 中添加。';
|
|
179
181
|
console.warn(`⚠ ${item.baseagent}: ${messages[item.code]}(${item.code});${hint}`);
|
|
180
182
|
}
|
|
181
183
|
}
|
|
@@ -251,8 +253,8 @@ function installErrorMessage(e) {
|
|
|
251
253
|
return String(e?.stderr || e?.message || e).trim();
|
|
252
254
|
}
|
|
253
255
|
export async function ensureEcwebInstalledForInit(options = {}) {
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
256
|
+
const installed = options.isInstalled ? options.isInstalled() : !!(await (await import('../utils/npm-ops.js')).resolveGlobalPkgAsync(WEB_PACKAGE_NAME)) || commandExists(WEB_CLI_BIN);
|
|
257
|
+
if (installed)
|
|
256
258
|
return { ok: true, installedNow: false };
|
|
257
259
|
if (!options.quiet)
|
|
258
260
|
console.log(` 📦 EC Web 组件未安装,正在安装 ${WEB_PACKAGE_LATEST}...`);
|
|
@@ -279,6 +281,10 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
279
281
|
const p = resolvePaths();
|
|
280
282
|
const hasIdentity = dependencies.hasLocalIdentity ?? hasLocalControlIdentity;
|
|
281
283
|
const existingConfig = (dependencies.loadConfig ?? loadDaemonConfig)();
|
|
284
|
+
if (ecwebService(existingConfig.services).enabled === false) {
|
|
285
|
+
console.error('❌ ECWeb 已被手动关闭,未修改设置;请先启用 ECWeb 后重试初始化。');
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
282
288
|
if (existingConfig.aid && !hasIdentity(existingConfig.aid)) {
|
|
283
289
|
console.error(`❌ ${missingControlIdentityMessage(existingConfig.aid)}`);
|
|
284
290
|
return false;
|
|
@@ -286,9 +292,21 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
286
292
|
ensureDataDirs();
|
|
287
293
|
const daemonRunning = dependencies.isDaemonRunning?.()
|
|
288
294
|
?? scanInstances().mains.some(instance => instance.alive);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
295
|
+
const readRuntimeAid = dependencies.runtimeAid ?? (async () => {
|
|
296
|
+
const status = await ipcQuery(p.socket, { type: 'status' }, 3000);
|
|
297
|
+
if (!status)
|
|
298
|
+
throw new Error('无法确认运行中 daemon 的身份,未执行重启;请稍后重试');
|
|
299
|
+
return status.controlAid?.aid;
|
|
300
|
+
});
|
|
301
|
+
let runtimeAid;
|
|
302
|
+
if (daemonRunning) {
|
|
303
|
+
try {
|
|
304
|
+
runtimeAid = await readRuntimeAid();
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
console.error(`❌ ${installErrorMessage(error)}`);
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
292
310
|
}
|
|
293
311
|
const install = await (dependencies.ensureEcwebInstalled ?? ensureEcwebInstalledForInit)();
|
|
294
312
|
if (!install.ok)
|
|
@@ -335,18 +353,32 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
335
353
|
else {
|
|
336
354
|
console.log('ℹ 主机名片将在 Web 初始化完成 Owner 绑定后发布。');
|
|
337
355
|
}
|
|
338
|
-
if (ecwebService(config.services)?.enabled
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
(dependencies.saveConfig ?? saveDaemonConfig)(config);
|
|
342
|
-
}
|
|
343
|
-
catch (error) {
|
|
344
|
-
console.error(`❌ 启用 ECWeb 失败: ${installErrorMessage(error)}`);
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
356
|
+
if (ecwebService(config.services)?.enabled === false) {
|
|
357
|
+
console.error('❌ ECWeb 已被手动关闭,未修改设置;请先启用 ECWeb 后重试初始化。');
|
|
358
|
+
return false;
|
|
347
359
|
}
|
|
348
360
|
try {
|
|
349
|
-
if (
|
|
361
|
+
if (daemonRunning && runtimeAid !== controlAid) {
|
|
362
|
+
console.log('ℹ 主机控制 AID 已准备,正在重启 EvolCore 使身份生效...');
|
|
363
|
+
const accepted = dependencies.restartDaemon ? await dependencies.restartDaemon()
|
|
364
|
+
: await (await import('./daemon-commands.js')).cmdRestart({ applyPackageUpgrades: false });
|
|
365
|
+
if (!accepted)
|
|
366
|
+
throw new Error('控制 AID 已保存,但重启未确认受理;请检查 ec status 后重试');
|
|
367
|
+
const deadline = Date.now() + 60000;
|
|
368
|
+
let activated = false;
|
|
369
|
+
do {
|
|
370
|
+
try {
|
|
371
|
+
activated = await readRuntimeAid() === controlAid;
|
|
372
|
+
}
|
|
373
|
+
catch { /* IPC is temporarily absent during restart. */ }
|
|
374
|
+
if (activated)
|
|
375
|
+
break;
|
|
376
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
377
|
+
} while (Date.now() < deadline);
|
|
378
|
+
if (!activated)
|
|
379
|
+
throw new Error('控制 AID 已保存,但重启后身份尚未验证;请检查 ec status,勿重复发起重启');
|
|
380
|
+
}
|
|
381
|
+
else if (!daemonRunning && dependencies.startDaemon) {
|
|
350
382
|
await dependencies.startDaemon();
|
|
351
383
|
}
|
|
352
384
|
else if (!daemonRunning) {
|
|
@@ -355,7 +387,7 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
355
387
|
}
|
|
356
388
|
const started = dependencies.startEcweb
|
|
357
389
|
? await dependencies.startEcweb()
|
|
358
|
-
: await (await import("./daemon-commands.js")).startEcwebIfEnabled(p);
|
|
390
|
+
: await (await import("./daemon-commands.js")).startEcwebIfEnabled(p, { initialization: true });
|
|
359
391
|
if (!started) {
|
|
360
392
|
console.error("❌ ECWeb 未能启动;可稍后运行 ec watch web 重试。");
|
|
361
393
|
return false;
|
|
@@ -367,12 +399,23 @@ export async function cmdInitWeb(dependencies = {}) {
|
|
|
367
399
|
}
|
|
368
400
|
const currentConfig = (dependencies.loadConfig ?? loadDaemonConfig)();
|
|
369
401
|
const port = ecwebService(currentConfig.services)?.port ?? DEFAULT_ECWEB_PORT;
|
|
370
|
-
const
|
|
402
|
+
const access = await (dependencies.waitForProxy ?? waitForEcwebProxyAccess)(currentConfig);
|
|
371
403
|
console.log('\nECweb 初始化:');
|
|
372
404
|
console.log(` 本地访问: http://localhost:${port}/init`);
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
405
|
+
console.log(` 外网代理: ${access.message}`);
|
|
406
|
+
if (access.state === 'ready' && access.url) {
|
|
407
|
+
console.log(` 外网访问: ${access.url}/init`);
|
|
408
|
+
const pair = await (dependencies.fetchPairingCode ?? fetchRemotePairingCode)();
|
|
409
|
+
const pairingUrl = pair ? buildEcwebPairingUrl(currentConfig, pair.code, true) : null;
|
|
410
|
+
if (pair && pairingUrl) {
|
|
411
|
+
console.log(` 配对码: ${pair.code}(仅可配对一次,约 ${Math.max(0, Math.round((pair.expiresAt - Date.now()) / 60000))} 分钟内有效)`);
|
|
412
|
+
console.log(` 一键初始化: ${pairingUrl}`);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
console.log(' 配对码暂不可用,可在本机初始化页面获取,或稍后重试 ec init --web。');
|
|
416
|
+
}
|
|
417
|
+
console.log(' 远程首次访问需要配对;已有有效 token 可直接继续。');
|
|
418
|
+
}
|
|
376
419
|
return true;
|
|
377
420
|
}
|
|
378
421
|
// ==================== Main ====================
|
|
@@ -752,23 +795,13 @@ export async function initTail(options = {}) {
|
|
|
752
795
|
}
|
|
753
796
|
async function handleEcwebPrompt() {
|
|
754
797
|
const daemonConfigForEcweb = loadDaemonConfig();
|
|
755
|
-
if (ecwebService(daemonConfigForEcweb.services)
|
|
798
|
+
if (ecwebService(daemonConfigForEcweb.services).enabled !== false) {
|
|
756
799
|
const installResult = await ensureEcwebInstalledForInit();
|
|
757
800
|
if (installResult.ok) {
|
|
758
|
-
const cfg = loadDaemonConfig();
|
|
759
|
-
saveDaemonConfig({
|
|
760
|
-
...cfg,
|
|
761
|
-
services: setEcwebEnabled(cfg.services, true),
|
|
762
|
-
});
|
|
763
801
|
console.log(' ✓ 已启用 ECWeb(ec start 将自动在后台启动)');
|
|
764
802
|
console.log(' 提示:首次访问运行 ec watch web 查看配对码和 URL');
|
|
765
803
|
}
|
|
766
804
|
else {
|
|
767
|
-
const cfg = loadDaemonConfig();
|
|
768
|
-
saveDaemonConfig({
|
|
769
|
-
...cfg,
|
|
770
|
-
services: setEcwebEnabled(cfg.services, false),
|
|
771
|
-
});
|
|
772
805
|
console.log(' 提示:安装完成后运行 ec start;如需立即打开控制台,运行 ec watch web');
|
|
773
806
|
}
|
|
774
807
|
}
|
|
@@ -930,25 +963,17 @@ export async function cmdInitNonInteractive(opts, dependencies = {}) {
|
|
|
930
963
|
projectsDefaultPath = opts.projectpath;
|
|
931
964
|
}
|
|
932
965
|
// ── 5. 读取现有配置;协议冲突由 SDK 注册意图及共识判定 ──
|
|
933
|
-
|
|
966
|
+
let existingCfg = loadDaemonConfig();
|
|
934
967
|
// ── 6. EC Web 安装(先安装成功,再写 enabled 配置)──
|
|
935
968
|
if (opts.ecweb === true) {
|
|
936
969
|
const ensureEcweb = dependencies.ensureEcweb ?? (() => ensureEcwebInstalledForInit({ quiet: true }));
|
|
937
970
|
const installResult = await ensureEcweb();
|
|
938
971
|
if (!installResult.ok) {
|
|
939
|
-
if (ecwebService(existingCfg.services)?.enabled === true) {
|
|
940
|
-
try {
|
|
941
|
-
saveDaemonConfig({
|
|
942
|
-
...existingCfg,
|
|
943
|
-
services: setEcwebEnabled(existingCfg.services, false),
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
catch (e) {
|
|
947
|
-
fail('ECWEB_INSTALL_FAILED', `failed to install ${WEB_PACKAGE_LATEST}: ${installResult.error}; failed to disable ecweb: ${e?.message || e}`, EXIT_RUNTIME, format);
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
972
|
fail('ECWEB_INSTALL_FAILED', `failed to install ${WEB_PACKAGE_LATEST}: ${installResult.error}`, EXIT_RUNTIME, format);
|
|
951
973
|
}
|
|
974
|
+
if (ecwebService(existingCfg.services).enabled === false) {
|
|
975
|
+
existingCfg = { ...existingCfg, services: setEcwebEnabled(existingCfg.services, true) };
|
|
976
|
+
}
|
|
952
977
|
}
|
|
953
978
|
// ── 7. 写 defaults.json ──
|
|
954
979
|
try {
|
|
@@ -994,9 +1019,6 @@ export async function cmdInitNonInteractive(opts, dependencies = {}) {
|
|
|
994
1019
|
...existingCfg,
|
|
995
1020
|
$schema_version: existingCfg.$schema_version ?? 1,
|
|
996
1021
|
aid: controlAid,
|
|
997
|
-
...(opts.ecweb === true
|
|
998
|
-
? { services: setEcwebEnabled(existingCfg.services, true) }
|
|
999
|
-
: {}),
|
|
1000
1022
|
};
|
|
1001
1023
|
saveDaemonConfig(next);
|
|
1002
1024
|
}
|
|
@@ -1035,7 +1057,7 @@ export async function cmdInitNonInteractive(opts, dependencies = {}) {
|
|
|
1035
1057
|
success: true,
|
|
1036
1058
|
controlAid: controlAid,
|
|
1037
1059
|
ownerAid,
|
|
1038
|
-
ecwebEnabled:
|
|
1060
|
+
ecwebEnabled: ecwebService(existingCfg.services).enabled === true,
|
|
1039
1061
|
baseagent: chosenBaseagent,
|
|
1040
1062
|
providers,
|
|
1041
1063
|
projectsDefaultPath: projectsDefaultPath ?? null,
|
|
@@ -145,7 +145,7 @@ export async function cmdInvoke(args) {
|
|
|
145
145
|
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
146
146
|
const delegationToken = readDelegationCredential();
|
|
147
147
|
// 托管与非托管都走 daemon:密钥解析($VAR)与 providers.json 的合理归属都在 daemon。
|
|
148
|
-
const argv = [
|
|
148
|
+
const argv = sessionId !== undefined || delegationToken ? ['invoke', ...args] : [
|
|
149
149
|
'invoke',
|
|
150
150
|
'--provider', parsed.providerId,
|
|
151
151
|
'--service', parsed.serviceType,
|
|
@@ -59,6 +59,8 @@ const MANAGED_TASK_COMMANDS = new Set([
|
|
|
59
59
|
// `stats` reads the usage database directly. It authorizes each managed call
|
|
60
60
|
// against the task's relation role in `resolveManagedStatsScope`.
|
|
61
61
|
'stats',
|
|
62
|
+
// Quota reads validate task credentials and scope inside quota.op.
|
|
63
|
+
'quota',
|
|
62
64
|
'status',
|
|
63
65
|
'storage',
|
|
64
66
|
'task',
|
package/dist/cli/model.js
CHANGED
|
@@ -18,6 +18,7 @@ import { getCatalog, getModelInfo, catalogEfforts, resolveCatalogModel, assertCa
|
|
|
18
18
|
import { constrainResolvedModelForRole, filterModelsForRole, validateModelSelectionForRole, } from '../core/model/model-permission.js';
|
|
19
19
|
import { resolvePaths } from '../paths.js';
|
|
20
20
|
import { daemonUnavailableMessage, queryDaemon } from './help.js';
|
|
21
|
+
import { readTaskRuntimeContextFromEnv } from './task-context.js';
|
|
21
22
|
import { parsePeerKey } from '../core/relation/peer-identity.js';
|
|
22
23
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
23
24
|
import { AGENT_DELEGATION_TOKEN_ENV, readDelegationCredential } from '../core/auth/agent-delegation.js';
|
|
@@ -189,7 +190,7 @@ Commands:
|
|
|
189
190
|
list 列出可用模型,标注当前 Agent 级模型
|
|
190
191
|
current 显示 Agent 级模型(经角色约束)+ 来源
|
|
191
192
|
info <model-id> 查看单个模型详情(厂商/上下文/价格/模态/effort/状态)
|
|
192
|
-
use <model-id> 设置 Agent
|
|
193
|
+
use <model-id> 设置 Agent 级模型(托管会话省略 --self;--self 仅可用于等于本端 AID)
|
|
193
194
|
reset 清除 Agent 级模型与推理强度,回落到较低优先级配置
|
|
194
195
|
effort <level> 设置 Agent 级推理强度(low|medium|high|xhigh|max|auto)
|
|
195
196
|
check 诊断网关连通性与模型可用性(分阶段输出进度)
|
|
@@ -203,6 +204,7 @@ Commands:
|
|
|
203
204
|
修改 Agent 级后,该 Agent 所有会话的下一条消息即时生效。
|
|
204
205
|
角色策略请通过角色策略编辑器修改。
|
|
205
206
|
托管会话内省略 --self/--peer/--role 时,命令作用于当前会话;写操作仅当前 Agent 的 owner/admin 可用。
|
|
207
|
+
托管会话的写操作不接受指向其他 Agent 的 --self,也不接受 --peer/--role;--self <本端 AID> 等同省略。
|
|
206
208
|
|
|
207
209
|
Options:
|
|
208
210
|
--self <aid> 本端 AID
|
|
@@ -216,7 +218,8 @@ Options:
|
|
|
216
218
|
ec model list
|
|
217
219
|
ec model current --self bot.agentid.pub --peer aun#alice.agentid.pub
|
|
218
220
|
ec model info deepseek-v4-pro
|
|
219
|
-
ec model use opus
|
|
221
|
+
ec model use opus # 托管会话(作用于当前 Agent)
|
|
222
|
+
ec model use opus --self bot.agentid.pub # 非托管终端
|
|
220
223
|
ec model effort high --self bot.agentid.pub
|
|
221
224
|
ec model reset --self bot.agentid.pub
|
|
222
225
|
ec model check --self bot.agentid.pub`;
|
|
@@ -485,9 +488,21 @@ export async function cmdModel(args) {
|
|
|
485
488
|
return;
|
|
486
489
|
}
|
|
487
490
|
if (process.env.EVOLCORE_SESSION_ID) {
|
|
488
|
-
if (!['list', 'current', 'info', 'check'].includes(sub)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
+
if (!['list', 'current', 'info', 'check'].includes(sub)) {
|
|
492
|
+
if (args.some(arg => arg === '--peer' || arg === '--role')) {
|
|
493
|
+
fail(formatJson, 'NOT_ALLOWED', 'Managed model writes cannot select --peer or --role');
|
|
494
|
+
}
|
|
495
|
+
const selfIndex = args.indexOf('--self');
|
|
496
|
+
if (selfIndex !== -1) {
|
|
497
|
+
// 托管写入只作用于当前会话的 Agent;`--self <本端 AID>` 是幂等写法,
|
|
498
|
+
// 与省略等价,按 help 的示例照抄不应失败。
|
|
499
|
+
const requested = args[selfIndex + 1];
|
|
500
|
+
const own = process.env.EVOLCORE_SELF_AID || readTaskRuntimeContextFromEnv()?.selfAid;
|
|
501
|
+
if (!own || requested !== own) {
|
|
502
|
+
fail(formatJson, 'NOT_ALLOWED', 'Managed model writes apply to the current session Agent; omit --self (--self must equal the current AID)');
|
|
503
|
+
}
|
|
504
|
+
args = args.slice(0, selfIndex).concat(args.slice(selfIndex + 2));
|
|
505
|
+
}
|
|
491
506
|
}
|
|
492
507
|
await runManagedCliOperation(['model', ...args], formatJson, sub === 'check' ? 60_000 : 10_000);
|
|
493
508
|
return;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { createInterface } from 'node:readline/promises';
|
|
4
|
+
import { Writable } from 'node:stream';
|
|
5
|
+
import { providerTemplateDetail } from '../config/provider-templates.js';
|
|
3
6
|
import { resolvePaths } from '../paths.js';
|
|
4
7
|
import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
|
|
5
8
|
import { parseProviderCommand } from '../config/provider-ipc-service.js';
|
|
@@ -11,7 +14,14 @@ function providerText(command, data) {
|
|
|
11
14
|
for (const [alias, target] of Object.entries(data.aliases ?? {}))
|
|
12
15
|
lines.push(` ${label(alias)} → ${label(target)}`);
|
|
13
16
|
};
|
|
14
|
-
if (command.operation === '
|
|
17
|
+
if (command.operation === 'templates') {
|
|
18
|
+
for (const item of data.templates ?? [data]) {
|
|
19
|
+
lines.push(`${label(item.templateId)} ${label(item.label)} (${label(item.product)})`, ` 服务:${Object.keys(item.provider.services ?? {}).join(', ')} 密钥入口:${label(item.credential.helpUrl)}`);
|
|
20
|
+
for (const field of item.fields)
|
|
21
|
+
lines.push(` 输入:${label(field.name)} ${label(field.label)}${field.required ? '(必填)' : ''}${field.default ? ' 默认 ' + label(field.default) : ''}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (command.operation === 'sync') {
|
|
15
25
|
lines.push('✓ Provider 同步完成', `地址固化:${data.materializedBaseUrls ?? 0} 项`, `配置变更:${data.changedFiles ?? 0} 个文件,更新 ${data.referencesUpdated ?? 0} 处引用`);
|
|
16
26
|
if (data.imports?.length) {
|
|
17
27
|
lines.push('本机导入:');
|
|
@@ -52,14 +62,16 @@ function providerText(command, data) {
|
|
|
52
62
|
lines.push(`${indent}${label(field)}:${label(value)}`);
|
|
53
63
|
};
|
|
54
64
|
const provider = structuredClone(data.provider ?? {});
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
for (const connection of [provider.common, ...Object.values(provider.services ?? {})]) {
|
|
66
|
+
if (!connection)
|
|
67
|
+
continue;
|
|
68
|
+
const key = connection.apiKey;
|
|
57
69
|
if (key && !/^\$(?:[A-Za-z_][A-Za-z0-9_]*|\{[A-Za-z_][A-Za-z0-9_]*\})$/u.test(key))
|
|
58
|
-
|
|
70
|
+
connection.apiKey = '<redacted>';
|
|
59
71
|
for (const field of ['headers', 'queryParams']) {
|
|
60
|
-
if (
|
|
61
|
-
for (const key of Object.keys(
|
|
62
|
-
|
|
72
|
+
if (connection[field])
|
|
73
|
+
for (const key of Object.keys(connection[field]))
|
|
74
|
+
connection[field][key] = '<redacted>';
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
77
|
for (const [field, value] of Object.entries(provider))
|
|
@@ -73,11 +85,47 @@ function providerText(command, data) {
|
|
|
73
85
|
lines.push(`配置版本:${label(data.revision)}`);
|
|
74
86
|
return lines.join('\n');
|
|
75
87
|
}
|
|
88
|
+
async function completeTemplateArgs(args, parsed) {
|
|
89
|
+
if (!parsed.templateId || parsed.operation === 'templates' || parsed.file)
|
|
90
|
+
return args;
|
|
91
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
92
|
+
return args;
|
|
93
|
+
const template = providerTemplateDetail(parsed.templateId);
|
|
94
|
+
const result = [...args];
|
|
95
|
+
for (const field of template.fields) {
|
|
96
|
+
if (!field.required || field.default || parsed.templateInput?.inputs?.[field.name])
|
|
97
|
+
continue;
|
|
98
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
99
|
+
try {
|
|
100
|
+
result.push('--input', field.name + '=' + (await prompt.question(field.label + ': ')).trim());
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
prompt.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!parsed.templateInput?.apiKey) {
|
|
107
|
+
process.stdout.write(template.credential.label + '(输入不回显): ');
|
|
108
|
+
const silent = new Writable({ write(_chunk, _encoding, callback) { callback(); } });
|
|
109
|
+
const prompt = createInterface({ input: process.stdin, output: silent, terminal: true });
|
|
110
|
+
try {
|
|
111
|
+
result.push('--api-key', (await prompt.question('')).trim());
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
prompt.close();
|
|
115
|
+
silent.end();
|
|
116
|
+
process.stdout.write('\n');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
76
121
|
export async function cmdProvider(args) {
|
|
77
122
|
if (!args.length || wantsHelp(args)) {
|
|
78
123
|
console.log('用法: ec provider <命令> [--format json]\n\n'
|
|
79
|
-
+ ' list\n show <provider-id>\n create --file <path>\n import --file <path>\n'
|
|
124
|
+
+ ' list\n show <provider-id>\n templates [template-id]\n create --file <path>\n import --file <path>\n'
|
|
80
125
|
+ ' update <provider-id> --file <path>\n delete <provider-id>\n sync\n\n'
|
|
126
|
+
+ '模板:create / update <id> --template <template-id> --file <inputs.json>\n'
|
|
127
|
+
+ '宿主终端也可用 --api-key、--name、--services ecagent,claude,codex、可重复 --input 字段=值;TTY 自动补齐。\n'
|
|
128
|
+
+ '托管任务模板写入仅接受 --file;同域合并需显式 update,不自动覆盖。\n'
|
|
81
129
|
+ 'sync 扫描导入本机 Provider、固化环境变量地址、迁移 ID 与配置引用,并切换全局默认到 ecagent;不覆盖 Agent 显式基座选择。\n'
|
|
82
130
|
+ '默认输出可读文本;--format json 输出完整结构化响应,适合脚本处理。\n'
|
|
83
131
|
+ '宿主控制终端或 daemon 验证的 trusted fullaccess 任务可管理 process 级 Provider。\n'
|
|
@@ -88,15 +136,28 @@ export async function cmdProvider(args) {
|
|
|
88
136
|
}
|
|
89
137
|
const json = args.some((value, index) => value === '--format=json' || (value === '--format' && args[index + 1] === 'json'));
|
|
90
138
|
try {
|
|
91
|
-
|
|
139
|
+
let parsed = parseProviderCommand(['provider', ...args]);
|
|
92
140
|
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
93
141
|
const delegationToken = readDelegationCredential();
|
|
142
|
+
if (sessionId !== undefined || delegationToken) {
|
|
143
|
+
if (parsed.templateId && parsed.operation !== 'templates' && (!parsed.file || parsed.templateInput)) {
|
|
144
|
+
throw new Error('托管任务模板写入仅支持 --file');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
args = await completeTemplateArgs(args, parsed);
|
|
149
|
+
parsed = parseProviderCommand(['provider', ...args]);
|
|
150
|
+
}
|
|
94
151
|
// Keep managed argv identical to the command bound by task approval.
|
|
95
152
|
// The daemon resolves relative input paths against the session project.
|
|
96
|
-
const argv =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
153
|
+
const argv = ['provider', ...args];
|
|
154
|
+
if (sessionId === undefined && !delegationToken && parsed.file) {
|
|
155
|
+
const index = argv.findIndex(value => value === '--file' || value.startsWith('--file='));
|
|
156
|
+
if (argv[index] === '--file')
|
|
157
|
+
argv[index + 1] = path.resolve(parsed.file);
|
|
158
|
+
else
|
|
159
|
+
argv[index] = '--file=' + path.resolve(parsed.file);
|
|
160
|
+
}
|
|
100
161
|
let controlToken;
|
|
101
162
|
if (!sessionId && !delegationToken) {
|
|
102
163
|
try {
|