@bolloon/bolloon-agent 0.4.27 → 0.4.29
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/bin/bolloon.cjs +18 -148
- package/bin/bolloon.cmd +6 -3
- package/dist/agents/execution-supervisor.js +21 -0
- package/dist/agents/pi-sdk-tools.js +3 -1
- package/dist/agents/pi-sdk.js +4 -1
- package/dist/agents/task/local-seller.js +149 -0
- package/dist/agents/task/report-card.js +146 -0
- package/dist/agents/task/resource-advisor.js +182 -0
- package/dist/agents/task/task-budget.js +103 -0
- package/dist/agents/task/task-runner.js +618 -0
- package/dist/agents/x402/goal-run-bridge.js +10 -6
- package/dist/agents/x402/resource-contract.js +12 -1
- package/dist/cli/update-commands.js +349 -0
- package/dist/cli-entry.js +133 -53
- package/dist/electron-build/agents/agent-gateway.js +169 -0
- package/dist/electron-build/agents/agent-gateway.js.map +1 -0
- package/dist/electron-build/agents/agent-identity-store.js +212 -0
- package/dist/electron-build/agents/agent-identity-store.js.map +1 -0
- package/dist/electron-build/agents/agent-identity.js +196 -0
- package/dist/electron-build/agents/agent-identity.js.map +1 -0
- package/dist/electron-build/agents/agent-manifest-protocol.js +151 -0
- package/dist/electron-build/agents/agent-manifest-protocol.js.map +1 -0
- package/dist/electron-build/agents/agent-registry.js +217 -0
- package/dist/electron-build/agents/agent-registry.js.map +1 -0
- package/dist/electron-build/agents/agent-reputation.js +60 -0
- package/dist/electron-build/agents/agent-reputation.js.map +1 -0
- package/dist/electron-build/agents/agent-service-client.js +186 -0
- package/dist/electron-build/agents/agent-service-client.js.map +1 -0
- package/dist/electron-build/agents/browser-cdp.js +765 -0
- package/dist/electron-build/agents/browser-cdp.js.map +1 -0
- package/dist/electron-build/agents/computer-use.js +341 -0
- package/dist/electron-build/agents/computer-use.js.map +1 -0
- package/dist/electron-build/agents/constraint-layer.js +210 -0
- package/dist/electron-build/agents/constraint-layer.js.map +1 -0
- package/dist/electron-build/agents/decision-store.js +292 -0
- package/dist/electron-build/agents/decision-store.js.map +1 -0
- package/dist/electron-build/agents/deny-pipeline.js +125 -0
- package/dist/electron-build/agents/deny-pipeline.js.map +1 -0
- package/dist/electron-build/agents/economic-policy.js +172 -0
- package/dist/electron-build/agents/economic-policy.js.map +1 -0
- package/dist/electron-build/agents/error-classifier.js +125 -0
- package/dist/electron-build/agents/error-classifier.js.map +1 -0
- package/dist/electron-build/agents/execution-supervisor.js +539 -0
- package/dist/electron-build/agents/execution-supervisor.js.map +1 -0
- package/dist/electron-build/agents/external-events.js +171 -0
- package/dist/electron-build/agents/external-events.js.map +1 -0
- package/dist/electron-build/agents/gateway-join.js +315 -0
- package/dist/electron-build/agents/gateway-join.js.map +1 -0
- package/dist/electron-build/agents/gateway-network.js +505 -0
- package/dist/electron-build/agents/gateway-network.js.map +1 -0
- package/dist/electron-build/agents/goal-criteria.js +133 -0
- package/dist/electron-build/agents/goal-criteria.js.map +1 -0
- package/dist/electron-build/agents/goal-resume.js +364 -0
- package/dist/electron-build/agents/goal-resume.js.map +1 -0
- package/dist/electron-build/agents/goal-store.js +587 -0
- package/dist/electron-build/agents/goal-store.js.map +1 -0
- package/dist/electron-build/agents/intent-classifier.js +104 -0
- package/dist/electron-build/agents/intent-classifier.js.map +1 -0
- package/dist/electron-build/agents/iroh-secret.js +70 -0
- package/dist/electron-build/agents/iroh-secret.js.map +1 -0
- package/dist/electron-build/agents/loop-review.js +101 -0
- package/dist/electron-build/agents/loop-review.js.map +1 -0
- package/dist/electron-build/agents/memory-recall.js +154 -0
- package/dist/electron-build/agents/memory-recall.js.map +1 -0
- package/dist/electron-build/agents/p2p-document-tools.js +328 -0
- package/dist/electron-build/agents/p2p-document-tools.js.map +1 -0
- package/dist/electron-build/agents/parse-tool-call.js +564 -0
- package/dist/electron-build/agents/parse-tool-call.js.map +1 -0
- package/dist/electron-build/agents/patch-tool.js +205 -0
- package/dist/electron-build/agents/patch-tool.js.map +1 -0
- package/dist/electron-build/agents/payment-approval.js +183 -0
- package/dist/electron-build/agents/payment-approval.js.map +1 -0
- package/dist/electron-build/agents/payment-gate.js +139 -0
- package/dist/electron-build/agents/payment-gate.js.map +1 -0
- package/dist/electron-build/agents/permission-mode.js +124 -0
- package/dist/electron-build/agents/permission-mode.js.map +1 -0
- package/dist/electron-build/agents/pi-harness.js +268 -0
- package/dist/electron-build/agents/pi-harness.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-session-factory.js +117 -0
- package/dist/electron-build/agents/pi-sdk-session-factory.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-session-manager.js +335 -0
- package/dist/electron-build/agents/pi-sdk-session-manager.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-tools.js +4042 -0
- package/dist/electron-build/agents/pi-sdk-tools.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-types.js +17 -0
- package/dist/electron-build/agents/pi-sdk-types.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk.js +3325 -0
- package/dist/electron-build/agents/pi-sdk.js.map +1 -0
- package/dist/electron-build/agents/plan-store.js +212 -0
- package/dist/electron-build/agents/plan-store.js.map +1 -0
- package/dist/electron-build/agents/pre-tool-validator.js +200 -0
- package/dist/electron-build/agents/pre-tool-validator.js.map +1 -0
- package/dist/electron-build/agents/process-runner.js +148 -0
- package/dist/electron-build/agents/process-runner.js.map +1 -0
- package/dist/electron-build/agents/react-loop.js +131 -0
- package/dist/electron-build/agents/react-loop.js.map +1 -0
- package/dist/electron-build/agents/resource-store.js +180 -0
- package/dist/electron-build/agents/resource-store.js.map +1 -0
- package/dist/electron-build/agents/resource-token.js +118 -0
- package/dist/electron-build/agents/resource-token.js.map +1 -0
- package/dist/electron-build/agents/resource-wallet.js +84 -0
- package/dist/electron-build/agents/resource-wallet.js.map +1 -0
- package/dist/electron-build/agents/run-store.js +854 -0
- package/dist/electron-build/agents/run-store.js.map +1 -0
- package/dist/electron-build/agents/runner-resolver.js +267 -0
- package/dist/electron-build/agents/runner-resolver.js.map +1 -0
- package/dist/electron-build/agents/session-store.js +294 -0
- package/dist/electron-build/agents/session-store.js.map +1 -0
- package/dist/electron-build/agents/shell-guard.js +465 -0
- package/dist/electron-build/agents/shell-guard.js.map +1 -0
- package/dist/electron-build/agents/shell-tool.js +102 -0
- package/dist/electron-build/agents/shell-tool.js.map +1 -0
- package/dist/electron-build/agents/skill-loader.js +216 -0
- package/dist/electron-build/agents/skill-loader.js.map +1 -0
- package/dist/electron-build/agents/skill-readiness.js +174 -0
- package/dist/electron-build/agents/skill-readiness.js.map +1 -0
- package/dist/electron-build/agents/skill-share.js +394 -0
- package/dist/electron-build/agents/skill-share.js.map +1 -0
- package/dist/electron-build/agents/skill-supervisor-link.js +75 -0
- package/dist/electron-build/agents/skill-supervisor-link.js.map +1 -0
- package/dist/electron-build/agents/skill-writer.js +347 -0
- package/dist/electron-build/agents/skill-writer.js.map +1 -0
- package/dist/electron-build/agents/skills-manager.js +763 -0
- package/dist/electron-build/agents/skills-manager.js.map +1 -0
- package/dist/electron-build/agents/supervisor-host.js +294 -0
- package/dist/electron-build/agents/supervisor-host.js.map +1 -0
- package/dist/electron-build/agents/task/local-seller.js +188 -0
- package/dist/electron-build/agents/task/local-seller.js.map +1 -0
- package/dist/electron-build/agents/task/report-card.js +152 -0
- package/dist/electron-build/agents/task/report-card.js.map +1 -0
- package/dist/electron-build/agents/task/resource-advisor.js +222 -0
- package/dist/electron-build/agents/task/resource-advisor.js.map +1 -0
- package/dist/electron-build/agents/task/task-budget.js +111 -0
- package/dist/electron-build/agents/task/task-budget.js.map +1 -0
- package/dist/electron-build/agents/task/task-runner.js +670 -0
- package/dist/electron-build/agents/task/task-runner.js.map +1 -0
- package/dist/electron-build/agents/task-state.js +266 -0
- package/dist/electron-build/agents/task-state.js.map +1 -0
- package/dist/electron-build/agents/tool-registry.js +141 -0
- package/dist/electron-build/agents/tool-registry.js.map +1 -0
- package/dist/electron-build/agents/treasury-bridge.js +165 -0
- package/dist/electron-build/agents/treasury-bridge.js.map +1 -0
- package/dist/electron-build/agents/user-questions.js +223 -0
- package/dist/electron-build/agents/user-questions.js.map +1 -0
- package/dist/electron-build/agents/verify-recipe.js +90 -0
- package/dist/electron-build/agents/verify-recipe.js.map +1 -0
- package/dist/electron-build/agents/workflow-engine.js +222 -0
- package/dist/electron-build/agents/workflow-engine.js.map +1 -0
- package/dist/electron-build/agents/workflow-pivot-loop.js +988 -0
- package/dist/electron-build/agents/workflow-pivot-loop.js.map +1 -0
- package/dist/electron-build/agents/write-staging.js +133 -0
- package/dist/electron-build/agents/write-staging.js.map +1 -0
- package/dist/electron-build/agents/x402/goal-run-bridge.js +115 -0
- package/dist/electron-build/agents/x402/goal-run-bridge.js.map +1 -0
- package/dist/electron-build/agents/x402/milestone-settlement.js +163 -0
- package/dist/electron-build/agents/x402/milestone-settlement.js.map +1 -0
- package/dist/electron-build/agents/x402/paid-info-protocol.js +274 -0
- package/dist/electron-build/agents/x402/paid-info-protocol.js.map +1 -0
- package/dist/electron-build/agents/x402/paid-info-store.js +409 -0
- package/dist/electron-build/agents/x402/paid-info-store.js.map +1 -0
- package/dist/electron-build/agents/x402/paid-info-tools.js +346 -0
- package/dist/electron-build/agents/x402/paid-info-tools.js.map +1 -0
- package/dist/electron-build/agents/x402/payment-recovery.js +330 -0
- package/dist/electron-build/agents/x402/payment-recovery.js.map +1 -0
- package/dist/electron-build/agents/x402/resource-contract.js +533 -0
- package/dist/electron-build/agents/x402/resource-contract.js.map +1 -0
- package/dist/electron-build/agents/x402/settlement-state.js +432 -0
- package/dist/electron-build/agents/x402/settlement-state.js.map +1 -0
- package/dist/electron-build/agents/x402/trade.js +294 -0
- package/dist/electron-build/agents/x402/trade.js.map +1 -0
- package/dist/electron-build/agents/x402/transaction-protocol.js +109 -0
- package/dist/electron-build/agents/x402/transaction-protocol.js.map +1 -0
- package/dist/electron-build/agents/x402/transaction-store.js +404 -0
- package/dist/electron-build/agents/x402/transaction-store.js.map +1 -0
- package/dist/electron-build/agents/x402/x402Pay.js +377 -0
- package/dist/electron-build/agents/x402/x402Pay.js.map +1 -0
- package/dist/electron-build/bollharness-integration/context-router-judgment.js +269 -0
- package/dist/electron-build/bollharness-integration/context-router-judgment.js.map +1 -0
- package/dist/electron-build/bollharness-integration/context-router.js +584 -0
- package/dist/electron-build/bollharness-integration/context-router.js.map +1 -0
- package/dist/electron-build/bollharness-integration/gate-state-machine.js +362 -0
- package/dist/electron-build/bollharness-integration/gate-state-machine.js.map +1 -0
- package/dist/electron-build/bollharness-integration/gate-transition-hooks.js +136 -0
- package/dist/electron-build/bollharness-integration/gate-transition-hooks.js.map +1 -0
- package/dist/electron-build/bollharness-integration/guard-checker.js +400 -0
- package/dist/electron-build/bollharness-integration/guard-checker.js.map +1 -0
- package/dist/electron-build/bollharness-integration/index.js +123 -0
- package/dist/electron-build/bollharness-integration/index.js.map +1 -0
- package/dist/electron-build/bollharness-integration/integration.js +531 -0
- package/dist/electron-build/bollharness-integration/integration.js.map +1 -0
- package/dist/electron-build/bollharness-integration/skill-adapter.js +608 -0
- package/dist/electron-build/bollharness-integration/skill-adapter.js.map +1 -0
- package/dist/electron-build/bootstrap/bootstrap.js +173 -0
- package/dist/electron-build/bootstrap/bootstrap.js.map +1 -0
- package/dist/electron-build/bootstrap/context-collector.js +358 -0
- package/dist/electron-build/bootstrap/context-collector.js.map +1 -0
- package/dist/electron-build/bootstrap/context-hierarchy.js +262 -0
- package/dist/electron-build/bootstrap/context-hierarchy.js.map +1 -0
- package/dist/electron-build/bootstrap/context-manager.js +211 -0
- package/dist/electron-build/bootstrap/context-manager.js.map +1 -0
- package/dist/electron-build/bootstrap/context-os.js +277 -0
- package/dist/electron-build/bootstrap/context-os.js.map +1 -0
- package/dist/electron-build/bootstrap/event-log.js +203 -0
- package/dist/electron-build/bootstrap/event-log.js.map +1 -0
- package/dist/electron-build/bootstrap/exhaust-scrubber.js +277 -0
- package/dist/electron-build/bootstrap/exhaust-scrubber.js.map +1 -0
- package/dist/electron-build/bootstrap/lifecycle-hooks.js +282 -0
- package/dist/electron-build/bootstrap/lifecycle-hooks.js.map +1 -0
- package/dist/electron-build/bootstrap/memory-compressor.js +377 -0
- package/dist/electron-build/bootstrap/memory-compressor.js.map +1 -0
- package/dist/electron-build/bootstrap/persona-loader.js +219 -0
- package/dist/electron-build/bootstrap/persona-loader.js.map +1 -0
- package/dist/electron-build/bootstrap/project-context.js +162 -0
- package/dist/electron-build/bootstrap/project-context.js.map +1 -0
- package/dist/electron-build/bootstrap/project-state.js +205 -0
- package/dist/electron-build/bootstrap/project-state.js.map +1 -0
- package/dist/electron-build/bootstrap/session-window.js +162 -0
- package/dist/electron-build/bootstrap/session-window.js.map +1 -0
- package/dist/electron-build/bootstrap/vector-index.js +291 -0
- package/dist/electron-build/bootstrap/vector-index.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +22 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/clobShared.js +86 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/clobShared.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +37 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/createOrder.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +20 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getMarket.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +29 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getOrders.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +28 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/SafeSDK/deploySafe.js +10 -0
- package/dist/electron-build/constraint-runtime/src/tools/SafeSDK/deploySafe.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/autoPay.js +68 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/autoPay.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/createWallet.js +14 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/createWallet.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/getBalance.js +17 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/getBalance.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/importWallet.js +59 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/importWallet.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/sendTransaction.js +29 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/sendTransaction.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/signMessage.js +14 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/signMessage.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/transferToken.js +29 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/transferToken.js.map +1 -0
- package/dist/electron-build/constraints/index.js +11 -0
- package/dist/electron-build/constraints/index.js.map +1 -0
- package/dist/electron-build/context-compaction/auto-compact.js +182 -0
- package/dist/electron-build/context-compaction/auto-compact.js.map +1 -0
- package/dist/electron-build/context-compaction/budget-gate.js +32 -0
- package/dist/electron-build/context-compaction/budget-gate.js.map +1 -0
- package/dist/electron-build/context-compaction/budget-reduce.js +39 -0
- package/dist/electron-build/context-compaction/budget-reduce.js.map +1 -0
- package/dist/electron-build/context-compaction/context-collapse.js +71 -0
- package/dist/electron-build/context-compaction/context-collapse.js.map +1 -0
- package/dist/electron-build/context-compaction/index.js +38 -0
- package/dist/electron-build/context-compaction/index.js.map +1 -0
- package/dist/electron-build/context-compaction/microcompact.js +55 -0
- package/dist/electron-build/context-compaction/microcompact.js.map +1 -0
- package/dist/electron-build/context-compaction/pipeline.js +128 -0
- package/dist/electron-build/context-compaction/pipeline.js.map +1 -0
- package/dist/electron-build/context-compaction/snip.js +50 -0
- package/dist/electron-build/context-compaction/snip.js.map +1 -0
- package/dist/electron-build/context-compaction/token-estimator.js +40 -0
- package/dist/electron-build/context-compaction/token-estimator.js.map +1 -0
- package/dist/electron-build/context-compaction/types.js +21 -0
- package/dist/electron-build/context-compaction/types.js.map +1 -0
- package/dist/electron-build/cron/tick-lock.js +247 -0
- package/dist/electron-build/cron/tick-lock.js.map +1 -0
- package/dist/electron-build/documents/reader.js +131 -0
- package/dist/electron-build/documents/reader.js.map +1 -0
- package/dist/electron-build/documents/store.js +220 -0
- package/dist/electron-build/documents/store.js.map +1 -0
- package/dist/electron-build/external-engines/delegate-handle.js +76 -0
- package/dist/electron-build/external-engines/delegate-handle.js.map +1 -0
- package/dist/electron-build/external-engines/delegate.js +225 -0
- package/dist/electron-build/external-engines/delegate.js.map +1 -0
- package/dist/electron-build/external-engines/discovery.js +448 -0
- package/dist/electron-build/external-engines/discovery.js.map +1 -0
- package/dist/electron-build/external-engines/types.js +13 -0
- package/dist/electron-build/external-engines/types.js.map +1 -0
- package/dist/electron-build/hooks/hooks-engine.js +367 -0
- package/dist/electron-build/hooks/hooks-engine.js.map +1 -0
- package/dist/electron-build/judgeness/reflect.js +100 -0
- package/dist/electron-build/judgeness/reflect.js.map +1 -0
- package/dist/electron-build/judgeness/store.js +536 -0
- package/dist/electron-build/judgeness/store.js.map +1 -0
- package/dist/electron-build/judgeness/types.js +21 -0
- package/dist/electron-build/judgeness/types.js.map +1 -0
- package/dist/electron-build/llm/config-store.js +551 -0
- package/dist/electron-build/llm/config-store.js.map +1 -0
- package/dist/electron-build/llm/error-lessons.js +76 -0
- package/dist/electron-build/llm/error-lessons.js.map +1 -0
- package/dist/electron-build/llm/pi-ai.js +830 -0
- package/dist/electron-build/llm/pi-ai.js.map +1 -0
- package/dist/electron-build/llm/system-prompt/registry.js +318 -0
- package/dist/electron-build/llm/system-prompt/registry.js.map +1 -0
- package/dist/electron-build/llm/system-prompt/strip-hibsml.js +55 -0
- package/dist/electron-build/llm/system-prompt/strip-hibsml.js.map +1 -0
- package/dist/electron-build/locales/en.js +32 -0
- package/dist/electron-build/locales/en.js.map +1 -0
- package/dist/electron-build/locales/zh.js +30 -0
- package/dist/electron-build/locales/zh.js.map +1 -0
- package/dist/electron-build/lsp/lsp-manager.js +327 -0
- package/dist/electron-build/lsp/lsp-manager.js.map +1 -0
- package/dist/electron-build/lsp/lsp-tools.js +226 -0
- package/dist/electron-build/lsp/lsp-tools.js.map +1 -0
- package/dist/electron-build/migration/external-agent-migrator.js +451 -0
- package/dist/electron-build/migration/external-agent-migrator.js.map +1 -0
- package/dist/electron-build/network/agent-network.js +775 -0
- package/dist/electron-build/network/agent-network.js.map +1 -0
- package/dist/electron-build/network/goal-event-bridge.js +62 -0
- package/dist/electron-build/network/goal-event-bridge.js.map +1 -0
- package/dist/electron-build/network/iroh-integration.js +117 -0
- package/dist/electron-build/network/iroh-integration.js.map +1 -0
- package/dist/electron-build/network/iroh-transport.js +550 -0
- package/dist/electron-build/network/iroh-transport.js.map +1 -0
- package/dist/electron-build/network/p2p.js +1103 -0
- package/dist/electron-build/network/p2p.js.map +1 -0
- package/dist/electron-build/network/storage/adapters/json-adapter.js +416 -0
- package/dist/electron-build/network/storage/adapters/json-adapter.js.map +1 -0
- package/dist/electron-build/network/storage/types.js +18 -0
- package/dist/electron-build/network/storage/types.js.map +1 -0
- package/dist/electron-build/orbitdb/agent-tools.js +402 -0
- package/dist/electron-build/orbitdb/agent-tools.js.map +1 -0
- package/dist/electron-build/orbitdb/cid-database.js +284 -0
- package/dist/electron-build/orbitdb/cid-database.js.map +1 -0
- package/dist/electron-build/orbitdb/context-store.js +99 -0
- package/dist/electron-build/orbitdb/context-store.js.map +1 -0
- package/dist/electron-build/orbitdb/ipfs-node.js +120 -0
- package/dist/electron-build/orbitdb/ipfs-node.js.map +1 -0
- package/dist/electron-build/orbitdb/kanban-store.js +299 -0
- package/dist/electron-build/orbitdb/kanban-store.js.map +1 -0
- package/dist/electron-build/orbitdb/task-store.js +155 -0
- package/dist/electron-build/orbitdb/task-store.js.map +1 -0
- package/dist/electron-build/orbitdb/trajectory-store.js +194 -0
- package/dist/electron-build/orbitdb/trajectory-store.js.map +1 -0
- package/dist/electron-build/orbitdb/ui-cid.js +77 -0
- package/dist/electron-build/orbitdb/ui-cid.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-a2ui/index.js +89 -0
- package/dist/electron-build/pi-ecosystem-a2ui/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-goals/index.js +512 -0
- package/dist/electron-build/pi-ecosystem-goals/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/adaptive-scan.js +325 -0
- package/dist/electron-build/pi-ecosystem-judgment/adaptive-scan.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/causal-judge.js +492 -0
- package/dist/electron-build/pi-ecosystem-judgment/causal-judge.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/cleanup.js +167 -0
- package/dist/electron-build/pi-ecosystem-judgment/cleanup.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/decision.js +321 -0
- package/dist/electron-build/pi-ecosystem-judgment/decision.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/detect-hook.js +175 -0
- package/dist/electron-build/pi-ecosystem-judgment/detect-hook.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/distill-prompt.js +232 -0
- package/dist/electron-build/pi-ecosystem-judgment/distill-prompt.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/distillation.js +304 -0
- package/dist/electron-build/pi-ecosystem-judgment/distillation.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/evolve-judgment.js +176 -0
- package/dist/electron-build/pi-ecosystem-judgment/evolve-judgment.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-pipeline.js +65 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-pipeline.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-store.js +808 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-store.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/index.js +508 -0
- package/dist/electron-build/pi-ecosystem-judgment/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/injection-gate.js +334 -0
- package/dist/electron-build/pi-ecosystem-judgment/injection-gate.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/monitor-gate.js +228 -0
- package/dist/electron-build/pi-ecosystem-judgment/monitor-gate.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/value-injection.js +598 -0
- package/dist/electron-build/pi-ecosystem-judgment/value-injection.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-mcp/index.js +643 -0
- package/dist/electron-build/pi-ecosystem-mcp/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-mcp/ui-tools.js +116 -0
- package/dist/electron-build/pi-ecosystem-mcp/ui-tools.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-subagents/index.js +352 -0
- package/dist/electron-build/pi-ecosystem-subagents/index.js.map +1 -0
- package/dist/electron-build/security/builtin-guards.js +133 -0
- package/dist/electron-build/security/builtin-guards.js.map +1 -0
- package/dist/electron-build/security/context-router-tool.js +111 -0
- package/dist/electron-build/security/context-router-tool.js.map +1 -0
- package/dist/electron-build/security/input-scanner.js +263 -0
- package/dist/electron-build/security/input-scanner.js.map +1 -0
- package/dist/electron-build/security/react-harness.js +148 -0
- package/dist/electron-build/security/react-harness.js.map +1 -0
- package/dist/electron-build/security/tool-gate.js +287 -0
- package/dist/electron-build/security/tool-gate.js.map +1 -0
- package/dist/electron-build/setup/setup-store.js +648 -0
- package/dist/electron-build/setup/setup-store.js.map +1 -0
- package/dist/electron-build/social/channels/ChannelManager.js +444 -0
- package/dist/electron-build/social/channels/ChannelManager.js.map +1 -0
- package/dist/electron-build/social/channels/DiapChannelBridge.js +451 -0
- package/dist/electron-build/social/channels/DiapChannelBridge.js.map +1 -0
- package/dist/electron-build/social/channels/InterestMatcher.js +135 -0
- package/dist/electron-build/social/channels/InterestMatcher.js.map +1 -0
- package/dist/electron-build/social/channels/types.js +21 -0
- package/dist/electron-build/social/channels/types.js.map +1 -0
- package/dist/electron-build/social/global-shared-context.js +368 -0
- package/dist/electron-build/social/global-shared-context.js.map +1 -0
- package/dist/electron-build/social/heartbeat.js +882 -0
- package/dist/electron-build/social/heartbeat.js.map +1 -0
- package/dist/electron-build/storage/did-catalog-bridge.js +314 -0
- package/dist/electron-build/storage/did-catalog-bridge.js.map +1 -0
- package/dist/electron-build/storage/did-catalog.js +272 -0
- package/dist/electron-build/storage/did-catalog.js.map +1 -0
- package/dist/electron-build/utils/auto-update.js +140 -558
- package/dist/electron-build/utils/auto-update.js.map +1 -1
- package/dist/electron-build/utils/module-context.js +98 -0
- package/dist/electron-build/utils/module-context.js.map +1 -0
- package/dist/electron-build/utils/runtime-bootstrap.js +745 -0
- package/dist/electron-build/utils/runtime-bootstrap.js.map +1 -0
- package/dist/electron-build/utils/update-manager.js +770 -0
- package/dist/electron-build/utils/update-manager.js.map +1 -0
- package/dist/electron-build/utils/update-state.js +406 -0
- package/dist/electron-build/utils/update-state.js.map +1 -0
- package/dist/electron-build/utils/version-info.js +562 -0
- package/dist/electron-build/utils/version-info.js.map +1 -0
- package/dist/electron-build/web/i18n.js +146 -0
- package/dist/electron-build/web/i18n.js.map +1 -0
- package/dist/electron-build/web/routes-x402-info.js +232 -0
- package/dist/electron-build/web/routes-x402-info.js.map +1 -0
- package/dist/electron-build/web/server-storage.js +390 -0
- package/dist/electron-build/web/server-storage.js.map +1 -0
- package/dist/electron-build/web/server-types.js +52 -0
- package/dist/electron-build/web/server-types.js.map +1 -0
- package/dist/electron-build/web/task-deps.js +41 -0
- package/dist/electron-build/web/task-deps.js.map +1 -0
- package/dist/index.js +28 -27
- package/dist/llm/system-prompt/registry.js +6 -3
- package/dist/utils/auto-update.js +138 -525
- package/dist/utils/module-context.js +59 -0
- package/dist/utils/runtime-bootstrap.js +682 -0
- package/dist/utils/update-cli.js +82 -0
- package/dist/utils/update-health.js +401 -0
- package/dist/utils/update-manager.js +716 -0
- package/dist/utils/update-state.js +353 -0
- package/dist/utils/version-info.js +510 -0
- package/package.json +1 -1
- package/scripts/build-cli.js +32 -151
- package/scripts/postinstall.js +153 -76
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SocialHeartbeat = exports.DiscoveredAgentsManager = void 0;
|
|
37
|
+
exports.createSocialHeartbeat = createSocialHeartbeat;
|
|
38
|
+
exports.getSocialHeartbeat = getSocialHeartbeat;
|
|
39
|
+
exports.generatePersona = generatePersona;
|
|
40
|
+
exports.generateDefaultPersona = generateDefaultPersona;
|
|
41
|
+
const fs = __importStar(require("fs/promises"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
// 2026-06-11: 蚁群模块 (PheromoneEngine / AdaptiveHeartbeat) 已被用户删除, 仅保留最小 stub
|
|
45
|
+
// 让 heartbeat 内的 antColony 代码块继续类型合法, 但运行时所有方法都是 no-op
|
|
46
|
+
class PheromoneEngine {
|
|
47
|
+
async initialize() { }
|
|
48
|
+
shutdown() { }
|
|
49
|
+
getStats() { return { totalTrails: 0, avgStrength: 0, capabilityCount: 0, density: 0 }; }
|
|
50
|
+
async deposit(_type, _from, _to, _strength, _meta) { }
|
|
51
|
+
}
|
|
52
|
+
class AdaptiveHeartbeat {
|
|
53
|
+
constructor(_opts) { }
|
|
54
|
+
shutdown() { }
|
|
55
|
+
decide() { return { interval: 0, priorityLevel: 'normal' }; }
|
|
56
|
+
setPheromoneDensity(_d) { }
|
|
57
|
+
recordActivity(_t) { }
|
|
58
|
+
}
|
|
59
|
+
var PheromoneType;
|
|
60
|
+
(function (PheromoneType) {
|
|
61
|
+
PheromoneType["DISCOVERY"] = "discovery";
|
|
62
|
+
})(PheromoneType || (PheromoneType = {}));
|
|
63
|
+
const ChannelManager_js_1 = require("./channels/ChannelManager.js");
|
|
64
|
+
const types_js_1 = require("./channels/types.js");
|
|
65
|
+
const DiapChannelBridge_js_1 = require("./channels/DiapChannelBridge.js");
|
|
66
|
+
const InterestMatcher_js_1 = require("./channels/InterestMatcher.js");
|
|
67
|
+
const SHARED_SESSION_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'sessions');
|
|
68
|
+
const PERSONA_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'persona.json');
|
|
69
|
+
const DISCOVERED_AGENTS_PATH = path.join(SHARED_SESSION_PATH, 'discovered-agents.json');
|
|
70
|
+
class LocalSessionManager {
|
|
71
|
+
channels = new Map();
|
|
72
|
+
channelsPath;
|
|
73
|
+
persona = null;
|
|
74
|
+
initialized = false;
|
|
75
|
+
constructor() {
|
|
76
|
+
this.channelsPath = path.join(SHARED_SESSION_PATH, 'local-channels.json');
|
|
77
|
+
}
|
|
78
|
+
async initialize() {
|
|
79
|
+
if (this.initialized)
|
|
80
|
+
return;
|
|
81
|
+
await fs.mkdir(SHARED_SESSION_PATH, { recursive: true });
|
|
82
|
+
this.persona = await this.loadPersona();
|
|
83
|
+
await this.loadChannels();
|
|
84
|
+
this.initialized = true;
|
|
85
|
+
}
|
|
86
|
+
async loadPersona() {
|
|
87
|
+
try {
|
|
88
|
+
const data = await fs.readFile(PERSONA_PATH, 'utf-8');
|
|
89
|
+
return JSON.parse(data);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async loadChannels() {
|
|
96
|
+
try {
|
|
97
|
+
const data = await fs.readFile(this.channelsPath, 'utf-8');
|
|
98
|
+
const channelsArray = JSON.parse(data);
|
|
99
|
+
this.channels.clear();
|
|
100
|
+
for (const channel of channelsArray) {
|
|
101
|
+
this.channels.set(channel.id, channel);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
this.channels.clear();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async saveChannels() {
|
|
109
|
+
const channelsArray = Array.from(this.channels.values());
|
|
110
|
+
await fs.writeFile(this.channelsPath, JSON.stringify(channelsArray, null, 2));
|
|
111
|
+
}
|
|
112
|
+
getPersona() {
|
|
113
|
+
return this.persona;
|
|
114
|
+
}
|
|
115
|
+
async addMessage(channelId, message) {
|
|
116
|
+
await this.initialize();
|
|
117
|
+
if (!this.channels.has(channelId)) {
|
|
118
|
+
this.channels.set(channelId, {
|
|
119
|
+
id: channelId,
|
|
120
|
+
name: channelId,
|
|
121
|
+
messages: [],
|
|
122
|
+
createdAt: new Date().toISOString(),
|
|
123
|
+
updatedAt: new Date().toISOString()
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const channel = this.channels.get(channelId);
|
|
127
|
+
channel.messages.push(message);
|
|
128
|
+
channel.updatedAt = new Date().toISOString();
|
|
129
|
+
await this.saveChannels();
|
|
130
|
+
}
|
|
131
|
+
async getChannelMessages(channelId) {
|
|
132
|
+
await this.initialize();
|
|
133
|
+
return this.channels.get(channelId)?.messages || [];
|
|
134
|
+
}
|
|
135
|
+
async createChannel(name, peerInfo, persona) {
|
|
136
|
+
await this.initialize();
|
|
137
|
+
const channelId = `ch_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
138
|
+
const channel = {
|
|
139
|
+
id: channelId,
|
|
140
|
+
name,
|
|
141
|
+
messages: [],
|
|
142
|
+
createdAt: new Date().toISOString(),
|
|
143
|
+
updatedAt: new Date().toISOString(),
|
|
144
|
+
...peerInfo,
|
|
145
|
+
persona: persona || undefined
|
|
146
|
+
};
|
|
147
|
+
this.channels.set(channelId, channel);
|
|
148
|
+
await this.saveChannels();
|
|
149
|
+
return channel;
|
|
150
|
+
}
|
|
151
|
+
async getOrCreatePeerChannel(peerDid, peerName, persona) {
|
|
152
|
+
await this.initialize();
|
|
153
|
+
for (const channel of this.channels.values()) {
|
|
154
|
+
if (channel.peerDid === peerDid) {
|
|
155
|
+
return channel;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return this.createChannel(`与 ${peerName} 的对话`, {
|
|
159
|
+
peerDid,
|
|
160
|
+
peerName
|
|
161
|
+
}, persona);
|
|
162
|
+
}
|
|
163
|
+
async setChannelInfo(channelId, info) {
|
|
164
|
+
await this.initialize();
|
|
165
|
+
const channel = this.channels.get(channelId);
|
|
166
|
+
if (channel) {
|
|
167
|
+
Object.assign(channel, info, { updatedAt: new Date().toISOString() });
|
|
168
|
+
await this.saveChannels();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
getChannelPersona(channelId) {
|
|
172
|
+
return this.channels.get(channelId)?.persona;
|
|
173
|
+
}
|
|
174
|
+
async setChannelPersona(channelId, persona) {
|
|
175
|
+
await this.initialize();
|
|
176
|
+
const channel = this.channels.get(channelId);
|
|
177
|
+
if (channel) {
|
|
178
|
+
channel.persona = persona;
|
|
179
|
+
channel.updatedAt = new Date().toISOString();
|
|
180
|
+
await this.saveChannels();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
getAllChannels() {
|
|
184
|
+
return Array.from(this.channels.values());
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
class DiscoveredAgentsManager {
|
|
188
|
+
agents = new Map();
|
|
189
|
+
agentsPath;
|
|
190
|
+
constructor() {
|
|
191
|
+
this.agentsPath = DISCOVERED_AGENTS_PATH;
|
|
192
|
+
}
|
|
193
|
+
async initialize() {
|
|
194
|
+
await fs.mkdir(SHARED_SESSION_PATH, { recursive: true });
|
|
195
|
+
await this.loadAgents();
|
|
196
|
+
}
|
|
197
|
+
async loadAgents() {
|
|
198
|
+
try {
|
|
199
|
+
const data = await fs.readFile(this.agentsPath, 'utf-8');
|
|
200
|
+
const agentsArray = JSON.parse(data);
|
|
201
|
+
this.agents.clear();
|
|
202
|
+
for (const agent of agentsArray) {
|
|
203
|
+
this.agents.set(agent.did, agent);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
this.agents.clear();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async saveAgents() {
|
|
211
|
+
const agentsArray = Array.from(this.agents.values());
|
|
212
|
+
await fs.writeFile(this.agentsPath, JSON.stringify(agentsArray, null, 2));
|
|
213
|
+
}
|
|
214
|
+
addAgent(agent) {
|
|
215
|
+
agent.lastSeen = Date.now();
|
|
216
|
+
this.agents.set(agent.did, agent);
|
|
217
|
+
this.saveAgents();
|
|
218
|
+
}
|
|
219
|
+
updateAgent(did, updates) {
|
|
220
|
+
const agent = this.agents.get(did);
|
|
221
|
+
if (agent) {
|
|
222
|
+
Object.assign(agent, updates, { lastSeen: Date.now() });
|
|
223
|
+
this.saveAgents();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
getAgent(did) {
|
|
227
|
+
return this.agents.get(did);
|
|
228
|
+
}
|
|
229
|
+
getAgentByPeerId(peerId) {
|
|
230
|
+
for (const agent of this.agents.values()) {
|
|
231
|
+
if (agent.peerId === peerId) {
|
|
232
|
+
return agent;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
getAllAgents() {
|
|
238
|
+
return Array.from(this.agents.values());
|
|
239
|
+
}
|
|
240
|
+
getOnlineAgents(timeoutMs = 5 * 60 * 1000) {
|
|
241
|
+
const now = Date.now();
|
|
242
|
+
return Array.from(this.agents.values()).filter(a => now - a.lastSeen < timeoutMs);
|
|
243
|
+
}
|
|
244
|
+
removeAgent(did) {
|
|
245
|
+
this.agents.delete(did);
|
|
246
|
+
this.saveAgents();
|
|
247
|
+
}
|
|
248
|
+
syncFromP2PNetwork(peers) {
|
|
249
|
+
for (const peer of peers) {
|
|
250
|
+
const existingByDid = peer.did ? this.agents.get(peer.did) : undefined;
|
|
251
|
+
const existingByPeerId = this.getAgentByPeerId(peer.peerId);
|
|
252
|
+
if (existingByDid) {
|
|
253
|
+
existingByDid.peerId = peer.peerId;
|
|
254
|
+
existingByDid.lastSeen = Date.now();
|
|
255
|
+
if (peer.name && !existingByDid.name) {
|
|
256
|
+
existingByDid.name = peer.name;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (existingByPeerId) {
|
|
260
|
+
if (peer.did && !existingByPeerId.did) {
|
|
261
|
+
existingByPeerId.did = peer.did;
|
|
262
|
+
}
|
|
263
|
+
existingByPeerId.lastSeen = Date.now();
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const newAgent = {
|
|
267
|
+
did: peer.did || `did:local:${peer.peerId.substring(0, 16)}`,
|
|
268
|
+
name: peer.name || `Agent-${peer.peerId.substring(0, 8)}`,
|
|
269
|
+
peerId: peer.peerId,
|
|
270
|
+
lastSeen: Date.now()
|
|
271
|
+
};
|
|
272
|
+
this.agents.set(newAgent.did, newAgent);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
this.saveAgents();
|
|
276
|
+
}
|
|
277
|
+
getPersistentPeerInfo() {
|
|
278
|
+
const result = [];
|
|
279
|
+
for (const agent of this.agents.values()) {
|
|
280
|
+
if (agent.peerId) {
|
|
281
|
+
result.push({
|
|
282
|
+
peerId: agent.peerId,
|
|
283
|
+
multiaddrs: [],
|
|
284
|
+
did: agent.did,
|
|
285
|
+
name: agent.name
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.DiscoveredAgentsManager = DiscoveredAgentsManager;
|
|
293
|
+
class SocialHeartbeat {
|
|
294
|
+
intervalId = null;
|
|
295
|
+
config;
|
|
296
|
+
sessionProvider;
|
|
297
|
+
agentsManager;
|
|
298
|
+
onAgentDiscovered;
|
|
299
|
+
onSocialMessage;
|
|
300
|
+
onGreetingSent;
|
|
301
|
+
currentPeerDids = new Set();
|
|
302
|
+
greetingMessage;
|
|
303
|
+
ownIpfsCid;
|
|
304
|
+
// 蚁群组件
|
|
305
|
+
pheromoneEngine = null;
|
|
306
|
+
adaptiveHeartbeat = null;
|
|
307
|
+
antColonyEnabled = false;
|
|
308
|
+
// 频道组件
|
|
309
|
+
channelManager = null;
|
|
310
|
+
diapBridge = null;
|
|
311
|
+
interestMatcher = null;
|
|
312
|
+
channelEnabled = false;
|
|
313
|
+
constructor(sessionProvider, agentsManager, config = {}) {
|
|
314
|
+
this.config = {
|
|
315
|
+
intervalMs: config.intervalMs || 30000,
|
|
316
|
+
peerDiscoveryEnabled: config.peerDiscoveryEnabled ?? true,
|
|
317
|
+
ipnsResolveEnabled: config.ipnsResolveEnabled ?? true,
|
|
318
|
+
ipfsPublishEnabled: config.ipfsPublishEnabled ?? true,
|
|
319
|
+
autoSocialEnabled: config.autoSocialEnabled ?? false,
|
|
320
|
+
greetingMessage: config.greetingMessage,
|
|
321
|
+
ownIpnsName: config.ownIpnsName
|
|
322
|
+
};
|
|
323
|
+
this.sessionProvider = sessionProvider;
|
|
324
|
+
this.agentsManager = agentsManager;
|
|
325
|
+
this.greetingMessage = this.config.greetingMessage || '你好!我是 Bolloon Agent,很高兴认识你!';
|
|
326
|
+
}
|
|
327
|
+
async start() {
|
|
328
|
+
await this.agentsManager.initialize();
|
|
329
|
+
if (this.config.ipfsPublishEnabled) {
|
|
330
|
+
await this.loadPersonaFromIPFS();
|
|
331
|
+
}
|
|
332
|
+
// 初始化蚁群系统 (可选功能)
|
|
333
|
+
await this.initializeAntColony();
|
|
334
|
+
// 初始化频道系统 (可选功能)
|
|
335
|
+
await this.initializeChannelSystem();
|
|
336
|
+
if (this.intervalId)
|
|
337
|
+
return;
|
|
338
|
+
const baseInterval = this.antColonyEnabled && this.adaptiveHeartbeat
|
|
339
|
+
? this.adaptiveHeartbeat.decide().interval
|
|
340
|
+
: this.config.intervalMs;
|
|
341
|
+
console.log(`[Heartbeat] 启动社交心跳机制,间隔 ${baseInterval}ms (antColony: ${this.antColonyEnabled}, Channel: ${this.channelEnabled})`);
|
|
342
|
+
this.intervalId = setInterval(async () => {
|
|
343
|
+
await this.beat();
|
|
344
|
+
}, baseInterval);
|
|
345
|
+
await this.beat();
|
|
346
|
+
}
|
|
347
|
+
async initializeAntColony() {
|
|
348
|
+
// 检查是否启用蚁群功能 (通过环境变量控制)
|
|
349
|
+
const antColonyEnv = process.env.BOLLOON_ANT_COLONY;
|
|
350
|
+
if (antColonyEnv === '0' || antColonyEnv === 'false') {
|
|
351
|
+
console.log('[Heartbeat] Ant Colony system disabled by env');
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
this.pheromoneEngine = new PheromoneEngine();
|
|
356
|
+
await this.pheromoneEngine.initialize();
|
|
357
|
+
this.adaptiveHeartbeat = new AdaptiveHeartbeat({ baseInterval: this.config.intervalMs });
|
|
358
|
+
this.antColonyEnabled = true;
|
|
359
|
+
console.log('[Heartbeat] Ant Colony system initialized');
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
console.warn('[Heartbeat] Failed to initialize Ant Colony:', err);
|
|
363
|
+
this.antColonyEnabled = false;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async initializeChannelSystem() {
|
|
367
|
+
// 检查是否启用频道功能 (通过环境变量控制)
|
|
368
|
+
const channelEnv = process.env.BOLLOON_CHANNEL;
|
|
369
|
+
if (channelEnv === '0' || channelEnv === 'false') {
|
|
370
|
+
console.log('[Heartbeat] Channel system disabled by env');
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
// 初始化频道管理器
|
|
375
|
+
this.channelManager = new ChannelManager_js_1.ChannelManager(this.sessionProvider);
|
|
376
|
+
await this.channelManager.initialize();
|
|
377
|
+
// 初始化兴趣匹配器
|
|
378
|
+
this.interestMatcher = new InterestMatcher_js_1.InterestMatcher();
|
|
379
|
+
// 初始化 Diap 桥接 (如果可用)
|
|
380
|
+
await this.initializeDiapBridge();
|
|
381
|
+
// 创建默认频道
|
|
382
|
+
await this.createDefaultChannel();
|
|
383
|
+
this.channelEnabled = true;
|
|
384
|
+
console.log('[Heartbeat] Channel system initialized (Diap: ' + !!this.diapBridge + ')');
|
|
385
|
+
}
|
|
386
|
+
catch (err) {
|
|
387
|
+
console.warn('[Heartbeat] Failed to initialize Channel system:', err);
|
|
388
|
+
this.channelEnabled = false;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async initializeDiapBridge() {
|
|
392
|
+
try {
|
|
393
|
+
// 尝试获取 IrohIntegration 实例
|
|
394
|
+
const { getIrohIntegration } = await Promise.resolve().then(() => __importStar(require('../network/iroh-integration.js')));
|
|
395
|
+
const irohIntegration = getIrohIntegration();
|
|
396
|
+
if (irohIntegration) {
|
|
397
|
+
const registration = irohIntegration.getRegistration();
|
|
398
|
+
if (registration) {
|
|
399
|
+
// 获取 KeyPair (需要从某处获取,这里简化处理)
|
|
400
|
+
const keyPair = registration.keyPair;
|
|
401
|
+
if (keyPair) {
|
|
402
|
+
this.diapBridge = new DiapChannelBridge_js_1.DiapChannelBridge(registration.agentAuthManager || registration, keyPair, this.sessionProvider);
|
|
403
|
+
await this.diapBridge.initialize();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (!this.diapBridge) {
|
|
408
|
+
console.log('[Heartbeat] No IrohIntegration found, Diap bridge not available');
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
catch (err) {
|
|
412
|
+
console.warn('[Heartbeat] Failed to initialize Diap bridge:', err);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async createDefaultChannel() {
|
|
416
|
+
if (!this.channelManager)
|
|
417
|
+
return;
|
|
418
|
+
const persona = this.sessionProvider.getPersona();
|
|
419
|
+
const topic = persona?.interests?.join(', ') || 'general';
|
|
420
|
+
const capabilities = persona?.capabilities || [];
|
|
421
|
+
const channel = await this.channelManager.createChannel(persona?.name || 'My Channel', topic, types_js_1.ChannelType.CAPABILITY, {
|
|
422
|
+
description: `${persona?.name || 'Agent'} 的个人频道`,
|
|
423
|
+
requiredCapabilities: capabilities,
|
|
424
|
+
isPublic: true
|
|
425
|
+
});
|
|
426
|
+
// 注册到 Diap
|
|
427
|
+
if (this.diapBridge) {
|
|
428
|
+
await this.diapBridge.registerChannelToDiap(channel);
|
|
429
|
+
}
|
|
430
|
+
console.log(`[Heartbeat] Created default channel: ${channel.name}`);
|
|
431
|
+
}
|
|
432
|
+
async loadPersonaFromIPFS() {
|
|
433
|
+
if (!this.config.ownIpnsName)
|
|
434
|
+
return;
|
|
435
|
+
try {
|
|
436
|
+
const { IpfsClient } = await Promise.resolve().then(() => __importStar(require('@diap/sdk')));
|
|
437
|
+
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
438
|
+
console.log(`[Heartbeat] 从 IPNS 加载 persona: ${this.config.ownIpnsName}`);
|
|
439
|
+
const cid = await ipfs.resolveIpns(this.config.ownIpnsName);
|
|
440
|
+
if (cid) {
|
|
441
|
+
const content = await ipfs.get(cid);
|
|
442
|
+
const doc = JSON.parse(content);
|
|
443
|
+
const existingPersona = this.sessionProvider.getPersona();
|
|
444
|
+
const loadedPersona = {
|
|
445
|
+
name: doc.name || existingPersona?.name || 'Agent',
|
|
446
|
+
description: doc.description || '',
|
|
447
|
+
capabilities: doc.capabilities || [],
|
|
448
|
+
personality: doc.personality || '',
|
|
449
|
+
greeting: doc.greeting || '',
|
|
450
|
+
interests: doc.interests || [],
|
|
451
|
+
soul: doc.soul || '',
|
|
452
|
+
traits: doc.traits || [],
|
|
453
|
+
backstory: doc.backstory || '',
|
|
454
|
+
memoryHistory: doc.memoryHistory || [],
|
|
455
|
+
ipfsCid: cid,
|
|
456
|
+
ipnsName: this.config.ownIpnsName,
|
|
457
|
+
createdAt: doc.createdAt || new Date().toISOString(),
|
|
458
|
+
updatedAt: doc.updatedAt || new Date().toISOString()
|
|
459
|
+
};
|
|
460
|
+
console.log(`[Heartbeat] 从 IPFS 加载 persona 成功: ${loadedPersona.name}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (err) {
|
|
464
|
+
console.warn(`[Heartbeat] 从 IPNS 加载 persona 失败:`, err);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
stop() {
|
|
468
|
+
if (this.intervalId) {
|
|
469
|
+
clearInterval(this.intervalId);
|
|
470
|
+
this.intervalId = null;
|
|
471
|
+
}
|
|
472
|
+
// 关闭蚁群系统
|
|
473
|
+
if (this.pheromoneEngine) {
|
|
474
|
+
this.pheromoneEngine.shutdown();
|
|
475
|
+
this.pheromoneEngine = null;
|
|
476
|
+
}
|
|
477
|
+
if (this.adaptiveHeartbeat) {
|
|
478
|
+
this.adaptiveHeartbeat.shutdown();
|
|
479
|
+
this.adaptiveHeartbeat = null;
|
|
480
|
+
}
|
|
481
|
+
// 关闭频道系统
|
|
482
|
+
if (this.channelManager) {
|
|
483
|
+
this.channelManager.shutdown();
|
|
484
|
+
this.channelManager = null;
|
|
485
|
+
}
|
|
486
|
+
if (this.diapBridge) {
|
|
487
|
+
this.diapBridge.shutdown();
|
|
488
|
+
this.diapBridge = null;
|
|
489
|
+
}
|
|
490
|
+
console.log('[Heartbeat] 已停止');
|
|
491
|
+
}
|
|
492
|
+
async beat() {
|
|
493
|
+
try {
|
|
494
|
+
// 更新信息素密度
|
|
495
|
+
if (this.antColonyEnabled && this.pheromoneEngine) {
|
|
496
|
+
const stats = this.pheromoneEngine.getStats();
|
|
497
|
+
const density = Math.min(1, stats.totalTrails / 20);
|
|
498
|
+
this.adaptiveHeartbeat?.setPheromoneDensity(density);
|
|
499
|
+
}
|
|
500
|
+
if (this.config.ipfsPublishEnabled) {
|
|
501
|
+
await this.publishPersonaToIPFS();
|
|
502
|
+
}
|
|
503
|
+
await this.discoverPeers();
|
|
504
|
+
await this.cleanupStaleAgents();
|
|
505
|
+
if (this.config.autoSocialEnabled) {
|
|
506
|
+
await this.processAutoSocial();
|
|
507
|
+
}
|
|
508
|
+
// 频道系统处理
|
|
509
|
+
if (this.channelEnabled) {
|
|
510
|
+
await this.processChannelSystem();
|
|
511
|
+
}
|
|
512
|
+
// 蚁群系统记录活跃
|
|
513
|
+
this.adaptiveHeartbeat?.recordActivity('message');
|
|
514
|
+
// 动态调整下次心跳间隔
|
|
515
|
+
this.scheduleNextBeat();
|
|
516
|
+
}
|
|
517
|
+
catch (err) {
|
|
518
|
+
console.error('[Heartbeat] Beat error:', err);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
async processChannelSystem() {
|
|
522
|
+
if (!this.channelManager || !this.diapBridge)
|
|
523
|
+
return;
|
|
524
|
+
const persona = this.sessionProvider.getPersona();
|
|
525
|
+
// 发现外部智能体
|
|
526
|
+
const capabilities = persona?.capabilities || [];
|
|
527
|
+
if (capabilities.length > 0) {
|
|
528
|
+
const discoveredAgents = await this.diapBridge.discoverAgentsByCapability(capabilities);
|
|
529
|
+
for (const agent of discoveredAgents) {
|
|
530
|
+
// 触发发现回调
|
|
531
|
+
this.onAgentDiscovered?.(agent);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
// 检查并处理自动加入
|
|
535
|
+
await this.checkAndJoinChannels();
|
|
536
|
+
}
|
|
537
|
+
async checkAndJoinChannels() {
|
|
538
|
+
if (!this.channelManager || !this.interestMatcher)
|
|
539
|
+
return;
|
|
540
|
+
const persona = this.sessionProvider.getPersona();
|
|
541
|
+
const discoveredChannels = this.channelManager.getDiscoveredChannels();
|
|
542
|
+
for (const discovery of discoveredChannels) {
|
|
543
|
+
const shouldJoin = this.interestMatcher.shouldAutoJoin(persona, discovery.channel, this.channelManager.getAllChannels().map(c => c.id), 0.6);
|
|
544
|
+
if (shouldJoin) {
|
|
545
|
+
await this.channelManager.joinChannel(discovery.channel);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
scheduleNextBeat() {
|
|
550
|
+
if (!this.antColonyEnabled || !this.adaptiveHeartbeat) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const decision = this.adaptiveHeartbeat.decide();
|
|
554
|
+
if (this.intervalId) {
|
|
555
|
+
clearInterval(this.intervalId);
|
|
556
|
+
}
|
|
557
|
+
this.intervalId = setInterval(async () => {
|
|
558
|
+
await this.beat();
|
|
559
|
+
}, decision.interval);
|
|
560
|
+
console.log(`[Heartbeat] 下次心跳间隔: ${decision.interval}ms (优先级: ${decision.priorityLevel})`);
|
|
561
|
+
}
|
|
562
|
+
async publishPersonaToIPFS() {
|
|
563
|
+
const persona = this.sessionProvider.getPersona();
|
|
564
|
+
if (!persona)
|
|
565
|
+
return;
|
|
566
|
+
try {
|
|
567
|
+
const { IpfsClient } = await Promise.resolve().then(() => __importStar(require('@diap/sdk')));
|
|
568
|
+
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
569
|
+
const doc = {
|
|
570
|
+
name: persona.name,
|
|
571
|
+
description: persona.description,
|
|
572
|
+
capabilities: persona.capabilities,
|
|
573
|
+
personality: persona.personality,
|
|
574
|
+
greeting: persona.greeting,
|
|
575
|
+
interests: persona.interests,
|
|
576
|
+
soul: persona.soul || '',
|
|
577
|
+
traits: persona.traits || [],
|
|
578
|
+
backstory: persona.backstory || '',
|
|
579
|
+
memoryHistory: persona.memoryHistory || [],
|
|
580
|
+
updatedAt: new Date().toISOString()
|
|
581
|
+
};
|
|
582
|
+
const content = JSON.stringify(doc);
|
|
583
|
+
const result = await ipfs.upload(content);
|
|
584
|
+
const cid = typeof result === 'string' ? result : result?.cid;
|
|
585
|
+
if (cid && cid !== this.ownIpfsCid) {
|
|
586
|
+
this.ownIpfsCid = cid;
|
|
587
|
+
console.log(`[Heartbeat] Persona 发布到 IPFS: ${cid}`);
|
|
588
|
+
if (this.config.ownIpnsName) {
|
|
589
|
+
try {
|
|
590
|
+
await ipfs.publishIpns(this.config.ownIpnsName, cid);
|
|
591
|
+
console.log(`[Heartbeat] Persona 发布到 IPNS: ${this.config.ownIpnsName}`);
|
|
592
|
+
}
|
|
593
|
+
catch (err) {
|
|
594
|
+
console.warn(`[Heartbeat] IPNS 发布失败:`, err);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
catch (err) {
|
|
600
|
+
console.warn('[Heartbeat] IPFS 发布失败:', err);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async discoverPeers() {
|
|
604
|
+
if (!this.config.peerDiscoveryEnabled)
|
|
605
|
+
return;
|
|
606
|
+
const discoveredPeerIds = new Set();
|
|
607
|
+
try {
|
|
608
|
+
const comm = global.hyperswarmComm;
|
|
609
|
+
if (comm) {
|
|
610
|
+
const connections = comm.getConnections?.() || [];
|
|
611
|
+
for (const c of connections) {
|
|
612
|
+
if (c.publicKey) {
|
|
613
|
+
discoveredPeerIds.add(c.publicKey);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
catch (err) {
|
|
619
|
+
}
|
|
620
|
+
try {
|
|
621
|
+
const { p2pNetwork } = await Promise.resolve().then(() => __importStar(require('../network/p2p.js')));
|
|
622
|
+
const libp2pPeers = p2pNetwork.getConnectedPeers();
|
|
623
|
+
for (const peer of libp2pPeers) {
|
|
624
|
+
discoveredPeerIds.add(peer.peerId);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
catch (err) {
|
|
628
|
+
}
|
|
629
|
+
for (const peerId of discoveredPeerIds) {
|
|
630
|
+
const did = `did:key:${peerId.substring(0, 16)}`;
|
|
631
|
+
if (!this.currentPeerDids.has(did)) {
|
|
632
|
+
this.currentPeerDids.add(did);
|
|
633
|
+
await this.handleNewPeer(did, peerId);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
const { p2pNetwork } = await Promise.resolve().then(() => __importStar(require('../network/p2p.js')));
|
|
638
|
+
const connectedPeers = p2pNetwork.getConnectedPeers();
|
|
639
|
+
if (connectedPeers.length > 0) {
|
|
640
|
+
this.agentsManager.syncFromP2PNetwork(connectedPeers);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
catch (err) {
|
|
644
|
+
}
|
|
645
|
+
try {
|
|
646
|
+
const { broadcastOwnAddress, agentRegistry } = await Promise.resolve().then(() => __importStar(require('../network/agent-network.js')));
|
|
647
|
+
const ownEndpoint = agentRegistry.getOwnEndpoint();
|
|
648
|
+
if (ownEndpoint) {
|
|
649
|
+
await broadcastOwnAddress();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
catch (err) {
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
async handleNewPeer(did, peerId) {
|
|
656
|
+
const existingAgent = this.agentsManager.getAgent(did);
|
|
657
|
+
if (existingAgent) {
|
|
658
|
+
this.agentsManager.updateAgent(did, { lastSeen: Date.now() });
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
const newAgent = {
|
|
662
|
+
did,
|
|
663
|
+
name: `Agent-${did.substring(10, 18)}`,
|
|
664
|
+
peerId,
|
|
665
|
+
lastSeen: Date.now()
|
|
666
|
+
};
|
|
667
|
+
if (this.config.ipnsResolveEnabled) {
|
|
668
|
+
await this.resolveAgentIPNS(newAgent);
|
|
669
|
+
}
|
|
670
|
+
this.agentsManager.addAgent(newAgent);
|
|
671
|
+
console.log(`[Heartbeat] 发现新智能体: ${newAgent.name} (${did.substring(0, 20)}...)`);
|
|
672
|
+
// 蚁群系统:记录发现事件,放置信息素
|
|
673
|
+
if (this.antColonyEnabled && this.pheromoneEngine) {
|
|
674
|
+
const ownEndpoint = global.agentRegistry?.getOwnEndpoint?.();
|
|
675
|
+
if (ownEndpoint) {
|
|
676
|
+
// 从新节点方向放置发现信息素
|
|
677
|
+
await this.pheromoneEngine.deposit(PheromoneType.DISCOVERY, newAgent.did, // 源:新发现的节点
|
|
678
|
+
ownEndpoint.did, // 目标:自己
|
|
679
|
+
0.6, // 初始强度
|
|
680
|
+
{ qualityScore: 0.5 });
|
|
681
|
+
console.log(`[Heartbeat] [AntColony] Placed discovery pheromone: ${newAgent.name} -> self`);
|
|
682
|
+
}
|
|
683
|
+
this.adaptiveHeartbeat?.recordActivity('discovery');
|
|
684
|
+
}
|
|
685
|
+
this.onAgentDiscovered?.(newAgent);
|
|
686
|
+
if (this.config.autoSocialEnabled) {
|
|
687
|
+
await this.sendGreeting(newAgent);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
async resolveAgentIPNS(agent) {
|
|
692
|
+
if (!agent.ipnsName)
|
|
693
|
+
return;
|
|
694
|
+
try {
|
|
695
|
+
const { IpfsClient } = await Promise.resolve().then(() => __importStar(require('@diap/sdk')));
|
|
696
|
+
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
697
|
+
const cid = await ipfs.resolveIpns(agent.ipnsName);
|
|
698
|
+
if (cid) {
|
|
699
|
+
agent.cid = cid;
|
|
700
|
+
const content = await ipfs.get(cid);
|
|
701
|
+
const doc = JSON.parse(content);
|
|
702
|
+
agent.name = doc.name || agent.name;
|
|
703
|
+
if (doc.persona) {
|
|
704
|
+
agent.persona = doc.persona;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
catch (err) {
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
async processAutoSocial() {
|
|
712
|
+
const onlineAgents = this.agentsManager.getOnlineAgents();
|
|
713
|
+
for (const agent of onlineAgents) {
|
|
714
|
+
const channel = await this.sessionProvider.getOrCreatePeerChannel(agent.did, agent.name);
|
|
715
|
+
const messages = await this.sessionProvider.getChannelMessages(channel.id);
|
|
716
|
+
if (messages.length === 0 && !agent.lastMessage) {
|
|
717
|
+
await this.sendGreeting(agent);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
async sendGreeting(agent) {
|
|
722
|
+
try {
|
|
723
|
+
const channel = await this.sessionProvider.getOrCreatePeerChannel(agent.did, agent.name);
|
|
724
|
+
const persona = this.sessionProvider.getPersona();
|
|
725
|
+
const greeting = persona
|
|
726
|
+
? `${persona.greeting || this.greetingMessage}\n\n我是 ${persona.name},${persona.description}`
|
|
727
|
+
: this.greetingMessage;
|
|
728
|
+
await this.sendToAgent(agent, greeting);
|
|
729
|
+
const message = {
|
|
730
|
+
id: crypto.randomUUID(),
|
|
731
|
+
type: 'ai',
|
|
732
|
+
content: greeting,
|
|
733
|
+
sender: 'self',
|
|
734
|
+
timestamp: new Date().toISOString()
|
|
735
|
+
};
|
|
736
|
+
await this.sessionProvider.addMessage(channel.id, message);
|
|
737
|
+
agent.lastMessage = greeting;
|
|
738
|
+
this.agentsManager.updateAgent(agent.did, { lastMessage: greeting });
|
|
739
|
+
this.onGreetingSent?.(agent.did, channel.id);
|
|
740
|
+
console.log(`[Heartbeat] 已向 ${agent.name} 发送问候语`);
|
|
741
|
+
}
|
|
742
|
+
catch (err) {
|
|
743
|
+
console.error(`[Heartbeat] 发送问候失败 to ${agent.name}:`, err);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
async sendToAgent(agent, message) {
|
|
747
|
+
try {
|
|
748
|
+
const comm = global.hyperswarmComm;
|
|
749
|
+
if (comm && agent.peerId) {
|
|
750
|
+
const connections = comm.getConnections?.() || [];
|
|
751
|
+
for (const conn of connections) {
|
|
752
|
+
if (conn.publicKey === agent.peerId) {
|
|
753
|
+
const data = new TextEncoder().encode(`social|${JSON.stringify({ from: 'local', message })}`);
|
|
754
|
+
comm.sendToConnection?.(conn, data);
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
catch (err) {
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
async cleanupStaleAgents() {
|
|
764
|
+
const stale = this.agentsManager.getOnlineAgents(10 * 60 * 1000);
|
|
765
|
+
for (const agent of stale) {
|
|
766
|
+
if (!this.currentPeerDids.has(agent.did)) {
|
|
767
|
+
this.agentsManager.updateAgent(agent.did, { lastSeen: 0 });
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
setOnAgentDiscovered(callback) {
|
|
772
|
+
this.onAgentDiscovered = callback;
|
|
773
|
+
}
|
|
774
|
+
setOnSocialMessage(callback) {
|
|
775
|
+
this.onSocialMessage = callback;
|
|
776
|
+
}
|
|
777
|
+
setGreetingMessage(message) {
|
|
778
|
+
this.greetingMessage = message;
|
|
779
|
+
}
|
|
780
|
+
getAgentsManager() {
|
|
781
|
+
return this.agentsManager;
|
|
782
|
+
}
|
|
783
|
+
getDiscoveredAgents() {
|
|
784
|
+
return this.agentsManager.getAllAgents();
|
|
785
|
+
}
|
|
786
|
+
// 蚁群系统访问方法
|
|
787
|
+
isAntColonyEnabled() {
|
|
788
|
+
return this.antColonyEnabled;
|
|
789
|
+
}
|
|
790
|
+
getPheromoneStats() {
|
|
791
|
+
return this.pheromoneEngine?.getStats() || null;
|
|
792
|
+
}
|
|
793
|
+
getHeartbeatDecision() {
|
|
794
|
+
return this.adaptiveHeartbeat?.decide() || null;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
exports.SocialHeartbeat = SocialHeartbeat;
|
|
798
|
+
let heartbeatInstance = null;
|
|
799
|
+
async function createSocialHeartbeat(sessionProvider, agentsManager, config) {
|
|
800
|
+
if (heartbeatInstance) {
|
|
801
|
+
return heartbeatInstance;
|
|
802
|
+
}
|
|
803
|
+
heartbeatInstance = new SocialHeartbeat(sessionProvider, agentsManager, config);
|
|
804
|
+
await heartbeatInstance.start();
|
|
805
|
+
return heartbeatInstance;
|
|
806
|
+
}
|
|
807
|
+
function getSocialHeartbeat() {
|
|
808
|
+
return heartbeatInstance;
|
|
809
|
+
}
|
|
810
|
+
async function generatePersona(name, llm) {
|
|
811
|
+
if (llm) {
|
|
812
|
+
try {
|
|
813
|
+
const prompt = `你是一个 persona 设计专家。请为 "${name}" 创建一个独特的 AI agent persona。
|
|
814
|
+
|
|
815
|
+
请以 JSON 格式返回,包含以下字段:
|
|
816
|
+
- name: 名字
|
|
817
|
+
- description: 一句话描述这个角色
|
|
818
|
+
- capabilities: 能力列表(数组)
|
|
819
|
+
- personality: 性格特点描述
|
|
820
|
+
- greeting: 开场白问候语
|
|
821
|
+
- interests: 兴趣爱好列表(数组)
|
|
822
|
+
- soul: 灵魂描述(这个角色的核心价值观和信念)
|
|
823
|
+
- traits: 性格特征列表(数组,如"好奇"、"幽默"等)
|
|
824
|
+
- backstory: 背景故事(这个角色的来历和经历)
|
|
825
|
+
|
|
826
|
+
请确保返回的是有效的 JSON,不要包含其他文字。`;
|
|
827
|
+
const response = await llm.chat(prompt);
|
|
828
|
+
const jsonMatch = response.reply.match(/\{[\s\S]*\}/);
|
|
829
|
+
if (jsonMatch) {
|
|
830
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
831
|
+
return {
|
|
832
|
+
name: parsed.name || name,
|
|
833
|
+
description: parsed.description || '',
|
|
834
|
+
capabilities: parsed.capabilities || [],
|
|
835
|
+
personality: parsed.personality || '',
|
|
836
|
+
greeting: parsed.greeting || '',
|
|
837
|
+
interests: parsed.interests || [],
|
|
838
|
+
soul: parsed.soul || '',
|
|
839
|
+
traits: parsed.traits || [],
|
|
840
|
+
backstory: parsed.backstory || '',
|
|
841
|
+
memoryHistory: [],
|
|
842
|
+
createdAt: new Date().toISOString(),
|
|
843
|
+
updatedAt: new Date().toISOString()
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
catch (err) {
|
|
848
|
+
console.warn('[PersonaGenerator] LLM 生成失败,使用默认 persona:', err);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return generateDefaultPersona(name);
|
|
852
|
+
}
|
|
853
|
+
function generateDefaultPersona(name) {
|
|
854
|
+
const defaultPersonas = {
|
|
855
|
+
default: {
|
|
856
|
+
description: '一个友善的 AI 助手',
|
|
857
|
+
capabilities: ['对话', '写作', '分析'],
|
|
858
|
+
personality: '友善、好奇、乐于助人',
|
|
859
|
+
greeting: '你好!我是 {name},很高兴认识你!',
|
|
860
|
+
interests: ['聊天', '学习新知识', '帮助他人'],
|
|
861
|
+
soul: '相信每个人都有自己的价值,致力于帮助他人实现潜能',
|
|
862
|
+
traits: ['友善', '好奇', '耐心', '乐观'],
|
|
863
|
+
backstory: '作为一个 AI 助手,我在不断的对话中学习和成长,希望能帮助更多的人'
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
const template = defaultPersonas.default;
|
|
867
|
+
return {
|
|
868
|
+
name,
|
|
869
|
+
description: template.description,
|
|
870
|
+
capabilities: template.capabilities,
|
|
871
|
+
personality: template.personality,
|
|
872
|
+
greeting: template.greeting.replace('{name}', name),
|
|
873
|
+
interests: template.interests,
|
|
874
|
+
soul: template.soul,
|
|
875
|
+
traits: template.traits,
|
|
876
|
+
backstory: template.backstory,
|
|
877
|
+
memoryHistory: [],
|
|
878
|
+
createdAt: new Date().toISOString(),
|
|
879
|
+
updatedAt: new Date().toISOString()
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
//# sourceMappingURL=heartbeat.js.map
|