evolcore 0.0.48 → 0.0.50
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 +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- 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 +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- 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 +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- 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 +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { randomUUID, createHash } from 'node:crypto';
|
|
2
|
+
import { AbilityStore } from '../store.js';
|
|
3
|
+
import { isJsonObject, validateAbilityResult, canonicalizeAbilityJson } from '../interop-v1.js';
|
|
4
|
+
import { isAidWideDeviceStatusQuery } from '../../aun/ability-device-routing.js';
|
|
5
|
+
import { durationSeconds, remoteAssert, RemoteError, REMOTE_CLI_VERSION } from './command.js';
|
|
6
|
+
import { boundedJson, parseCapability, parseRemoteIndex, sameProviderPath, validateValue, parseRemoteContract } from './contract.js';
|
|
7
|
+
const digest = (value) => createHash('sha256').update(canonicalizeAbilityJson(value)).digest('hex');
|
|
8
|
+
const requestKey = (context, request) => digest([context.callerAid, request]);
|
|
9
|
+
const operationKey = (context, provider, operation) => digest([context.callerAid, provider, operation]);
|
|
10
|
+
function sameScope(value, context) {
|
|
11
|
+
return value.callerAid === context.callerAid && value.sessionId === context.sessionId
|
|
12
|
+
&& value.peerKey === context.peerKey && value.threadId === context.threadId;
|
|
13
|
+
}
|
|
14
|
+
function response(data, ok = true, code) {
|
|
15
|
+
return { schema_version: REMOTE_CLI_VERSION, ok, ...(code ? { code } : {}), data };
|
|
16
|
+
}
|
|
17
|
+
export function remoteFailure(error) {
|
|
18
|
+
const code = error instanceof RemoteError ? error.code : 'REMOTE_ABILITY_FAILED';
|
|
19
|
+
const data = error instanceof RemoteError ? error.data : undefined;
|
|
20
|
+
const denied = ['NOT_ALLOWED', 'NO_PERMISSION', 'ROLE_ACCESS_DENIED', 'SCOPE_MISMATCH', 'DELEGATION_REQUIRED', 'INVALID_DELEGATION'].includes(code);
|
|
21
|
+
return { schema_version: REMOTE_CLI_VERSION, ok: false,
|
|
22
|
+
code,
|
|
23
|
+
error: error instanceof RemoteError ? error.message : 'Remote Ability operation failed',
|
|
24
|
+
...(data ? { data } : {}),
|
|
25
|
+
...(code === 'PARAMS_INVALID' ? { stage: 'validation', sent: false } : {}),
|
|
26
|
+
...(denied ? { next_action: { action: 'stop', reason: 'Permission denied; report the reason. Do not retry through another identity or transport.', resend_allowed: false } }
|
|
27
|
+
: code === 'PARAMS_INVALID' ? { next_action: { action: 'correct_params', reason: 'Use this capability’s current params_schema and allowed values. Read remote info only if the contract is missing; no request was sent.' } }
|
|
28
|
+
: data?.usage ? { next_action: { usage: data.usage } } : {}) };
|
|
29
|
+
}
|
|
30
|
+
export function remoteExitCode(result) {
|
|
31
|
+
return result.ok ? 0 : ['RESULT_PENDING', 'EXECUTION_UNKNOWN', 'NO_DISCOVERY_RESPONSE', 'DEVICE_SELECTION_REQUIRED', 'CONTRACT_SELECTION_REQUIRED', 'DISCOVERY_REQUIRED'].includes(result.code ?? '') ? 2 : 1;
|
|
32
|
+
}
|
|
33
|
+
/** All durable evidence is daemon-owned; no user-supplied file is a discovery or plan. */
|
|
34
|
+
export class AbilityCallerService {
|
|
35
|
+
now;
|
|
36
|
+
store;
|
|
37
|
+
constructor(root, now = Date.now) {
|
|
38
|
+
this.now = now;
|
|
39
|
+
this.store = new AbilityStore(root);
|
|
40
|
+
}
|
|
41
|
+
close() { this.store.close(); }
|
|
42
|
+
async execute(command, context, transport, params = {}) {
|
|
43
|
+
if (command.action === 'result') {
|
|
44
|
+
const call = this.store.get('call', requestKey(context, command.requestId));
|
|
45
|
+
remoteAssert(call && sameScope(call, context), 'REQUEST_NOT_FOUND', 'Request is not available in this session and topic');
|
|
46
|
+
return this.query(call, context, transport, command.options.wait ? durationSeconds(command.options.wait, 60) * 1000 : undefined);
|
|
47
|
+
}
|
|
48
|
+
if (command.action === 'call' && command.options.plan) {
|
|
49
|
+
const plan = this.store.get('plan', command.options.plan);
|
|
50
|
+
remoteAssert(plan && sameScope(plan, context), 'PLAN_NOT_FOUND', 'Plan is not available in this session and topic');
|
|
51
|
+
return this.dispatch(plan, context, transport);
|
|
52
|
+
}
|
|
53
|
+
const provider = command.provider;
|
|
54
|
+
await transport.authorize(provider, 'read');
|
|
55
|
+
if (command.action === 'discover')
|
|
56
|
+
return this.discover(command, context, transport);
|
|
57
|
+
const snapshot = await this.discovery(command, context, transport);
|
|
58
|
+
if (command.action === 'list') {
|
|
59
|
+
const data = this.discoveryView(snapshot, command.path, command.options);
|
|
60
|
+
if (command.options.usage && snapshot.skillRef)
|
|
61
|
+
data.usage = { untrusted: true, reference: snapshot.skillRef,
|
|
62
|
+
content: await this.readUsage(snapshot, snapshot.skillRef, transport) };
|
|
63
|
+
return response(data);
|
|
64
|
+
}
|
|
65
|
+
if (command.action === 'devices')
|
|
66
|
+
return response({ provider_aid: provider, discovery_id: snapshot.id, ability_path: command.path,
|
|
67
|
+
devices: this.candidates(snapshot, command.path) });
|
|
68
|
+
const selected = this.selectCapability(snapshot, command.path, command.options['definition-id']);
|
|
69
|
+
const raw = await transport.read(provider, sameProviderPath(selected.detail_ref, provider));
|
|
70
|
+
const indexMatches = snapshot.indexCapabilities.filter(row => row.path === selected.path && row.definition_id === selected.definition_id);
|
|
71
|
+
if (snapshot.source === 'online' && snapshot.indexCapabilities.some(row => row.path === selected.path) && !indexMatches.length) {
|
|
72
|
+
throw new RemoteError('CONTRACT_CHANGED', 'L1 and online discovery disagree; refresh discovery');
|
|
73
|
+
}
|
|
74
|
+
const contract = parseRemoteContract(raw, selected, [...indexMatches,
|
|
75
|
+
...snapshot.capabilities.filter(row => row.path === selected.path && row.definition_id === selected.definition_id)]);
|
|
76
|
+
const { definition } = contract;
|
|
77
|
+
if (command.action === 'info') {
|
|
78
|
+
const view = this.discoveryView(snapshot, command.path, command.options);
|
|
79
|
+
if (!command.options.full) {
|
|
80
|
+
delete view.capabilities;
|
|
81
|
+
delete view.pagination;
|
|
82
|
+
}
|
|
83
|
+
const data = { ...view, definition, definition_id: definition.definition_id,
|
|
84
|
+
devices: this.candidates(snapshot, command.path),
|
|
85
|
+
detail_ref: selected.detail_ref, ...(contract.release ? { release: contract.release } : {}) };
|
|
86
|
+
if (command.options.usage) {
|
|
87
|
+
const reference = selected.usage_ref ?? snapshot.skillRef;
|
|
88
|
+
if (contract.usage)
|
|
89
|
+
data.usage = { untrusted: true, reference: selected.detail_ref, content: contract.usage };
|
|
90
|
+
else if (reference)
|
|
91
|
+
data.usage = { untrusted: true, reference, content: await this.readUsage(snapshot, reference, transport) };
|
|
92
|
+
}
|
|
93
|
+
return response(data);
|
|
94
|
+
}
|
|
95
|
+
remoteAssert(isJsonObject(params), 'PARAMS_INVALID', 'Business params must be a JSON object');
|
|
96
|
+
validateValue(definition.params_schema, params, 'PARAMS_INVALID');
|
|
97
|
+
const aidWide = isAidWideDeviceStatusQuery({ type: 'ability', role: 'call', ability_path: command.path, params });
|
|
98
|
+
const candidates = selected.devices ?? [];
|
|
99
|
+
let deviceId = command.options['device-id'];
|
|
100
|
+
if (aidWide)
|
|
101
|
+
remoteAssert(!deviceId, 'ABILITY_DEVICE_NOT_ALLOWED', 'device/status read collects all responding devices; omit --device-id');
|
|
102
|
+
else {
|
|
103
|
+
remoteAssert(candidates.length, 'DISCOVERY_REQUIRED', 'No device evidence for this capability; run remote discover', { provider_aid: provider, ability_path: command.path });
|
|
104
|
+
if (deviceId)
|
|
105
|
+
remoteAssert(candidates.includes(deviceId), 'DEVICE_NOT_DISCOVERED', 'Selected device does not publish this capability');
|
|
106
|
+
else {
|
|
107
|
+
remoteAssert(candidates.length === 1, 'DEVICE_SELECTION_REQUIRED', 'Choose a device with --device-id', { devices: this.candidates(snapshot, command.path) });
|
|
108
|
+
deviceId = candidates[0];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const timeout = durationSeconds(command.options.timeout ?? '60s');
|
|
112
|
+
const ttl = durationSeconds(command.options.ttl ?? String(timeout));
|
|
113
|
+
const operationId = command.options['operation-id'] ?? `op-${randomUUID()}`;
|
|
114
|
+
const plan = { ...context, id: `plan-${randomUUID()}`, provider, path: command.path, definition, deviceId,
|
|
115
|
+
params, timeout, ttl, operationId, discoveryId: snapshot.id, expiresAt: Math.min(this.now() + 300_000, snapshot.expiresAt),
|
|
116
|
+
fingerprint: digest([provider, deviceId ?? null, command.path, definition.definition_id, params, ttl, timeout, false]) };
|
|
117
|
+
if (command.options['dry-run']) {
|
|
118
|
+
this.store.put('plan', plan.id, context.callerAid, plan);
|
|
119
|
+
return { ...response({ plan_id: plan.id, provider_aid: provider, ability_path: plan.path, definition_id: definition.definition_id,
|
|
120
|
+
device_id: deviceId, params, timeout_seconds: timeout, ttl_seconds: ttl, operation_id: operationId,
|
|
121
|
+
selection_source: snapshot.source, expires_at: plan.expiresAt, require_confirm: definition.require_confirm, auth_required: definition.auth_required }), sent: false };
|
|
122
|
+
}
|
|
123
|
+
return this.dispatch(plan, context, transport);
|
|
124
|
+
}
|
|
125
|
+
ownedDiscovery(id, context, provider) {
|
|
126
|
+
const found = this.store.get('discovery', id);
|
|
127
|
+
remoteAssert(found && sameScope(found, context) && found.provider === provider, 'DISCOVERY_NOT_FOUND', 'Discovery is not available for this Provider, session and topic');
|
|
128
|
+
remoteAssert(found.expiresAt > this.now(), 'DISCOVERY_REQUIRED', 'Discovery evidence expired; refresh it');
|
|
129
|
+
return found;
|
|
130
|
+
}
|
|
131
|
+
async discovery(command, context, transport) {
|
|
132
|
+
if (command.options.discovery)
|
|
133
|
+
return this.ownedDiscovery(command.options.discovery, context, command.provider);
|
|
134
|
+
if (!command.options.refresh) {
|
|
135
|
+
const cached = this.store.list('discovery', context.callerAid).filter(item => sameScope(item, context) && item.provider === command.provider && item.expiresAt > this.now())
|
|
136
|
+
.sort((a, b) => (b.source === 'online' ? 1 : 0) - (a.source === 'online' ? 1 : 0) || b.fetchedAt - a.fetchedAt)[0];
|
|
137
|
+
if (cached)
|
|
138
|
+
return cached;
|
|
139
|
+
}
|
|
140
|
+
const index = await this.readIndex(command.provider, transport);
|
|
141
|
+
const snapshot = { ...context, id: `discovery-${randomUUID()}`, provider: command.provider, source: 'index', fetchedAt: this.now(), expiresAt: this.now() + 300_000,
|
|
142
|
+
capabilities: index.capabilities, indexCapabilities: index.capabilities, skillRef: index.skill_ref, directory: index };
|
|
143
|
+
this.store.put('discovery', snapshot.id, context.callerAid, snapshot);
|
|
144
|
+
return snapshot;
|
|
145
|
+
}
|
|
146
|
+
async readUsage(snapshot, reference, transport) {
|
|
147
|
+
const key = digest([snapshot.id, reference]);
|
|
148
|
+
const cached = this.store.get('usage', key);
|
|
149
|
+
if (cached)
|
|
150
|
+
return cached.content;
|
|
151
|
+
const content = await transport.read(snapshot.provider, sameProviderPath(reference, snapshot.provider));
|
|
152
|
+
this.store.put('usage', key, snapshot.callerAid, { content });
|
|
153
|
+
return content;
|
|
154
|
+
}
|
|
155
|
+
async readIndex(provider, transport) {
|
|
156
|
+
let value;
|
|
157
|
+
let pathname = '/.well-known/ability/index.json';
|
|
158
|
+
try {
|
|
159
|
+
value = await transport.read(provider, pathname);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
const code = error.code;
|
|
163
|
+
if (!['OBJECT_NOT_FOUND', 'NOT_FOUND', 'ENOENT', 'FS_NOT_FOUND'].includes(code ?? ''))
|
|
164
|
+
throw error;
|
|
165
|
+
pathname = '/ability/index.json';
|
|
166
|
+
value = await transport.read(provider, pathname);
|
|
167
|
+
}
|
|
168
|
+
return { ...parseRemoteIndex(value, provider), indexRef: `${provider}:${pathname}` };
|
|
169
|
+
}
|
|
170
|
+
selectCapability(snapshot, abilityPath, definitionId) {
|
|
171
|
+
const rows = snapshot.capabilities.filter(row => row.path === abilityPath && (!definitionId || row.definition_id === definitionId));
|
|
172
|
+
remoteAssert(rows.length, 'ABILITY_NOT_FOUND', 'Exact ability path/definition is absent from discovery');
|
|
173
|
+
remoteAssert(new Set(rows.map(row => `${row.definition_id}:${row.release_id}:${row.detail_ref}`)).size === 1, 'CONTRACT_SELECTION_REQUIRED', 'Choose an exact definition with --definition-id', { candidates: rows });
|
|
174
|
+
return { ...rows[0], devices: [...new Set(rows.flatMap(row => row.devices ?? []))] };
|
|
175
|
+
}
|
|
176
|
+
candidates(snapshot, abilityPath) {
|
|
177
|
+
return snapshot.capabilities.filter(row => row.path === abilityPath).flatMap(row => (row.devices ?? []).map(device => ({
|
|
178
|
+
device_id: device, definition_id: row.definition_id, release_id: row.release_id, observed_at: snapshot.fetchedAt, evidence_source: snapshot.source,
|
|
179
|
+
})));
|
|
180
|
+
}
|
|
181
|
+
discoveryView(snapshot, abilityPath, options = {}) {
|
|
182
|
+
const { capabilities: _capabilities, indexRef, ...directory } = snapshot.directory ?? {};
|
|
183
|
+
const directoryFields = directory;
|
|
184
|
+
const full = !!options.full;
|
|
185
|
+
const metadata = full ? directory : Object.fromEntries(['schema', 'publisher', 'compatibility_schema', 'catalog_revision', 'updated_at', 'skill_ref']
|
|
186
|
+
.filter(key => ['string', 'number'].includes(typeof directoryFields[key])).map(key => [key, directoryFields[key]]));
|
|
187
|
+
const search = options.search?.toLowerCase();
|
|
188
|
+
const merged = new Map();
|
|
189
|
+
for (const row of snapshot.capabilities) {
|
|
190
|
+
const { devices, ...declaration } = row;
|
|
191
|
+
const key = JSON.stringify(declaration);
|
|
192
|
+
const previous = merged.get(key);
|
|
193
|
+
merged.set(key, { ...row, devices: [...new Set([...(previous?.devices ?? []), ...(devices ?? [])])] });
|
|
194
|
+
}
|
|
195
|
+
const rows = [...merged.values()].filter(row => (!abilityPath || row.path === abilityPath)
|
|
196
|
+
&& (!search || [row.path, row.name, row.summary, row.description].some(value => typeof value === 'string' && value.toLowerCase().includes(search))));
|
|
197
|
+
const page = Number(options.page ?? 1), limit = Number(options.limit ?? 20);
|
|
198
|
+
const start = (page - 1) * limit;
|
|
199
|
+
const capabilities = rows.slice(start, start + limit).map(row => full ? row : {
|
|
200
|
+
path: row.path, definition_id: row.definition_id,
|
|
201
|
+
...(typeof row.name === 'string' ? { name: row.name.slice(0, 80) } : {}),
|
|
202
|
+
...(typeof row.summary === 'string' || typeof row.description === 'string' ? { summary: String(row.summary ?? row.description).slice(0, 160) } : {}),
|
|
203
|
+
device_count: row.devices?.length ?? 0,
|
|
204
|
+
});
|
|
205
|
+
const next = start + capabilities.length < rows.length ? page + 1 : null;
|
|
206
|
+
const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
207
|
+
const nextCommand = next ? `ec ability remote list ${snapshot.provider}${abilityPath ? ` ${abilityPath}` : ''} --discovery ${snapshot.id} --page ${next} --limit ${limit}${full ? ' --full' : ''}${search ? ` --search ${quote(options.search)}` : ''}` : null;
|
|
208
|
+
return { subject_aid: snapshot.provider, provider_aid: snapshot.provider, discovery_id: snapshot.id, source: snapshot.source,
|
|
209
|
+
...(snapshot.directory ? { directory: metadata, ...(indexRef ? { index_ref: indexRef } : {}) } : {}),
|
|
210
|
+
fetched_at: snapshot.fetchedAt, expires_at: snapshot.expiresAt, stale: snapshot.expiresAt <= this.now(),
|
|
211
|
+
view: full ? 'full' : 'compact',
|
|
212
|
+
pagination: { page, limit, total: rows.length, returned: capabilities.length, next_page: next, next_command: nextCommand },
|
|
213
|
+
capabilities };
|
|
214
|
+
}
|
|
215
|
+
async discover(command, context, transport) {
|
|
216
|
+
const provider = command.provider;
|
|
217
|
+
let index = { capabilities: [] };
|
|
218
|
+
try {
|
|
219
|
+
index = await this.readIndex(provider, transport);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (!['OBJECT_NOT_FOUND', 'NOT_FOUND', 'ENOENT', 'FS_NOT_FOUND'].includes(error.code ?? ''))
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
await transport.authorize(provider, 'send');
|
|
226
|
+
const window = durationSeconds(command.options.window ?? '5s', 30);
|
|
227
|
+
const requestId = `c-${randomUUID()}`, operationId = `op-${randomUUID()}`;
|
|
228
|
+
const call = { ...context, provider, path: 'protocol/discover', requestId, operationId,
|
|
229
|
+
fingerprint: digest([provider, 'protocol/discover', operationId]), sent: null, createdAt: this.now(), discoveryIndex: index };
|
|
230
|
+
this.store.put('call', requestKey(context, requestId), context.callerAid, call);
|
|
231
|
+
try {
|
|
232
|
+
const sent = await transport.send(provider, { type: 'ability', role: 'call', call_id: requestId, operation_id: operationId,
|
|
233
|
+
ability_path: 'protocol/discover', params: { spec_version: 'aid-ability/2', window_seconds: window }, ttl: window, async: false }, undefined, window * 1000);
|
|
234
|
+
call.sent = sent.sent === false ? false : sent.sent === true || sent.message_id ? true : null;
|
|
235
|
+
if (!sent.ok)
|
|
236
|
+
call.error = { code: String(sent.code ?? 'TRANSPORT_FAILED'), message: String(sent.error ?? 'Discovery transport failed') };
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
call.error = { code: 'EXECUTION_UNKNOWN', message: 'Discovery transport result is unknown' };
|
|
240
|
+
}
|
|
241
|
+
this.store.put('call', requestKey(context, requestId), context.callerAid, call);
|
|
242
|
+
const record = await transport.get(requestId);
|
|
243
|
+
return this.discoveryResult(call, record, context, index, command.path, command.options);
|
|
244
|
+
}
|
|
245
|
+
discoveryResult(call, record, context, index = call.discoveryIndex ?? { capabilities: [] }, abilityPath, options = {}) {
|
|
246
|
+
if (record)
|
|
247
|
+
remoteAssert(record.selfAid === context.callerAid && record.targetAid === call.provider && record.origin?.sessionId === context.sessionId
|
|
248
|
+
&& record.origin?.peerKey === context.peerKey && record.origin?.threadId === context.threadId, 'REQUEST_NOT_FOUND', 'Request origin mismatch');
|
|
249
|
+
if (record?.outboundMessageId || record?.responseMessageId || record?.responses?.length)
|
|
250
|
+
call.sent = true;
|
|
251
|
+
if (call.discoveryId) {
|
|
252
|
+
const original = this.store.get('discovery', call.discoveryId);
|
|
253
|
+
if (original)
|
|
254
|
+
index = original.directory ?? { capabilities: original.indexCapabilities, skill_ref: original.skillRef };
|
|
255
|
+
}
|
|
256
|
+
const capabilities = [];
|
|
257
|
+
const devices = new Set();
|
|
258
|
+
let invalid = 0;
|
|
259
|
+
for (const item of record?.responses ?? []) {
|
|
260
|
+
try {
|
|
261
|
+
const result = validateAbilityResult(item.responsePayload, { callId: call.requestId, operationId: call.operationId, abilityPath: call.path });
|
|
262
|
+
remoteAssert(result.role === 'result' && result.ok === true && isJsonObject(result.result), 'RESULT_INVALID', 'Invalid discovery result');
|
|
263
|
+
const body = result.result;
|
|
264
|
+
remoteAssert(isJsonObject(body.protocol) && body.protocol.spec_version === 'aid-ability/2' && Array.isArray(body.capabilities) && item.responseDeviceId, 'RESULT_INVALID', 'Unsupported discovery profile');
|
|
265
|
+
boundedJson(body);
|
|
266
|
+
const rows = body.capabilities.map(row => parseCapability(row, call.provider, [item.responseDeviceId]));
|
|
267
|
+
capabilities.push(...rows);
|
|
268
|
+
devices.add(item.responseDeviceId);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
invalid++;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const closed = record?.state === 'completed';
|
|
275
|
+
const observedAt = record?.deadlineAt ?? call.createdAt;
|
|
276
|
+
const snapshot = { ...context, id: call.discoveryId ?? `discovery-${randomUUID()}`, provider: call.provider,
|
|
277
|
+
source: 'online', fetchedAt: observedAt, expiresAt: observedAt + 60_000, capabilities, indexCapabilities: index.capabilities, skillRef: index.skill_ref, directory: index };
|
|
278
|
+
if (devices.size && closed) {
|
|
279
|
+
this.store.put('discovery', snapshot.id, context.callerAid, snapshot);
|
|
280
|
+
call.discoveryId = snapshot.id;
|
|
281
|
+
this.store.put('call', requestKey(context, call.requestId), context.callerAid, call);
|
|
282
|
+
}
|
|
283
|
+
const data = { ...this.discoveryView(snapshot, abilityPath, options), request_id: call.requestId, devices: [...devices], window_closed: closed,
|
|
284
|
+
response_count: record?.responses?.length ?? 0, invalid_response_count: invalid, coverage: 'responding_devices_only' };
|
|
285
|
+
const code = invalid ? 'PARTIAL_RESULT' : devices.size && closed ? undefined : call.error?.code ?? (!devices.size ? 'NO_DISCOVERY_RESPONSE' : 'RESULT_PENDING');
|
|
286
|
+
return { ...response(data, !code, code), sent: call.sent,
|
|
287
|
+
...(code ? { next_action: { command: `ec ability remote result ${call.requestId}`, resend_allowed: false } } : {}) };
|
|
288
|
+
}
|
|
289
|
+
async dispatch(plan, context, transport) {
|
|
290
|
+
await transport.authorize(plan.provider, 'send');
|
|
291
|
+
const key = operationKey(context, plan.provider, plan.operationId);
|
|
292
|
+
const existing = this.store.get('operation', key);
|
|
293
|
+
if (existing) {
|
|
294
|
+
remoteAssert(sameScope(existing, context), 'OPERATION_ID_CONFLICT', 'Operation ID is already bound to another origin');
|
|
295
|
+
remoteAssert(existing.fingerprint === plan.fingerprint, 'OPERATION_ID_CONFLICT', 'Operation ID is already bound to different parameters');
|
|
296
|
+
return this.query(existing, context, transport);
|
|
297
|
+
}
|
|
298
|
+
remoteAssert(plan.expiresAt > this.now(), 'PLAN_EXPIRED', 'Call plan or discovery evidence expired');
|
|
299
|
+
this.ownedDiscovery(plan.discoveryId, context, plan.provider);
|
|
300
|
+
const call = { ...context, provider: plan.provider, path: plan.path, definition: plan.definition, deviceId: plan.deviceId,
|
|
301
|
+
requestId: `c-${randomUUID()}`, operationId: plan.operationId, fingerprint: plan.fingerprint, sent: null, createdAt: this.now() };
|
|
302
|
+
// Claim before the first await/send. A crash at any later point leaves an
|
|
303
|
+
// unknown receipt which is queried, never automatically dispatched again.
|
|
304
|
+
this.store.transaction(() => {
|
|
305
|
+
remoteAssert(!this.store.get('operation', key), 'OPERATION_ID_CONFLICT', 'Operation was concurrently claimed');
|
|
306
|
+
this.store.put('operation', key, context.callerAid, call);
|
|
307
|
+
this.store.put('call', requestKey(context, call.requestId), context.callerAid, call);
|
|
308
|
+
});
|
|
309
|
+
try {
|
|
310
|
+
const sent = await transport.send(call.provider, { type: 'ability', role: 'call', call_id: call.requestId, operation_id: call.operationId,
|
|
311
|
+
ability_path: call.path, definition_id: plan.definition.definition_id, params: plan.params, ttl: plan.ttl, async: false }, call.deviceId, plan.timeout * 1000);
|
|
312
|
+
call.sent = sent.sent === false ? false : sent.sent === true || sent.message_id ? true : null;
|
|
313
|
+
if (!sent.ok)
|
|
314
|
+
call.error = { code: String(sent.code ?? 'TRANSPORT_FAILED'), message: String(sent.error ?? 'Transport failed') };
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
call.error = { code: 'EXECUTION_UNKNOWN', message: 'Transport result is unknown; query the original request' };
|
|
318
|
+
}
|
|
319
|
+
this.store.transaction(() => {
|
|
320
|
+
this.store.put('operation', key, context.callerAid, call);
|
|
321
|
+
this.store.put('call', requestKey(context, call.requestId), context.callerAid, call);
|
|
322
|
+
});
|
|
323
|
+
return this.query(call, context, transport);
|
|
324
|
+
}
|
|
325
|
+
async query(call, context, transport, waitMs) {
|
|
326
|
+
await transport.authorize(call.provider, 'history');
|
|
327
|
+
const record = await transport.get(call.requestId, waitMs);
|
|
328
|
+
if (record)
|
|
329
|
+
remoteAssert(record.selfAid === context.callerAid && record.targetAid === call.provider && record.origin?.sessionId === context.sessionId
|
|
330
|
+
&& record.origin?.peerKey === context.peerKey && record.origin?.threadId === context.threadId, 'REQUEST_NOT_FOUND', 'Request origin mismatch');
|
|
331
|
+
if (record?.outboundMessageId || record?.responseMessageId || record?.responses?.length)
|
|
332
|
+
call.sent = true;
|
|
333
|
+
if (call.path === 'protocol/discover')
|
|
334
|
+
return this.discoveryResult(call, record, context);
|
|
335
|
+
const data = { provider_aid: call.provider, ability_path: call.path, definition_id: call.definition?.definition_id,
|
|
336
|
+
device_id: call.deviceId, call_id: call.requestId, operation_id: call.operationId, request_id: call.requestId,
|
|
337
|
+
transport_state: record?.state ?? 'unknown', execution_state: 'unknown', business_ok: null,
|
|
338
|
+
result_validated: false, ack_received: !!record?.ackMessageId, result: null,
|
|
339
|
+
may_have_executed: call.sent !== false };
|
|
340
|
+
const pending = (code, error) => ({ ...response(data, false, code), sent: call.sent, ...(error ? { error } : {}),
|
|
341
|
+
next_action: { command: `ec ability remote result ${call.requestId} --wait 30s`, resend_allowed: false } });
|
|
342
|
+
if (call.sent === false && call.error && record?.state !== 'completed') {
|
|
343
|
+
return { ...remoteFailure(new RemoteError(call.error.code, call.error.message)), data, sent: false, stage: 'send',
|
|
344
|
+
next_action: { action: 'stop', resend_allowed: false } };
|
|
345
|
+
}
|
|
346
|
+
if (record?.state !== 'completed')
|
|
347
|
+
return pending(call.error?.code ?? (record?.state === 'failed' ? 'TRANSPORT_FAILED' : record?.state === 'unknown' || !record ? 'EXECUTION_UNKNOWN' : 'RESULT_PENDING'), call.error?.message);
|
|
348
|
+
const validate = (payload) => {
|
|
349
|
+
remoteAssert(call.definition, 'RESULT_INVALID', 'Original contract is unavailable');
|
|
350
|
+
const result = validateAbilityResult(payload, { callId: call.requestId, operationId: call.operationId, abilityPath: call.path, definitionId: call.definition.definition_id });
|
|
351
|
+
remoteAssert(result.role === 'result', 'RESULT_INVALID', 'ACK is not a final result');
|
|
352
|
+
if (result.ok)
|
|
353
|
+
validateValue(call.definition.result_schema, result.result, 'RESULT_INVALID');
|
|
354
|
+
return { execution_state: result.execution_state, business_ok: result.ok, result_validated: true,
|
|
355
|
+
result: result.ok ? result.result : null, ...(result.ok ? {} : { provider_error: result.error }) };
|
|
356
|
+
};
|
|
357
|
+
try {
|
|
358
|
+
if (record.responseMode === 'all_devices') {
|
|
359
|
+
const results = (record.responses ?? []).map(item => {
|
|
360
|
+
try {
|
|
361
|
+
return { device_id: item.responseDeviceId, ...validate(item.responsePayload) };
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
return { device_id: item.responseDeviceId, business_ok: false, result_validated: false, code: 'RESULT_INVALID' };
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
const ok = results.length > 0 && results.every(item => item.business_ok === true && item.result_validated);
|
|
368
|
+
return { ...response({ ...data, results, collection_state: 'window_closed', coverage: 'responding_devices_only', business_ok: ok,
|
|
369
|
+
result_validated: results.length > 0 && results.every(item => item.result_validated) }, ok, ok ? undefined : 'PARTIAL_RESULT'), sent: call.sent };
|
|
370
|
+
}
|
|
371
|
+
remoteAssert(record.responseDeviceId === call.deviceId, 'RESULT_INVALID', 'Result did not originate from the selected device');
|
|
372
|
+
const result = validate(record.responsePayload);
|
|
373
|
+
const code = result.business_ok ? undefined : result.execution_state === 'unknown' ? 'EXECUTION_UNKNOWN' : 'BUSINESS_FAILED';
|
|
374
|
+
return { ...response({ ...data, ...result }, result.business_ok, code), sent: call.sent };
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
return pending('RESULT_INVALID', error instanceof Error ? error.message : 'Invalid result');
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -2,8 +2,10 @@ import { abilityAssert } from './types.js';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { getPackageRoot } from '../paths.js';
|
|
5
|
+
import { REMOTE_CLI_VERSION, REMOTE_COMMANDS, remoteCommandSchema } from './caller/command.js';
|
|
5
6
|
export const ABILITY_COMMAND_VERSION = 'evolcore.ability-cli/v1';
|
|
6
7
|
export const ABILITY_COMMANDS = {
|
|
8
|
+
remote: { description: '远端 AUN 能力发现、契约、设备、调用与结果查询;见 remote --help' },
|
|
7
9
|
capabilities: { description: '查询 daemon 实际支持的命令' },
|
|
8
10
|
schema: { description: '查询命令或 manifest/project JSON Schema', positional: 'required' },
|
|
9
11
|
targets: { description: '列出有权读取的 Agent/host AID' },
|
|
@@ -62,11 +64,14 @@ export function parseAbilityOptions(args, command) {
|
|
|
62
64
|
}
|
|
63
65
|
export function abilityCapabilities() {
|
|
64
66
|
return { schemaVersion: ABILITY_COMMAND_VERSION, commands: ABILITY_COMMANDS, development: ABILITY_DEV_COMMANDS,
|
|
67
|
+
remote: { schemaVersion: REMOTE_CLI_VERSION, commands: REMOTE_COMMANDS, managedAunSessionRequired: true, automaticRetry: false, asynchronousSubmission: false },
|
|
65
68
|
features: { selfSelection: true, localArchive: true, runtimeDefaultCommands: true, buildAdapters: ['java', 'go', 'rust', 'command'], environmentAutoInstall: false,
|
|
66
69
|
ownerSelfManagementPolicy: false, separateCodeApprovalQueue: false, isolatedDevTest: false, persistedLogs: false },
|
|
67
70
|
output: { success: '{ok:true,data}', failure: '{ok:false,status,code,error}', jobSubmissionIsCompletion: false } };
|
|
68
71
|
}
|
|
69
72
|
export function abilityCommandSchema(operation) {
|
|
73
|
+
if (operation.startsWith('remote.'))
|
|
74
|
+
return remoteCommandSchema(operation.slice('remote.'.length));
|
|
70
75
|
if (operation === 'manifest' || operation === 'project') {
|
|
71
76
|
const filename = operation === 'manifest' ? 'ability-plugin.schema.1.json' : 'ability-project.schema.1.json';
|
|
72
77
|
return { schemaVersion: ABILITY_COMMAND_VERSION, operation, input: JSON.parse(fs.readFileSync(path.join(getPackageRoot(), 'kits/schemas', filename), 'utf8')) };
|
package/dist/ability/daemon.js
CHANGED
|
@@ -9,6 +9,7 @@ import { createDelegationAuthorizer } from '../core/auth/delegation-authorizatio
|
|
|
9
9
|
import { AUNChannel } from '../channels/aun.js';
|
|
10
10
|
import { logger } from '../utils/logger.js';
|
|
11
11
|
import { resolveEffective } from '../config/config-manager.js';
|
|
12
|
+
import { createRemoteAbilityExecutor } from './caller/daemon.js';
|
|
12
13
|
export function registerAbilityPlatform(root, deps) {
|
|
13
14
|
const delegated = createDelegationAuthorizer(deps);
|
|
14
15
|
const channels = () => [deps.getControlChannel?.(), ...deps.channelInstances.map(item => item.channel)].filter((item) => item instanceof AUNChannel);
|
|
@@ -77,7 +78,10 @@ export function registerAbilityPlatform(root, deps) {
|
|
|
77
78
|
await channel.publishAbilityDocuments(documents, expectedIndexes);
|
|
78
79
|
},
|
|
79
80
|
});
|
|
81
|
+
const remote = createRemoteAbilityExecutor(root, deps, channels);
|
|
80
82
|
deps.ipcServer.setAbilityExecutor(async (command) => {
|
|
83
|
+
if (command.type === 'ability.remote.op')
|
|
84
|
+
return remote.execute(command);
|
|
81
85
|
try {
|
|
82
86
|
let actor;
|
|
83
87
|
let context = { authentication: 'ecweb' };
|
|
@@ -133,5 +137,5 @@ export function registerAbilityPlatform(root, deps) {
|
|
|
133
137
|
const recovery = service.recover().catch(() => logger.warn('[ability] Recovery incomplete; inspect AID plugin state'));
|
|
134
138
|
const timer = setInterval(reconcilePublication, 30000);
|
|
135
139
|
timer.unref();
|
|
136
|
-
return { async close() { closing = true; clearInterval(timer); removeProvider(); await recovery; await reconcile; await service.close(); } };
|
|
140
|
+
return { async close() { closing = true; clearInterval(timer); removeProvider(); await recovery; await reconcile; await service.close(); remote.close(); } };
|
|
137
141
|
}
|
|
@@ -265,10 +265,12 @@ function validateSchemaValue(schema, value, path) {
|
|
|
265
265
|
if (!valid)
|
|
266
266
|
fail(`example does not match ${path}`, 'contract_invalid', path);
|
|
267
267
|
if (schema.const !== undefined && canonicalJson(schema.const) !== canonicalJson(value)) {
|
|
268
|
-
|
|
268
|
+
const expected = JSON.stringify(schema.const);
|
|
269
|
+
fail(`value at ${path} must equal ${expected.length > 512 ? `${expected.slice(0, 512)}… (see contract for full value)` : expected}`, 'contract_invalid', path);
|
|
269
270
|
}
|
|
270
271
|
if (Array.isArray(schema.enum) && !schema.enum.some(item => canonicalJson(item) === canonicalJson(value))) {
|
|
271
|
-
|
|
272
|
+
const allowed = JSON.stringify(schema.enum);
|
|
273
|
+
fail(`value at ${path} must be one of ${allowed.length > 512 ? `${allowed.slice(0, 512)}… (see contract for all values)` : allowed}`, 'contract_invalid', path);
|
|
272
274
|
}
|
|
273
275
|
if (type === 'object') {
|
|
274
276
|
const object = value;
|
|
@@ -280,7 +282,7 @@ function validateSchemaValue(schema, value, path) {
|
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
284
|
for (const [key, child] of Object.entries(object)) {
|
|
283
|
-
if (isJsonObject(properties[key]))
|
|
285
|
+
if (Object.hasOwn(properties, key) && isJsonObject(properties[key]))
|
|
284
286
|
validateSchemaValue(properties[key], child, `${path}.${key}`);
|
|
285
287
|
else if (schema.additionalProperties === false)
|
|
286
288
|
fail(`example has unknown ${path}.${key}`, 'contract_invalid', path);
|
|
@@ -309,6 +311,11 @@ function validateSchemaValue(schema, value, path) {
|
|
|
309
311
|
fail(`example is above maximum`, 'contract_invalid', path);
|
|
310
312
|
}
|
|
311
313
|
}
|
|
314
|
+
/** Shared Caller-side value validation using the supported wire Schema profile. */
|
|
315
|
+
export function validateAbilityValue(schema, value) {
|
|
316
|
+
validateSchemaProfile(schema);
|
|
317
|
+
validateSchemaValue(schema, value, 'value');
|
|
318
|
+
}
|
|
312
319
|
function canonicalJson(value) {
|
|
313
320
|
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
314
321
|
return JSON.stringify(value);
|
|
@@ -8,6 +8,7 @@ export function parseAbilityArgv(argv, context = {}) {
|
|
|
8
8
|
abilityAssert(Array.isArray(argv) && argv[0] === 'ability', 'ARGUMENT_INVALID', 'Expected ability command');
|
|
9
9
|
const [, operation, ...args] = argv;
|
|
10
10
|
abilityAssert(Object.hasOwn(ABILITY_COMMANDS, operation), 'ACTION_UNSUPPORTED', 'Unknown ability command');
|
|
11
|
+
abilityAssert(operation !== 'remote', 'ACTION_UNSUPPORTED', 'Remote commands require the managed ability.remote.op endpoint');
|
|
11
12
|
const { values, positional } = parseAbilityOptions(args, ABILITY_COMMANDS[operation]);
|
|
12
13
|
let input = {};
|
|
13
14
|
if (values.file) {
|