evolcore 0.0.49 → 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.
Files changed (250) hide show
  1. package/CHANGELOG.md +64 -1
  2. package/bin/ecmsg.js +9 -4
  3. package/dist/ability/caller/authorization.js +21 -0
  4. package/dist/ability/caller/command.js +164 -0
  5. package/dist/ability/caller/contract.js +102 -0
  6. package/dist/ability/caller/daemon.js +158 -0
  7. package/dist/ability/caller/service.js +380 -0
  8. package/dist/ability/command-contract.js +5 -0
  9. package/dist/ability/daemon.js +5 -1
  10. package/dist/ability/interop-v1.js +10 -3
  11. package/dist/ability/management.js +1 -0
  12. package/dist/agent-template/jobs.js +173 -1
  13. package/dist/agent-template/runtime.js +280 -6
  14. package/dist/agent-template/service.js +1159 -40
  15. package/dist/agent-template/types.js +2 -1
  16. package/dist/agents/baseagent-availability.js +27 -3
  17. package/dist/agents/baseagent-capability-adapter.js +102 -0
  18. package/dist/agents/baseagent-plugin-descriptor.js +274 -0
  19. package/dist/agents/baseagent-plugin-loader.js +145 -0
  20. package/dist/agents/baseagent.js +68 -2
  21. package/dist/agents/claude-gateway/agent-registration.js +389 -0
  22. package/dist/agents/claude-gateway/binding.js +96 -0
  23. package/dist/agents/claude-gateway/inbox.js +138 -0
  24. package/dist/agents/claude-gateway/index.js +125 -0
  25. package/dist/agents/claude-gateway/listing.js +330 -0
  26. package/dist/agents/claude-gateway/router.js +328 -0
  27. package/dist/agents/claude-gateway/sessions.js +128 -0
  28. package/dist/agents/claude-gateway/terminal.js +250 -0
  29. package/dist/agents/claude-gateway/transcript.js +272 -0
  30. package/dist/agents/claude-gateway/types.js +14 -0
  31. package/dist/agents/claude-runner.js +6 -10
  32. package/dist/agents/codex-runner.js +4 -1
  33. package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
  34. package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
  35. package/dist/agents/gemini/index.js +51 -0
  36. package/dist/aun/aid/control-aid.js +52 -32
  37. package/dist/aun/group/invite-service.js +6 -36
  38. package/dist/aun/group/operations.js +6 -0
  39. package/dist/aun/msg/mention-schema.js +1 -1
  40. package/dist/aun/msg/p2p.js +29 -1
  41. package/dist/aun/msg/upload.js +126 -3
  42. package/dist/build-identity.json +1 -1
  43. package/dist/channels/aun.js +537 -189
  44. package/dist/cli/ability-command.js +42 -0
  45. package/dist/cli/agent-command.js +20 -1
  46. package/dist/cli/agent-create.js +78 -18
  47. package/dist/cli/agent-template.js +5 -3
  48. package/dist/cli/agent.js +91 -0
  49. package/dist/cli/aun-commands.js +92 -34
  50. package/dist/cli/bench.js +5 -2
  51. package/dist/cli/config.js +22 -6
  52. package/dist/cli/daemon-commands.js +245 -101
  53. package/dist/cli/ecmsg-gateway.js +11 -9
  54. package/dist/cli/index.js +23 -4
  55. package/dist/cli/init.js +39 -63
  56. package/dist/cli/managed-command-guard.js +1 -0
  57. package/dist/cli/menu-client.js +32 -7
  58. package/dist/cli/pay-command.js +30 -0
  59. package/dist/cli/provider-command.js +6 -2
  60. package/dist/cli/restart-monitor.js +2 -2
  61. package/dist/cli/services-command.js +11 -9
  62. package/dist/cli/thread-command.js +78 -12
  63. package/dist/config/access-policy.js +16 -3
  64. package/dist/config/config-field-policy.js +17 -8
  65. package/dist/config/config-manager.js +86 -46
  66. package/dist/config/config-operation-service.js +22 -1
  67. package/dist/config/gateway-config.js +9 -8
  68. package/dist/config/owner-config.js +0 -16
  69. package/dist/config/peer-role-resolver.js +1 -7
  70. package/dist/config/providers-config.js +99 -16
  71. package/dist/config/providers-management.js +35 -19
  72. package/dist/config/resolved-config-op.js +1 -42
  73. package/dist/config/schema-migration.js +78 -5
  74. package/dist/config/schema-registry.js +52 -7
  75. package/dist/config-store.js +1309 -17
  76. package/dist/core/agent-application-service.js +220 -1
  77. package/dist/core/agent-ipc-registration.js +19 -2
  78. package/dist/core/agent-reload-coordinator.js +5 -0
  79. package/dist/core/agent-runtime.js +198 -54
  80. package/dist/core/auth/agent-delegation.js +14 -0
  81. package/dist/core/auth/operation-authorizer.js +16 -1
  82. package/dist/core/auth/operation-catalog.js +50 -7
  83. package/dist/core/baseagent-loader.js +30 -3
  84. package/dist/core/capability/capability-manager.js +16 -7
  85. package/dist/core/channel-runtime.js +4 -2
  86. package/dist/core/command/agent-control.js +20 -2
  87. package/dist/core/command/agent-template-menu.js +4 -3
  88. package/dist/core/command/cli-intent-parser.js +15 -0
  89. package/dist/core/command/menu-catalog.js +20 -4
  90. package/dist/core/command/menu-file-path.js +70 -0
  91. package/dist/core/command/menu-handler.js +91 -72
  92. package/dist/core/command/menu-protocol.js +5 -0
  93. package/dist/core/command/menu-query-batch.js +2 -2
  94. package/dist/core/command/private-mention-menu.js +71 -0
  95. package/dist/core/command/slash-handler.js +17 -26
  96. package/dist/core/command/team-workspace-bootstrap.js +2 -1
  97. package/dist/core/command/topic-slash.js +7 -1
  98. package/dist/core/daemon-bootstrap.js +0 -4
  99. package/dist/core/daemon-control.js +2 -1
  100. package/dist/core/daemon-lifecycle.js +13 -5
  101. package/dist/core/evolagent-registry.js +12 -7
  102. package/dist/core/handoff/runtime.js +1 -1
  103. package/dist/core/host-snapshot.js +8 -3
  104. package/dist/core/initialization/service.js +3 -0
  105. package/dist/core/interaction-router.js +130 -0
  106. package/dist/core/ipc-registration.js +4 -0
  107. package/dist/core/memory/consolidation-context.js +2 -1
  108. package/dist/core/memory/consolidation.js +35 -64
  109. package/dist/core/message/aun-ipc-sender.js +98 -21
  110. package/dist/core/message/aun-request-registry.js +31 -0
  111. package/dist/core/message/message-bridge.js +105 -6
  112. package/dist/core/message/message-log.js +8 -0
  113. package/dist/core/message/message-queue.js +5 -3
  114. package/dist/core/message/peer-mode.js +15 -4
  115. package/dist/core/message/response-engine.js +23 -8
  116. package/dist/core/message/send-options.js +37 -3
  117. package/dist/core/message/send-routing.js +11 -7
  118. package/dist/core/model/model-catalog.js +5 -5
  119. package/dist/core/ownership/owner-resolver.js +12 -86
  120. package/dist/core/pack-auth.js +4 -0
  121. package/dist/core/permission/ec-command-parser.js +182 -58
  122. package/dist/core/permission/protected-paths.js +64 -9
  123. package/dist/core/permission/services-path-acl.js +9 -2
  124. package/dist/core/permission/tool-policy.js +21 -9
  125. package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
  126. package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
  127. package/dist/core/session/session-manager.js +47 -10
  128. package/dist/core/session/session-mapper.js +16 -0
  129. package/dist/core/skill/index-generator.js +2 -3
  130. package/dist/core/skill/switch-resolver.js +3 -0
  131. package/dist/core/thread/command-parser.js +4 -1
  132. package/dist/core/thread/ipc-operation.js +4 -2
  133. package/dist/core/thread/thread-operation.js +25 -10
  134. package/dist/core/thread/thread-service.js +294 -55
  135. package/dist/core/thread/topic-id.js +52 -2
  136. package/dist/core/thread/types.js +15 -1
  137. package/dist/eck/kit-renderer.js +2 -1
  138. package/dist/ecweb/basic-settings-service.js +5 -9
  139. package/dist/ecweb/providers-service.js +4 -2
  140. package/dist/index.js +116 -41
  141. package/dist/ipc.js +58 -2
  142. package/dist/paths.js +48 -1
  143. package/dist/pay/command.js +38 -0
  144. package/dist/pay/protocol.js +136 -0
  145. package/dist/pay/runtime.js +188 -0
  146. package/dist/pay/service.js +384 -0
  147. package/dist/pay/store.js +81 -0
  148. package/dist/response-system/engines/v1/proactive-flow.js +29 -2
  149. package/dist/services/dispatcher.js +23 -5
  150. package/dist/services/host/main.js +388 -0
  151. package/dist/services/host/protocol.js +118 -0
  152. package/dist/services/host/resident.js +310 -0
  153. package/dist/services/host-client.js +386 -0
  154. package/dist/services/host-deploy.js +180 -0
  155. package/dist/services/host-launch.js +117 -0
  156. package/dist/services/host-recycle.js +203 -0
  157. package/dist/services/host-runtime.js +802 -0
  158. package/dist/services/idempotency.js +44 -86
  159. package/dist/services/index-generator.js +4 -3
  160. package/dist/services/index.js +176 -18
  161. package/dist/services/ipc-operation.js +204 -44
  162. package/dist/services/script-runner.js +515 -83
  163. package/dist/services/validation.js +109 -4
  164. package/dist/trigger/application-service.js +6 -4
  165. package/dist/trigger/local-files.js +19 -9
  166. package/dist/trigger/scheduler.js +22 -12
  167. package/dist/trigger/script-sandbox.js +51 -20
  168. package/dist/utils/aid-bind.js +3 -0
  169. package/dist/utils/evolcore-version.js +2 -2
  170. package/dist/utils/host-info.js +73 -0
  171. package/dist/utils/logger.js +2 -2
  172. package/dist/utils/media-cache.js +190 -43
  173. package/dist/utils/restart-safety.js +14 -1
  174. package/dist/utils/system-memory.js +113 -25
  175. package/dist/utils/systemd-lifecycle.js +154 -0
  176. package/dist/utils/windows-shell-trust.js +7 -3
  177. package/kits/docs/INDEX.md +3 -2
  178. 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
  179. package/kits/docs/channels/aun.md +1 -1
  180. package/kits/docs/evolcore/INDEX.md +7 -6
  181. package/kits/docs/evolcore/agent.md +36 -1
  182. package/kits/docs/evolcore/aid.md +20 -3
  183. package/kits/docs/evolcore/config.md +1 -1
  184. package/kits/docs/evolcore/group.md +2 -1
  185. package/kits/docs/evolcore/memory-tags.md +2 -0
  186. package/kits/docs/evolcore/menu-client.md +3 -3
  187. package/kits/docs/evolcore/menu-protocol.md +7 -0
  188. package/kits/docs/evolcore/model.md +3 -0
  189. package/kits/docs/evolcore/msg.md +68 -10
  190. package/kits/docs/evolcore/pay.md +34 -0
  191. package/kits/docs/evolcore/provider.md +21 -0
  192. package/kits/docs/evolcore/services.md +46 -18
  193. package/kits/docs/evolcore/thread-chain.md +2 -0
  194. package/kits/docs/evolcore/tool-authorization.md +10 -0
  195. package/kits/rules/01-overview.md +11 -32
  196. package/kits/rules/02-navigation.md +7 -0
  197. package/kits/rules/06-channel.md +3 -3
  198. package/kits/schemas/_meta.json +38 -5
  199. package/kits/schemas/agent-config.schema.21.json +974 -0
  200. package/kits/schemas/agent-config.schema.22.json +977 -0
  201. package/kits/schemas/agent-config.schema.23.json +958 -0
  202. package/kits/schemas/daemon.schema.10.json +373 -0
  203. package/kits/schemas/daemon.schema.9.json +12 -0
  204. package/kits/schemas/defaults.schema.7.json +472 -0
  205. package/kits/schemas/providers.schema.3.json +18 -2
  206. package/kits/schemas/relation-config.schema.13.json +289 -0
  207. package/kits/skills/.switches.json +13 -1
  208. package/kits/skills/ability/SKILL.md +229 -34
  209. package/kits/skills/ability/STRUCTURE.md +333 -0
  210. package/kits/skills/ability/references/cli.md +208 -0
  211. package/kits/skills/ability/references/development.md +107 -37
  212. package/kits/skills/ability/references/management.md +106 -46
  213. package/kits/skills/ability/references/runtime-protocol.md +65 -63
  214. package/kits/skills/agent-output-cards/SKILL.md +12 -5
  215. package/kits/skills/ec-group/SKILL.md +8 -6
  216. package/kits/skills/ec-group/TASK.md +186 -0
  217. package/kits/skills/ec-group/WORKLOG.md +180 -0
  218. package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
  219. package/kits/skills/ec-pay/SKILL.md +101 -0
  220. package/kits/skills/ec-pay/references/pay-cli.md +110 -0
  221. package/kits/skills/ec-provider/SKILL.md +1 -1
  222. package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
  223. package/kits/skills/ec-service-call/SKILL.md +135 -0
  224. package/kits/skills/ec-service-pack/SKILL.md +277 -0
  225. package/kits/skills/ec-trigger/SKILL.md +1 -1
  226. package/kits/templates/memory-consolidation/notes.md +2 -2
  227. package/kits/templates/memory-consolidation/workflow.md +46 -0
  228. package/kits/templates/system-fragments/channel.md +13 -4
  229. package/kits/templates/system-fragments/commands.md +4 -3
  230. package/kits/templates/system-fragments/reply.md +1 -0
  231. package/kits/templates/system-fragments/session.md +1 -1
  232. package/kits/templates/system-fragments/thread.md +27 -129
  233. package/kits/templates/system-fragments/venue.md +16 -0
  234. package/package.json +4 -5
  235. package/scripts/agent-template/inspect.mjs +37 -23
  236. package/scripts/agent-template/overlay.mjs +20 -2
  237. package/scripts/agent-template/shared/common.mjs +16 -4
  238. package/scripts/agent-template/shared/team-schema.json +20 -4
  239. package/scripts/agent-template/shared/template-contract.mjs +53 -13
  240. package/scripts/agent-template/shared/template-package.mjs +90 -26
  241. package/scripts/agent-template/shared/template-runtime.mjs +111 -1
  242. package/scripts/agent-template/shared/template.mjs +65 -7
  243. package/scripts/agent-template/team-pack.mjs +89 -33
  244. package/scripts/agent-template/team-preview.mjs +249 -5
  245. package/kits/docs/aun/ABILITY_CALLING.md +0 -280
  246. package/kits/docs/evolcore/ability.md +0 -185
  247. package/kits/skills/ability/references/calling.md +0 -56
  248. package/kits/skills/ability/references/contract-checklist.md +0 -37
  249. package/kits/skills/ability/references/recovery.md +0 -27
  250. /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
package/dist/ipc.js CHANGED
@@ -79,6 +79,7 @@ const LOCAL_CONTROL_COMMANDS = new Set([
79
79
  'upgrade.op',
80
80
  'provider.op',
81
81
  'agent-template.op',
82
+ 'agent-project.op',
82
83
  'invoke.op',
83
84
  'ecweb.init',
84
85
  'ecweb.basic-settings',
@@ -100,8 +101,9 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
100
101
  'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
101
102
  ]);
102
103
  const DELEGATED_ARGV_ENDPOINTS = new Set([
104
+ 'pay.op',
103
105
  'quota.op',
104
- 'agent.op', 'ability.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op', 'invoke.op',
106
+ 'agent.op', 'ability.op', 'ability.remote.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op', 'invoke.op',
105
107
  'upgrade.op',
106
108
  'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
107
109
  'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', 'logs.query', ...MEMORY_COMMAND_ENDPOINTS,
@@ -140,7 +142,7 @@ function requiresLocalControlToken(cmd) {
140
142
  // Ownership has an explicit, non-fallback authentication contract below.
141
143
  if (type === 'aid.ownership')
142
144
  return false;
143
- if (type === 'skill.refresh' || type === 'thread.op' || type === 'events.op' || type === 'services.op')
145
+ if (type === 'skill.refresh' || type === 'thread.op' || type === 'events.op' || type === 'services.op' || type === 'pay.op')
144
146
  return !sessionId || !delegated;
145
147
  if (type === 'ability.op')
146
148
  return !sessionId && !delegated;
@@ -236,6 +238,9 @@ export class IpcServer {
236
238
  codexPreToolUseExecutor;
237
239
  aunMsgSender;
238
240
  aunRequestGetExecutor;
241
+ abilityRequestSender;
242
+ abilityRequestGetExecutor;
243
+ paymentExecutor;
239
244
  diagExecutor;
240
245
  menuClientExecutor;
241
246
  handoffReturnExecutor;
@@ -613,6 +618,21 @@ export class IpcServer {
613
618
  setAunRequestGetExecutor(executor) {
614
619
  this.aunRequestGetExecutor = executor;
615
620
  }
621
+ setAbilityRequestSender(sender) { this.abilityRequestSender = sender; }
622
+ setAbilityRequestGetExecutor(executor) { this.abilityRequestGetExecutor = executor; }
623
+ async sendAbilityRequest(params, originGrant) {
624
+ if (!this.abilityRequestSender)
625
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'Ability transport is not configured', sent: false };
626
+ return this.abilityRequestSender(params, originGrant);
627
+ }
628
+ async getAbilityRequest(params, originGrant) {
629
+ if (!this.abilityRequestGetExecutor)
630
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'Ability request registry is not configured' };
631
+ return this.abilityRequestGetExecutor(params, originGrant);
632
+ }
633
+ setPaymentExecutor(executor) {
634
+ this.paymentExecutor = executor;
635
+ }
616
636
  hasAunMsgSender() {
617
637
  return this.aunMsgSender !== undefined;
618
638
  }
@@ -621,6 +641,12 @@ export class IpcServer {
621
641
  throw new Error('aunMsgSender not configured');
622
642
  return this.aunMsgSender(params);
623
643
  }
644
+ /** In-process access retains the same origin and target authorization as IPC queries. */
645
+ async getAunRequest(params) {
646
+ if (!this.aunRequestGetExecutor)
647
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'AUN request registry is not configured' };
648
+ return this.aunRequestGetExecutor(params);
649
+ }
624
650
  setDiagExecutor(executor) { this.diagExecutor = executor; }
625
651
  setMenuClientExecutor(executor) { this.menuClientExecutor = executor; }
626
652
  /** Inject internal handoff result return executor for `ec handoff return`. */
@@ -1327,6 +1353,7 @@ export class IpcServer {
1327
1353
  return handleProvidersService(cmd.request);
1328
1354
  }
1329
1355
  case 'ability.op':
1356
+ case 'ability.remote.op':
1330
1357
  case 'ecweb.ability':
1331
1358
  return this.abilityExecutor ? this.abilityExecutor(cmd) : { ok: false, code: 'ABILITY_UNAVAILABLE', error: 'Ability service is unavailable', status: 503 };
1332
1359
  case 'ecweb.init': {
@@ -1897,6 +1924,16 @@ export class IpcServer {
1897
1924
  delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
1898
1925
  });
1899
1926
  }
1927
+ case 'pay.op': {
1928
+ if (!this.paymentExecutor)
1929
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'Payment runtime is not configured' };
1930
+ if (!Array.isArray(cmd.argv) || !cmd.argv.every((value) => typeof value === 'string')
1931
+ || typeof cmd.sessionId !== 'string' || !cmd.sessionId || !cmd.delegationToken || !cmd.delegationCommandHash) {
1932
+ return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Payment operations require an approved delegated command' };
1933
+ }
1934
+ return this.paymentExecutor({ argv: cmd.argv, sessionId: cmd.sessionId,
1935
+ delegationToken: cmd.delegationToken, delegationCommandHash: cmd.delegationCommandHash });
1936
+ }
1900
1937
  case 'aun-msg-send': {
1901
1938
  if (cmd.argv !== undefined) {
1902
1939
  if (!this.aunMsgSender)
@@ -1930,6 +1967,7 @@ export class IpcServer {
1930
1967
  contentType: typeof rawFile.contentType === 'string' ? rawFile.contentType : undefined,
1931
1968
  text: typeof rawFile.text === 'string' ? rawFile.text : undefined,
1932
1969
  transcript: typeof rawFile.transcript === 'string' ? rawFile.transcript : undefined,
1970
+ title: typeof rawFile.title === 'string' ? rawFile.title : undefined,
1933
1971
  }
1934
1972
  : undefined;
1935
1973
  if ((!payload && !file) || (payload && file)) {
@@ -2642,6 +2680,24 @@ export class IpcServer {
2642
2680
  return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message };
2643
2681
  }
2644
2682
  }
2683
+ case 'agent-project.op': {
2684
+ if (cmd.sessionId !== undefined || cmd.delegationToken !== undefined)
2685
+ return { ok: false, code: 'NOT_ALLOWED', error: 'Managed project commands must use agent.op' };
2686
+ if (!this.agentApplicationService)
2687
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'Agent service unavailable' };
2688
+ try {
2689
+ const { refreshOwnershipForAuthorization, getDaemonOwners } = await import('./core/ownership/owner-resolver.js');
2690
+ await refreshOwnershipForAuthorization(undefined, { force: true, allowTransient: false, source: 'agent-project-cli' });
2691
+ const actor = getDaemonOwners()[0];
2692
+ if (!actor)
2693
+ return { ok: false, code: 'NOT_ALLOWED', error: 'DaemonOwner required' };
2694
+ const { executeAgentProjectOperation } = await import('./cli/agent.js');
2695
+ return await executeAgentProjectOperation(actor, cmd.args, this.agentApplicationService);
2696
+ }
2697
+ catch (error) {
2698
+ return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message };
2699
+ }
2700
+ }
2645
2701
  case 'skill.refresh': {
2646
2702
  if (!this.skillRefreshExecutor) {
2647
2703
  return { ok: false, code: 'NOT_CONFIGURED', error: 'skill.refresh not configured' };
package/dist/paths.js CHANGED
@@ -171,6 +171,17 @@ export function agentRelationDir(aid, peerKey) {
171
171
  export function agentRelationSharedDir(aid, peerKey) {
172
172
  return path.join(agentRelationDir(aid, peerKey), 'shared');
173
173
  }
174
+ /**
175
+ * Agent 级附件目录:所有收发附件的文件本体都在这里,按内容去重。
176
+ * 与关系无关,同一份文件发给多个对端只占一份磁盘。
177
+ */
178
+ export function agentAttachmentsDir(aid) {
179
+ return path.join(agentDir(aid), 'attachments');
180
+ }
181
+ /** 关系归属索引:每个对端一个 `<peerKey>.jsonl`,只记元数据不存文件。 */
182
+ export function agentAttachmentIndexDir(aid) {
183
+ return path.join(agentAttachmentsDir(aid), 'index');
184
+ }
174
185
  /** @deprecated Use agentRelationsDir instead */
175
186
  export function agentIdentitiesDir(aid) {
176
187
  return agentRelationsDir(aid);
@@ -460,7 +471,9 @@ function migrateFromAun() {
460
471
  }
461
472
  }
462
473
  copyDirIfMissing(path.join(oldRoot, 'CA'), path.join(newRoot, 'CA'));
463
- for (const f of ['.seed', '.device_id']) {
474
+ // `.device_id.hmac` is the SDK-written guard for `.device_id`; migrating the
475
+ // pair together avoids a rewrite under the destination root's key.
476
+ for (const f of ['.seed', '.device_id', '.device_id.hmac']) {
464
477
  copyFileIfMissing(path.join(oldRoot, f), path.join(newRoot, f));
465
478
  }
466
479
  }
@@ -575,3 +588,37 @@ export function consumeAsModeOverride() {
575
588
  catch { /* ignore */ }
576
589
  return value === 'dev' || value === 'install' ? value : null;
577
590
  }
591
+ // ── 历史记录中的可迁移路径 ────────────────────────────────────────────────
592
+ //
593
+ // `messages.jsonl` 会跟着 `$EVOLCORE_HOME` 一起搬迁(换机器、换盘符)。
594
+ // 里存绝对路径,搬完后全部失效。因此历史正文里统一写别名路径,
595
+ // 由模型按系统提示里注入的别名值展开——别名值每轮渲染,天然跟着当前安装走。
596
+ const RELATIONS_DIR_ALIAS = '$RELATIONS_DIR/';
597
+ const AGENT_DIR_ALIAS = '$AGENT_DIR/';
598
+ function toAliasPath(prefix, baseDir, absolutePath) {
599
+ if (!baseDir)
600
+ return null;
601
+ const relative = path.relative(path.resolve(baseDir), path.resolve(absolutePath));
602
+ if (!relative || relative.startsWith('..') || path.isAbsolute(relative))
603
+ return null;
604
+ return prefix + relative.split(path.sep).join('/');
605
+ }
606
+ /**
607
+ * 附件落盘路径 → agent 级别名路径。
608
+ *
609
+ * 收发附件的文件本体统一放在 `$AGENT_DIR/attachments/` 下(按内容去重),
610
+ * 历史里记成 `$AGENT_DIR/attachments/<文件名>`;模型用 `[venue]` 段的
611
+ * AGENT_DIR 值展开,换机器/换盘符后仍然有效。
612
+ */
613
+ export function toAttachmentMarkedPath(selfAid, absolutePath) {
614
+ return toAliasPath(AGENT_DIR_ALIAS, agentDir(selfAid), absolutePath) ?? absolutePath;
615
+ }
616
+ /**
617
+ * 旧版附件路径 → 关系级别名路径。
618
+ *
619
+ * 升级前附件落在 `$RELATIONS_DIR/<peerKey>/attachments/`,历史里可能仍引用这些位置,
620
+ * 保留该转换供读取侧展开。
621
+ */
622
+ export function toRelationMarkedPath(selfAid, absolutePath) {
623
+ return toAliasPath(RELATIONS_DIR_ALIAS, agentRelationsDir(selfAid), absolutePath) ?? absolutePath;
624
+ }
@@ -0,0 +1,38 @@
1
+ import { PaymentError } from './protocol.js';
2
+ export const PAYMENT_HELP = `用法: ec pay request --spec-file <JSON文件>
3
+ ec pay status <request-id>
4
+ ec pay cancel <request-id>
5
+ ec pay verify <request-id>
6
+ ec pay refresh <request-id>
7
+ ec pay update <request-id> --spec-file <JSON文件>
8
+ ec pay complete <request-id> --event-id <event-id>
9
+
10
+ 可选 --format json;所有结果均为 JSON。仅当前 Owner 的 AUN 私聊托管任务可用。
11
+ request 上传二维码并发送付款 Action Card;verify/refresh 异步安排原任务。
12
+ update 提交待处理事件的订单核验及可选新码;complete 确认付款后的任务已处理。
13
+ 完整输入格式:kits/docs/evolcore/pay.md;遇到付款先加载 ec-pay 技能。`;
14
+ export function parsePaymentCommand(argv) {
15
+ const args = argv[0] === 'pay' ? argv.slice(1) : [...argv];
16
+ const format = args.indexOf('--format');
17
+ if (format >= 0) {
18
+ if (args[format + 1] !== 'json')
19
+ throw new PaymentError('INVALID_ARGUMENT', '--format only supports json');
20
+ args.splice(format, 2);
21
+ }
22
+ const [op, id, flag, value] = args;
23
+ if (op === 'request' && args.length === 3 && id === '--spec-file' && flag && !flag.startsWith('-')) {
24
+ return { operation: op, file: flag };
25
+ }
26
+ if (!id || !/^pay_[a-f0-9]{32}$/.test(id))
27
+ throw new PaymentError('INVALID_ARGUMENT', PAYMENT_HELP);
28
+ if (['status', 'cancel', 'verify', 'refresh'].includes(op) && args.length === 2) {
29
+ return { operation: op, requestId: id };
30
+ }
31
+ if (op === 'update' && args.length === 4 && flag === '--spec-file' && value && !value.startsWith('-')) {
32
+ return { operation: op, requestId: id, file: value };
33
+ }
34
+ if (op === 'complete' && args.length === 4 && flag === '--event-id' && /^payjob_[a-f0-9]{32}$/.test(value)) {
35
+ return { operation: op, requestId: id, eventId: value };
36
+ }
37
+ throw new PaymentError('INVALID_ARGUMENT', PAYMENT_HELP);
38
+ }
@@ -0,0 +1,136 @@
1
+ import { z } from 'zod';
2
+ export class PaymentError extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.code = code;
7
+ this.name = 'PaymentError';
8
+ }
9
+ }
10
+ const text = z.string().trim().min(1).max(2000);
11
+ const timestamp = z.number().int().nonnegative().safe();
12
+ export const providerSchema = z.enum(['wechat', 'alipay']);
13
+ const evidenceSource = z.enum(['page_text', 'page_dom', 'qr_payload', 'inferred', 'unknown']);
14
+ const methodSchema = z.object({
15
+ provider: providerSchema,
16
+ availability: z.enum(['ready', 'requires_site_switch', 'unavailable', 'unknown']),
17
+ qr_ids: z.array(z.string().min(1).max(100)).max(4),
18
+ evidence: z.object({ source: evidenceSource, text: text.optional() }).strict(),
19
+ }).strict();
20
+ const qrSchema = z.object({
21
+ id: z.string().regex(/^[A-Za-z0-9_-]{1,100}$/),
22
+ attachment_index: z.number().int().min(0).max(3),
23
+ providers: z.array(providerSchema).min(1).max(2),
24
+ source: z.enum(['page_image', 'page_screenshot', 'page_dom']),
25
+ expires_at_ms: timestamp.nullable().default(null),
26
+ raw_payload: z.string().min(1).max(8192).optional(),
27
+ }).strict();
28
+ export const mediaSchema = z.object({
29
+ attachments: z.array(z.object({ file_path: z.string().min(1).max(4096) }).strict()).max(4),
30
+ method_options: z.array(methodSchema).max(2),
31
+ qr_codes: z.array(qrSchema).max(4),
32
+ }).strict();
33
+ export const factsSchema = z.object({
34
+ source: z.object({
35
+ origin: z.string().url().refine(value => {
36
+ const url = new URL(value);
37
+ return url.protocol === 'https:' && !url.username && !url.password && url.origin === value;
38
+ }, 'origin must be an HTTPS origin without credentials, path or query'),
39
+ order_id: text.optional(), purpose: text.optional(),
40
+ }).strict(),
41
+ product: z.object({ title: text, description: text.optional(), quantity: z.number().int().positive().safe().optional(),
42
+ image_attachment_index: z.number().int().min(0).max(3).optional() }).strict(),
43
+ merchant: z.object({ name: text, source: evidenceSource }).strict().optional(),
44
+ amount: z.object({ value_minor: z.number().int().nonnegative().safe().nullable(),
45
+ currency: z.string().regex(/^[A-Z]{3}$/).nullable(), source: evidenceSource }).strict(),
46
+ }).strict();
47
+ export const requestSchema = factsSchema.extend(mediaSchema.shape).extend({
48
+ idempotency_key: z.string().regex(/^[A-Za-z0-9_-]{1,128}$/).optional(),
49
+ expires_at_ms: timestamp.optional(),
50
+ order_expires_at_ms: timestamp.nullable().default(null),
51
+ }).strict();
52
+ export const verificationSchema = z.object({
53
+ order_state: z.enum(['pending', 'paid', 'failed', 'unknown']),
54
+ source: z.enum(['website_order', 'website_success_page', 'payment_api']),
55
+ checked_at_ms: timestamp,
56
+ evidence: text,
57
+ order_id: text.optional(),
58
+ }).strict();
59
+ export const updateSchema = z.object({
60
+ expected_state_version: z.number().int().positive().safe(),
61
+ event_id: z.string().regex(/^payjob_[a-f0-9]{32}$/),
62
+ verification: verificationSchema.optional(),
63
+ media: mediaSchema.optional(),
64
+ }).strict().refine(value => !!value.verification || !!value.media, 'update must include verification or media');
65
+ export function validateMedia(media, now) {
66
+ const ids = new Set(media.qr_codes.map(qr => qr.id));
67
+ if (ids.size !== media.qr_codes.length || new Set(media.method_options.map(m => m.provider)).size !== media.method_options.length) {
68
+ throw new PaymentError('INVALID_ARGUMENT', 'Duplicate payment method or QR id');
69
+ }
70
+ for (const qr of media.qr_codes) {
71
+ if (qr.attachment_index >= media.attachments.length || new Set(qr.providers).size !== qr.providers.length) {
72
+ throw new PaymentError('QR_INVALID', 'QR attachment or provider binding is invalid');
73
+ }
74
+ }
75
+ for (const method of media.method_options) {
76
+ if (method.availability !== 'ready' && method.qr_ids.length) {
77
+ throw new PaymentError('METHOD_NOT_READY', 'Only ready methods may bind QR codes');
78
+ }
79
+ if (method.availability === 'ready' && (!method.qr_ids.length
80
+ || method.evidence.source === 'inferred' || method.evidence.source === 'unknown')) {
81
+ throw new PaymentError('METHOD_NOT_READY', 'Ready methods require explicit evidence and a QR code');
82
+ }
83
+ for (const id of method.qr_ids) {
84
+ const qr = media.qr_codes.find(q => q.id === id);
85
+ if (!qr || !qr.providers.includes(method.provider) || qr.expires_at_ms !== null && qr.expires_at_ms <= now) {
86
+ throw new PaymentError('QR_INVALID', 'Payment method references an invalid or expired QR');
87
+ }
88
+ }
89
+ }
90
+ }
91
+ export function paymentActions(p, now) {
92
+ if (p.order_state === 'paid')
93
+ return [];
94
+ const actions = [];
95
+ const active = p.request_state === 'active' && p.expires_at_ms > now
96
+ && (p.order_expires_at_ms === null || p.order_expires_at_ms > now);
97
+ if (active && p.order_state === 'pending') {
98
+ for (const method of p.method_options) {
99
+ const name = method.provider === 'wechat' ? '微信' : '支付宝';
100
+ if (method.availability === 'ready' && method.qr_ids.some(id => p.qr_codes.some(q => q.id === id
101
+ && (q.expires_at_ms === null || q.expires_at_ms > now)))) {
102
+ actions.push({ label: `使用${name}付款`, value: `pay.open.${method.provider}`, behavior: 'reply', style: 'primary' });
103
+ }
104
+ else if (method.availability === 'requires_site_switch') {
105
+ actions.push({ label: `切换${name}`, value: `pay.select.${method.provider}`, behavior: 'reply' });
106
+ }
107
+ }
108
+ actions.push({ label: '重新获取二维码', value: 'pay.refresh', behavior: 'reply' });
109
+ }
110
+ if (p.order_state !== 'verification_pending')
111
+ actions.push({ label: '我已付款,请核验', value: 'pay.verify', behavior: 'reply' });
112
+ if (p.request_state === 'active')
113
+ actions.push({ label: '取消本次请求', value: 'pay.cancel', behavior: 'reply' });
114
+ return actions;
115
+ }
116
+ export function buildPaymentCard(p, attachments, threadId, now = Date.now()) {
117
+ const amount = p.amount.value_minor === null || p.amount.currency === null ? '金额待确认'
118
+ : new Intl.NumberFormat('zh-CN', { style: 'currency', currency: p.amount.currency }).format(p.amount.value_minor / 10 ** (new Intl.NumberFormat('zh-CN', { style: 'currency', currency: p.amount.currency })
119
+ .resolvedOptions().maximumFractionDigits ?? 2));
120
+ const state = p.order_state === 'paid' ? '已付款' : p.order_state === 'verification_pending' ? '正在核验订单'
121
+ : p.request_state !== 'active' ? ({ expired: '请求已过期', cancelled: '请求已取消', superseded: '请求已替代' })[p.request_state]
122
+ : p.order_state === 'unknown' ? '付款结果待核验' : p.order_state === 'failed' ? '网站订单失败' : '待付款';
123
+ const text = `${p.product.title} · ${amount} · ${state}\n网站:${p.source.origin}`
124
+ + (p.source.order_id ? `\n订单:${p.source.order_id}` : '')
125
+ + (p.source.purpose ? `\n用途:${p.source.purpose}` : '')
126
+ + `\n本次请求有效至:${new Date(p.expires_at_ms).toISOString()}\n付款结果以原网站订单核验为准。`;
127
+ return { type: 'action_card', card_kind: 'payment', title: p.product.title, text, blocking: false,
128
+ ...(threadId ? { thread_id: threadId } : {}), attachments, actions: paymentActions(p, now), payment: p };
129
+ }
130
+ export function isPaymentControlPayload(payload) {
131
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload))
132
+ return false;
133
+ const value = payload;
134
+ return value.type === 'json' && typeof value.kind === 'string' && value.kind.startsWith('payment.')
135
+ || value.type === 'action_card_reply' && value.payment_action !== undefined;
136
+ }
@@ -0,0 +1,188 @@
1
+ import path from 'node:path';
2
+ import crypto from 'node:crypto';
3
+ import sharp from 'sharp';
4
+ import jsQR from 'jsqr';
5
+ import { agentDir } from '../paths.js';
6
+ import { readManagedLocalFile } from '../trigger/local-files.js';
7
+ import { currentContactBinding, sameContactBinding } from '../core/message/contact-admission.js';
8
+ import { PaymentError, isPaymentControlPayload } from './protocol.js';
9
+ import { PaymentStore } from './store.js';
10
+ import { PaymentService } from './service.js';
11
+ import { parsePaymentCommand } from './command.js';
12
+ import { sessionTopicThreadId } from '../core/thread/topic-id.js';
13
+ import { logger } from '../utils/logger.js';
14
+ const services = new Map();
15
+ export function paymentStore(aid) { return new PaymentStore(path.join(agentDir(aid), 'data', 'payments')); }
16
+ export async function consumePaymentInbound(selfAid, fromAid, payload, encrypted) {
17
+ const service = services.get(selfAid);
18
+ const value = payload && typeof payload === 'object' && !Array.isArray(payload) ? payload : undefined;
19
+ if (!value)
20
+ return false;
21
+ const ref = value.card_message_id;
22
+ const belongs = value.type === 'action_card_reply' && typeof ref === 'string' && ref.length <= 256
23
+ && !!paymentStore(selfAid).findCard(ref);
24
+ if (!belongs && !isPaymentControlPayload(payload))
25
+ return false;
26
+ if (!service)
27
+ return true; // Never leak payment controls into model input while runtime starts.
28
+ try {
29
+ return await service.inbound({ fromAid, payload: value, encrypted });
30
+ }
31
+ catch (error) {
32
+ logger.warn(`[Pay] Isolated payment control: ${error instanceof Error ? error.message : String(error)}`);
33
+ return true;
34
+ }
35
+ }
36
+ export async function preparePaymentMedia(media, scope, channel) {
37
+ const images = media.attachments.map(item => readManagedLocalFile(item.file_path, scope, 'attachment'));
38
+ const qrCodes = structuredClone(media.qr_codes);
39
+ // Validate every image and all codes before uploading any of them.
40
+ for (let index = 0; index < images.length; index++) {
41
+ const metadata = await sharp(images[index], { limitInputPixels: 16_000_000 }).metadata();
42
+ if (!['png', 'jpeg', 'webp'].includes(metadata.format ?? ''))
43
+ throw new PaymentError('QR_INVALID', 'Payment images must be PNG, JPEG or WebP');
44
+ const codes = qrCodes.filter(q => q.attachment_index === index);
45
+ if (codes.length) {
46
+ const { data, info } = await sharp(images[index], { limitInputPixels: 16_000_000 }).rotate().ensureAlpha().raw().toBuffer({ resolveWithObject: true });
47
+ const decoded = jsQR(new Uint8ClampedArray(data), info.width, info.height);
48
+ if (!decoded?.data || decoded.data.length > 8192)
49
+ throw new PaymentError('QR_INVALID', 'Payment QR could not be decoded; crop a clear code including its border');
50
+ for (const qr of codes) {
51
+ if (qr.raw_payload !== undefined && qr.raw_payload !== decoded.data)
52
+ throw new PaymentError('QR_INVALID', 'QR image and raw payload do not match');
53
+ qr.raw_payload = decoded.data;
54
+ }
55
+ }
56
+ }
57
+ const attachments = [];
58
+ for (let i = 0; i < images.length; i++)
59
+ attachments.push(await channel.uploadPaymentImage(images[i], path.basename(media.attachments[i].file_path)));
60
+ return { attachments, qr_codes: qrCodes };
61
+ }
62
+ export function registerPaymentRuntime(deps) {
63
+ const owned = new Map();
64
+ const channelFor = (aid) => {
65
+ const instance = deps.channelInstances.find(item => item.channelType === 'aun'
66
+ && item.channel.getAid?.() === aid);
67
+ if (!instance)
68
+ throw new PaymentError('CHANNEL_UNAVAILABLE', 'Agent AUN channel is unavailable');
69
+ return instance.channel;
70
+ };
71
+ const get = (aid) => {
72
+ const existing = owned.get(aid);
73
+ if (existing)
74
+ return existing;
75
+ const store = paymentStore(aid);
76
+ const service = new PaymentService({ store, currentBinding: () => currentContactBinding(aid),
77
+ prepareMedia: async () => { throw new PaymentError('NOT_AUTHORIZED', 'Media upload requires a delegated task'); },
78
+ send: async (record, delivery) => {
79
+ const result = await channelFor(aid).sendContentPayload(record.binding.owner_aid, delivery.payload, {
80
+ contentKind: delivery.kind === 'card' ? 'card' : 'custom',
81
+ dedupeKey: `payment:${record.payment.request_id}:${delivery.id}`,
82
+ context: { delivery: { chatType: 'private' }, ...(record.threadId ? { threadId: record.threadId } : {}),
83
+ metadata: { encrypted: record.encrypted, source: 'msg' }, sessionId: record.sessionId },
84
+ postSend: { type: 'register_payment_delivery', requestId: record.payment.request_id, deliveryId: delivery.id },
85
+ logText: delivery.payload.text ?? '[payment]',
86
+ });
87
+ if (result.status === 'permanent')
88
+ throw new PaymentError(result.code ?? 'DELIVERY_FAILED', result.error ?? 'Payment delivery failed');
89
+ return { messageId: result.messageId, queued: !!result.outboxId || result.queued };
90
+ },
91
+ enqueue: async (record, job) => {
92
+ const session = await deps.sessionManager.getSessionById(record.sessionId);
93
+ if (!session || session.deletedAt || session.selfAID !== aid || session.channelType !== 'aun'
94
+ || session.chatType !== 'private' || session.channelId !== record.binding.owner_aid
95
+ || sessionTopicThreadId(session) !== record.threadId
96
+ || !sameContactBinding(record.binding, currentContactBinding(aid))) {
97
+ throw new PaymentError('NOT_AUTHORIZED', 'Original payment task is no longer available');
98
+ }
99
+ const content = `[付款任务事件]\n请求:${record.payment.request_id}\n事件:${job.id}\n操作:${job.kind}\n`
100
+ + `请先加载 ec-pay 技能,再执行 ec pay status ${record.payment.request_id} 获取最新状态。`
101
+ + (job.kind === 'continue' ? '\n订单已核验付款。核对原任务,检查此前完成情况后继续后续步骤,避免重复购买或开通;完成后用 ec pay complete 确认事件。'
102
+ : '\n先核验原网站订单;切换或刷新必须确认原订单未付,不得再次下单。通过 ec pay update 提交事件结果。');
103
+ await deps.messageQueue.enqueuePersisted(session.id, {
104
+ channel: session.channel, channelType: 'aun', channelId: record.binding.owner_aid,
105
+ selfAID: aid, baseagent: session.baseagent, chatType: 'private', peerId: record.binding.owner_aid,
106
+ content, messageId: job.id, timestamp: job.createdAt, source: 'self-address',
107
+ encrypted: record.encrypted, threadId: record.threadId,
108
+ selfAddressedMeta: { noopSentinel: '__PAYMENT_TASK_NOOP__' },
109
+ replyContext: { delivery: { chatType: 'private' }, ...(record.threadId ? { threadId: record.threadId } : {}),
110
+ metadata: { encrypted: record.encrypted } },
111
+ }, session.projectPath, { interruptible: false, role: 'owner', agentName: aid,
112
+ sessionKeyField: session.sessionKey, selfAID: aid });
113
+ },
114
+ });
115
+ owned.set(aid, service);
116
+ services.set(aid, service);
117
+ return service;
118
+ };
119
+ deps.ipcServer.setPaymentExecutor(async (params) => {
120
+ try {
121
+ const command = parsePaymentCommand(params.argv);
122
+ const authorized = await deps.authorize(params, `ec.pay.${command.operation}`);
123
+ if (!authorized.ok)
124
+ return authorized;
125
+ const grant = authorized.grant;
126
+ const session = await deps.sessionManager.getSessionById(params.sessionId);
127
+ const binding = currentContactBinding(authorized.aid);
128
+ if (!session || !binding || grant.systemSession || grant.actorId !== binding.owner_aid
129
+ || grant.channelType !== 'aun' || grant.chatType !== 'private' || grant.peerKey !== `aun#${binding.owner_aid}`
130
+ || session.selfAID !== authorized.aid || session.channelId !== binding.owner_aid
131
+ || session.channelType !== 'aun' || session.chatType !== 'private') {
132
+ throw new PaymentError('NOT_AUTHORIZED', 'Payment commands require the current Owner AUN private conversation');
133
+ }
134
+ const origin = { binding, sessionId: session.id, threadId: sessionTopicThreadId(session),
135
+ encrypted: deps.sessionManager.getSessionEncrypt(session.id) === true };
136
+ const scope = { selfAid: authorized.aid, projectPath: session.projectPath,
137
+ sessionRuntimeDir: authorized.sessionRuntimeDir, cwd: session.projectPath };
138
+ const prepare = (media) => preparePaymentMedia(media, scope, channelFor(authorized.aid));
139
+ const service = get(authorized.aid);
140
+ const readSpec = () => {
141
+ const bytes = readManagedLocalFile(command.file, scope, 'attachment');
142
+ if (bytes.length > 64 * 1024)
143
+ throw new PaymentError('INVALID_ARGUMENT', 'Payment specification exceeds 64 KiB');
144
+ return JSON.parse(bytes.toString('utf8'));
145
+ };
146
+ if (command.operation === 'request')
147
+ return await service.request(origin, readSpec(), crypto.createHash('sha256').update(`${session.id}:${grant.messageId}:${command.file}`).digest('hex'), prepare);
148
+ if (command.operation === 'update')
149
+ return await service.update(origin, command.requestId, readSpec(), prepare);
150
+ if (command.operation === 'complete')
151
+ return await service.complete(origin, command.requestId, command.eventId);
152
+ return await service.command(origin, command.requestId, command.operation);
153
+ }
154
+ catch (error) {
155
+ return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error instanceof Error ? error.message : String(error) };
156
+ }
157
+ });
158
+ let reconciling = false;
159
+ const reconcile = async () => {
160
+ if (reconciling)
161
+ return;
162
+ reconciling = true;
163
+ try {
164
+ for (const item of deps.channelInstances) {
165
+ if (item.channelType !== 'aun')
166
+ continue;
167
+ const aid = item.channel.getAid?.();
168
+ if (aid) {
169
+ try {
170
+ await get(aid).reconcile();
171
+ }
172
+ catch (error) {
173
+ logger.warn(`[Pay] Reconcile pending: ${String(error)}`);
174
+ }
175
+ }
176
+ }
177
+ }
178
+ finally {
179
+ reconciling = false;
180
+ }
181
+ };
182
+ void reconcile();
183
+ const timer = setInterval(() => { void reconcile(); }, 15_000);
184
+ timer.unref();
185
+ return () => { clearInterval(timer); for (const [aid, service] of owned)
186
+ if (services.get(aid) === service)
187
+ services.delete(aid); };
188
+ }