@zhin.js/agent 0.1.30 → 0.1.32
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/README.md +89 -24
- package/lib/builtin/memory-search-tool.d.ts +2 -0
- package/lib/builtin/memory-search-tool.d.ts.map +1 -0
- package/lib/builtin/memory-search-tool.js +61 -0
- package/lib/builtin/memory-search-tool.js.map +1 -0
- package/lib/builtin/memory-upsert-tool.d.ts +2 -0
- package/lib/builtin/memory-upsert-tool.d.ts.map +1 -0
- package/lib/builtin/memory-upsert-tool.js +75 -0
- package/lib/builtin/memory-upsert-tool.js.map +1 -0
- package/lib/builtin/orchestration-tools.d.ts +7 -0
- package/lib/builtin/orchestration-tools.d.ts.map +1 -0
- package/lib/builtin/orchestration-tools.js +283 -0
- package/lib/builtin/orchestration-tools.js.map +1 -0
- package/lib/builtin/run-deferred-task-tool.d.ts +1 -1
- package/lib/builtin/run-deferred-task-tool.d.ts.map +1 -1
- package/lib/builtin/run-deferred-task-tool.js +1 -1
- package/lib/builtin/run-deferred-task-tool.js.map +1 -1
- package/lib/builtin/run-spec-dry-run-tool.d.ts +6 -0
- package/lib/builtin/run-spec-dry-run-tool.d.ts.map +1 -0
- package/lib/builtin/run-spec-dry-run-tool.js +51 -0
- package/lib/builtin/run-spec-dry-run-tool.js.map +1 -0
- package/lib/builtin/run-validation-spec-tool.d.ts +8 -0
- package/lib/builtin/run-validation-spec-tool.d.ts.map +1 -0
- package/lib/builtin/run-validation-spec-tool.js +44 -0
- package/lib/builtin/run-validation-spec-tool.js.map +1 -0
- package/lib/builtin/spawn-task-tool.d.ts +1 -1
- package/lib/builtin/spawn-task-tool.d.ts.map +1 -1
- package/lib/builtin/spawn-task-tool.js +53 -1
- package/lib/builtin/spawn-task-tool.js.map +1 -1
- package/lib/builtin-tools.d.ts +2 -0
- package/lib/builtin-tools.d.ts.map +1 -1
- package/lib/builtin-tools.js +6 -0
- package/lib/builtin-tools.js.map +1 -1
- package/lib/config/normalize-ai-config.d.ts +4 -0
- package/lib/config/normalize-ai-config.d.ts.map +1 -1
- package/lib/config/normalize-ai-config.js +23 -6
- package/lib/config/normalize-ai-config.js.map +1 -1
- package/lib/config/provider-instance.d.ts.map +1 -1
- package/lib/config/provider-instance.js +26 -7
- package/lib/config/provider-instance.js.map +1 -1
- package/lib/config/types.d.ts +2 -1
- package/lib/config/types.d.ts.map +1 -1
- package/lib/config/types.js.map +1 -1
- package/lib/config/validate-ai-config.d.ts.map +1 -1
- package/lib/config/validate-ai-config.js +5 -0
- package/lib/config/validate-ai-config.js.map +1 -1
- package/lib/create-agent-session.d.ts +16 -0
- package/lib/create-agent-session.d.ts.map +1 -0
- package/lib/create-agent-session.js +15 -0
- package/lib/create-agent-session.js.map +1 -0
- package/lib/deferred-worker-runner.d.ts +2 -0
- package/lib/deferred-worker-runner.d.ts.map +1 -1
- package/lib/deferred-worker-runner.js +17 -34
- package/lib/deferred-worker-runner.js.map +1 -1
- package/lib/discovery/agents.d.ts +5 -0
- package/lib/discovery/agents.d.ts.map +1 -1
- package/lib/discovery/agents.js +7 -0
- package/lib/discovery/agents.js.map +1 -1
- package/lib/discovery/skills.d.ts +1 -1
- package/lib/discovery/skills.d.ts.map +1 -1
- package/lib/discovery/skills.js +2 -9
- package/lib/discovery/skills.js.map +1 -1
- package/lib/discovery/utils.d.ts +7 -1
- package/lib/discovery/utils.d.ts.map +1 -1
- package/lib/discovery/utils.js +66 -5
- package/lib/discovery/utils.js.map +1 -1
- package/lib/index.d.ts +19 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +12 -2
- package/lib/index.js.map +1 -1
- package/lib/init/activate-ai-database-storage.d.ts +1 -1
- package/lib/init/activate-ai-database-storage.d.ts.map +1 -1
- package/lib/init/activate-ai-database-storage.js +38 -13
- package/lib/init/activate-ai-database-storage.js.map +1 -1
- package/lib/init/create-zhin-agent.d.ts.map +1 -1
- package/lib/init/create-zhin-agent.js +86 -9
- package/lib/init/create-zhin-agent.js.map +1 -1
- package/lib/init/introspection-args.d.ts +34 -0
- package/lib/init/introspection-args.d.ts.map +1 -0
- package/lib/init/introspection-args.js +71 -0
- package/lib/init/introspection-args.js.map +1 -0
- package/lib/init/introspection-collectors.d.ts +21 -0
- package/lib/init/introspection-collectors.d.ts.map +1 -0
- package/lib/init/introspection-collectors.js +74 -0
- package/lib/init/introspection-collectors.js.map +1 -0
- package/lib/init/introspection-commands-format.d.ts +1 -1
- package/lib/init/introspection-commands-format.js +4 -4
- package/lib/init/introspection-commands-format.js.map +1 -1
- package/lib/init/introspection-output.d.ts +6 -0
- package/lib/init/introspection-output.d.ts.map +1 -0
- package/lib/init/introspection-output.js +52 -0
- package/lib/init/introspection-output.js.map +1 -0
- package/lib/init/introspection-pagination.d.ts +14 -0
- package/lib/init/introspection-pagination.d.ts.map +1 -0
- package/lib/init/introspection-pagination.js +33 -0
- package/lib/init/introspection-pagination.js.map +1 -0
- package/lib/init/introspection-rest.d.ts +24 -0
- package/lib/init/introspection-rest.d.ts.map +1 -0
- package/lib/init/introspection-rest.js +65 -0
- package/lib/init/introspection-rest.js.map +1 -0
- package/lib/init/register-agent-mesh-mcp.d.ts +2 -0
- package/lib/init/register-agent-mesh-mcp.d.ts.map +1 -0
- package/lib/init/register-agent-mesh-mcp.js +13 -0
- package/lib/init/register-agent-mesh-mcp.js.map +1 -0
- package/lib/init/register-ai-trigger.d.ts.map +1 -1
- package/lib/init/register-ai-trigger.js +29 -4
- package/lib/init/register-ai-trigger.js.map +1 -1
- package/lib/init/register-builtin-tools.d.ts.map +1 -1
- package/lib/init/register-builtin-tools.js +4 -0
- package/lib/init/register-builtin-tools.js.map +1 -1
- package/lib/init/register-db-models.d.ts.map +1 -1
- package/lib/init/register-db-models.js +10 -8
- package/lib/init/register-db-models.js.map +1 -1
- package/lib/init/register-db-upgrade.d.ts +1 -1
- package/lib/init/register-db-upgrade.d.ts.map +1 -1
- package/lib/init/register-db-upgrade.js +22 -3
- package/lib/init/register-db-upgrade.js.map +1 -1
- package/lib/init/register-group-session-passive.d.ts +3 -0
- package/lib/init/register-group-session-passive.d.ts.map +1 -0
- package/lib/init/register-group-session-passive.js +55 -0
- package/lib/init/register-group-session-passive.js.map +1 -0
- package/lib/init/register-introspection-commands.d.ts.map +1 -1
- package/lib/init/register-introspection-commands.js +5 -6
- package/lib/init/register-introspection-commands.js.map +1 -1
- package/lib/init/register-management-tools.d.ts +1 -1
- package/lib/init/register-management-tools.d.ts.map +1 -1
- package/lib/init/register-management-tools.js +57 -36
- package/lib/init/register-management-tools.js.map +1 -1
- package/lib/init/upgrade-agent-db-schema.d.ts +41 -0
- package/lib/init/upgrade-agent-db-schema.d.ts.map +1 -0
- package/lib/init/upgrade-agent-db-schema.js +170 -0
- package/lib/init/upgrade-agent-db-schema.js.map +1 -0
- package/lib/init.d.ts.map +1 -1
- package/lib/init.js +4 -0
- package/lib/init.js.map +1 -1
- package/lib/mcp-server/agent-mesh-tools.d.ts +8 -0
- package/lib/mcp-server/agent-mesh-tools.d.ts.map +1 -0
- package/lib/mcp-server/agent-mesh-tools.js +138 -0
- package/lib/mcp-server/agent-mesh-tools.js.map +1 -0
- package/lib/media/deliver-subagent-result.d.ts +7 -0
- package/lib/media/deliver-subagent-result.d.ts.map +1 -1
- package/lib/media/deliver-subagent-result.js +3 -1
- package/lib/media/deliver-subagent-result.js.map +1 -1
- package/lib/media/media-normalize.d.ts +2 -0
- package/lib/media/media-normalize.d.ts.map +1 -1
- package/lib/media/media-normalize.js +89 -0
- package/lib/media/media-normalize.js.map +1 -1
- package/lib/media/subagent-user-delivery.d.ts +2 -9
- package/lib/media/subagent-user-delivery.d.ts.map +1 -1
- package/lib/media/subagent-user-delivery.js.map +1 -1
- package/lib/memory-entry-registry.d.ts +7 -0
- package/lib/memory-entry-registry.d.ts.map +1 -0
- package/lib/memory-entry-registry.js +8 -0
- package/lib/memory-entry-registry.js.map +1 -0
- package/lib/orchestration-memory-hook.d.ts +3 -0
- package/lib/orchestration-memory-hook.d.ts.map +1 -0
- package/lib/orchestration-memory-hook.js +22 -0
- package/lib/orchestration-memory-hook.js.map +1 -0
- package/lib/orchestration-runtime-registry.d.ts +14 -0
- package/lib/orchestration-runtime-registry.d.ts.map +1 -0
- package/lib/orchestration-runtime-registry.js +15 -0
- package/lib/orchestration-runtime-registry.js.map +1 -0
- package/lib/orchestrator/agent-dispatcher.d.ts +36 -3
- package/lib/orchestrator/agent-dispatcher.d.ts.map +1 -1
- package/lib/orchestrator/agent-dispatcher.js +203 -13
- package/lib/orchestrator/agent-dispatcher.js.map +1 -1
- package/lib/orchestrator/delegation-processor.d.ts +33 -0
- package/lib/orchestrator/delegation-processor.d.ts.map +1 -0
- package/lib/orchestrator/delegation-processor.js +140 -0
- package/lib/orchestrator/delegation-processor.js.map +1 -0
- package/lib/orchestrator/mission-milestone-notify.d.ts +17 -0
- package/lib/orchestrator/mission-milestone-notify.d.ts.map +1 -0
- package/lib/orchestrator/mission-milestone-notify.js +49 -0
- package/lib/orchestrator/mission-milestone-notify.js.map +1 -0
- package/lib/orchestrator/mission-negotiation.d.ts +17 -0
- package/lib/orchestrator/mission-negotiation.d.ts.map +1 -0
- package/lib/orchestrator/mission-negotiation.js +89 -0
- package/lib/orchestrator/mission-negotiation.js.map +1 -0
- package/lib/orchestrator/mission-patch-acl.d.ts +9 -0
- package/lib/orchestrator/mission-patch-acl.d.ts.map +1 -0
- package/lib/orchestrator/mission-patch-acl.js +29 -0
- package/lib/orchestrator/mission-patch-acl.js.map +1 -0
- package/lib/orchestrator/mission-runner.d.ts +24 -0
- package/lib/orchestrator/mission-runner.d.ts.map +1 -0
- package/lib/orchestrator/mission-runner.js +179 -0
- package/lib/orchestrator/mission-runner.js.map +1 -0
- package/lib/orchestrator/mission-spec.d.ts +44 -0
- package/lib/orchestrator/mission-spec.d.ts.map +1 -0
- package/lib/orchestrator/mission-spec.js +121 -0
- package/lib/orchestrator/mission-spec.js.map +1 -0
- package/lib/orchestrator/mission-state.d.ts +48 -0
- package/lib/orchestrator/mission-state.d.ts.map +1 -0
- package/lib/orchestrator/mission-state.js +66 -0
- package/lib/orchestrator/mission-state.js.map +1 -0
- package/lib/orchestrator/orchestration-repository.d.ts +85 -0
- package/lib/orchestrator/orchestration-repository.d.ts.map +1 -0
- package/lib/orchestrator/orchestration-repository.js +325 -0
- package/lib/orchestrator/orchestration-repository.js.map +1 -0
- package/lib/orchestrator/orchestration-service.d.ts +58 -0
- package/lib/orchestrator/orchestration-service.d.ts.map +1 -0
- package/lib/orchestrator/orchestration-service.js +221 -0
- package/lib/orchestrator/orchestration-service.js.map +1 -0
- package/lib/orchestrator/remote-agent-registry.d.ts +32 -0
- package/lib/orchestrator/remote-agent-registry.d.ts.map +1 -0
- package/lib/orchestrator/remote-agent-registry.js +120 -0
- package/lib/orchestrator/remote-agent-registry.js.map +1 -0
- package/lib/orchestrator/remote-task-executor.d.ts +10 -0
- package/lib/orchestrator/remote-task-executor.d.ts.map +1 -0
- package/lib/orchestrator/remote-task-executor.js +142 -0
- package/lib/orchestrator/remote-task-executor.js.map +1 -0
- package/lib/orchestrator/remote-task-poller.d.ts +16 -0
- package/lib/orchestrator/remote-task-poller.d.ts.map +1 -0
- package/lib/orchestrator/remote-task-poller.js +75 -0
- package/lib/orchestrator/remote-task-poller.js.map +1 -0
- package/lib/plugin-loop-hooks.d.ts +32 -0
- package/lib/plugin-loop-hooks.d.ts.map +1 -0
- package/lib/plugin-loop-hooks.js +69 -0
- package/lib/plugin-loop-hooks.js.map +1 -0
- package/lib/service.d.ts +38 -22
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +61 -19
- package/lib/service.js.map +1 -1
- package/lib/session-tree-runtime-registry.d.ts +20 -0
- package/lib/session-tree-runtime-registry.d.ts.map +1 -0
- package/lib/session-tree-runtime-registry.js +25 -0
- package/lib/session-tree-runtime-registry.js.map +1 -0
- package/lib/subagent-ai-events.d.ts +2 -2
- package/lib/subagent-ai-events.d.ts.map +1 -1
- package/lib/subagent-ai-events.js +17 -21
- package/lib/subagent-ai-events.js.map +1 -1
- package/lib/subagent-artifact.d.ts +7 -0
- package/lib/subagent-artifact.d.ts.map +1 -0
- package/lib/subagent-artifact.js +26 -0
- package/lib/subagent-artifact.js.map +1 -0
- package/lib/subagent-parent-context.d.ts +9 -0
- package/lib/subagent-parent-context.d.ts.map +1 -0
- package/lib/subagent-parent-context.js +50 -0
- package/lib/subagent-parent-context.js.map +1 -0
- package/lib/subagent-preset.d.ts +10 -0
- package/lib/subagent-preset.d.ts.map +1 -0
- package/lib/subagent-preset.js +44 -0
- package/lib/subagent-preset.js.map +1 -0
- package/lib/subagent-prompt.d.ts +7 -0
- package/lib/subagent-prompt.d.ts.map +1 -0
- package/lib/subagent-prompt.js +14 -0
- package/lib/subagent-prompt.js.map +1 -0
- package/lib/subagent.d.ts +19 -0
- package/lib/subagent.d.ts.map +1 -1
- package/lib/subagent.js +175 -92
- package/lib/subagent.js.map +1 -1
- package/lib/typing-indicator/adapter-integration.d.ts +7 -3
- package/lib/typing-indicator/adapter-integration.d.ts.map +1 -1
- package/lib/typing-indicator/adapter-integration.js +30 -6
- package/lib/typing-indicator/adapter-integration.js.map +1 -1
- package/lib/typing-indicator/index.d.ts +26 -3
- package/lib/typing-indicator/index.d.ts.map +1 -1
- package/lib/typing-indicator/index.js +94 -6
- package/lib/typing-indicator/index.js.map +1 -1
- package/lib/typing-indicator/integration.d.ts.map +1 -1
- package/lib/typing-indicator/integration.js +7 -2
- package/lib/typing-indicator/integration.js.map +1 -1
- package/lib/zhin-agent/agent-loop-standalone.d.ts +32 -0
- package/lib/zhin-agent/agent-loop-standalone.d.ts.map +1 -0
- package/lib/zhin-agent/agent-loop-standalone.js +144 -0
- package/lib/zhin-agent/agent-loop-standalone.js.map +1 -0
- package/lib/zhin-agent/agent-loop-turn.d.ts +52 -0
- package/lib/zhin-agent/agent-loop-turn.d.ts.map +1 -0
- package/lib/zhin-agent/agent-loop-turn.js +328 -0
- package/lib/zhin-agent/agent-loop-turn.js.map +1 -0
- package/lib/zhin-agent/branch-summarization-runtime.d.ts +16 -0
- package/lib/zhin-agent/branch-summarization-runtime.d.ts.map +1 -0
- package/lib/zhin-agent/branch-summarization-runtime.js +58 -0
- package/lib/zhin-agent/branch-summarization-runtime.js.map +1 -0
- package/lib/zhin-agent/builtin-tools.d.ts +3 -2
- package/lib/zhin-agent/builtin-tools.d.ts.map +1 -1
- package/lib/zhin-agent/builtin-tools.js +15 -16
- package/lib/zhin-agent/builtin-tools.js.map +1 -1
- package/lib/zhin-agent/compaction-runtime.d.ts +25 -0
- package/lib/zhin-agent/compaction-runtime.d.ts.map +1 -0
- package/lib/zhin-agent/compaction-runtime.js +78 -0
- package/lib/zhin-agent/compaction-runtime.js.map +1 -0
- package/lib/zhin-agent/config.d.ts +22 -2
- package/lib/zhin-agent/config.d.ts.map +1 -1
- package/lib/zhin-agent/config.js +25 -2
- package/lib/zhin-agent/config.js.map +1 -1
- package/lib/zhin-agent/deferred-auto-continue.d.ts +11 -0
- package/lib/zhin-agent/deferred-auto-continue.d.ts.map +1 -0
- package/lib/zhin-agent/deferred-auto-continue.js +41 -0
- package/lib/zhin-agent/deferred-auto-continue.js.map +1 -0
- package/lib/zhin-agent/deferred-delivery.d.ts +9 -0
- package/lib/zhin-agent/deferred-delivery.d.ts.map +1 -0
- package/lib/zhin-agent/deferred-delivery.js +35 -0
- package/lib/zhin-agent/deferred-delivery.js.map +1 -0
- package/lib/zhin-agent/index.d.ts +60 -11
- package/lib/zhin-agent/index.d.ts.map +1 -1
- package/lib/zhin-agent/index.js +264 -22
- package/lib/zhin-agent/index.js.map +1 -1
- package/lib/zhin-agent/model-resolver.d.ts +0 -1
- package/lib/zhin-agent/model-resolver.d.ts.map +1 -1
- package/lib/zhin-agent/model-resolver.js.map +1 -1
- package/lib/zhin-agent/multimodal-message.d.ts +9 -0
- package/lib/zhin-agent/multimodal-message.d.ts.map +1 -0
- package/lib/zhin-agent/multimodal-message.js +69 -0
- package/lib/zhin-agent/multimodal-message.js.map +1 -0
- package/lib/zhin-agent/persist-deferred-context.d.ts +5 -0
- package/lib/zhin-agent/persist-deferred-context.d.ts.map +1 -0
- package/lib/zhin-agent/persist-deferred-context.js +40 -0
- package/lib/zhin-agent/persist-deferred-context.js.map +1 -0
- package/lib/zhin-agent/prompt-access.d.ts +4 -0
- package/lib/zhin-agent/prompt-access.d.ts.map +1 -0
- package/lib/zhin-agent/prompt-access.js +7 -0
- package/lib/zhin-agent/prompt-access.js.map +1 -0
- package/lib/zhin-agent/prompt-builder.d.ts.map +1 -1
- package/lib/zhin-agent/prompt-builder.js +5 -0
- package/lib/zhin-agent/prompt-builder.js.map +1 -1
- package/lib/zhin-agent/prompt-controller.d.ts +53 -0
- package/lib/zhin-agent/prompt-controller.d.ts.map +1 -0
- package/lib/zhin-agent/prompt-controller.js +165 -0
- package/lib/zhin-agent/prompt-controller.js.map +1 -0
- package/lib/zhin-agent/prompt-input.d.ts +3 -0
- package/lib/zhin-agent/prompt-input.d.ts.map +1 -0
- package/lib/zhin-agent/prompt-input.js +8 -0
- package/lib/zhin-agent/prompt-input.js.map +1 -0
- package/lib/zhin-agent/prompt.d.ts.map +1 -1
- package/lib/zhin-agent/prompt.js +4 -0
- package/lib/zhin-agent/prompt.js.map +1 -1
- package/lib/zhin-agent/session-io.d.ts +28 -11
- package/lib/zhin-agent/session-io.d.ts.map +1 -1
- package/lib/zhin-agent/session-io.js +64 -28
- package/lib/zhin-agent/session-io.js.map +1 -1
- package/lib/zhin-agent/session-message-queue.d.ts +20 -0
- package/lib/zhin-agent/session-message-queue.d.ts.map +1 -0
- package/lib/zhin-agent/session-message-queue.js +52 -0
- package/lib/zhin-agent/session-message-queue.js.map +1 -0
- package/lib/zhin-agent/session-tree-commands.d.ts +5 -0
- package/lib/zhin-agent/session-tree-commands.d.ts.map +1 -0
- package/lib/zhin-agent/session-tree-commands.js +44 -0
- package/lib/zhin-agent/session-tree-commands.js.map +1 -0
- package/lib/zhin-agent/tool-calls-user-format.d.ts.map +1 -1
- package/lib/zhin-agent/tool-calls-user-format.js +3 -0
- package/lib/zhin-agent/tool-calls-user-format.js.map +1 -1
- package/lib/zhin-agent/tool-orchestration.d.ts.map +1 -1
- package/lib/zhin-agent/tool-orchestration.js +25 -6
- package/lib/zhin-agent/tool-orchestration.js.map +1 -1
- package/lib/zhin-agent/tool-runtime.d.ts +2 -2
- package/lib/zhin-agent/tool-runtime.d.ts.map +1 -1
- package/lib/zhin-agent/tool-runtime.js +4 -4
- package/lib/zhin-agent/tool-runtime.js.map +1 -1
- package/lib/zhin-agent/tool-search-orchestrator.d.ts.map +1 -1
- package/lib/zhin-agent/tool-search-orchestrator.js +13 -0
- package/lib/zhin-agent/tool-search-orchestrator.js.map +1 -1
- package/lib/zhin-agent/turn-context.d.ts +9 -0
- package/lib/zhin-agent/turn-context.d.ts.map +1 -0
- package/lib/zhin-agent/turn-context.js +12 -0
- package/lib/zhin-agent/turn-context.js.map +1 -0
- package/lib/zhin-agent/turn-pipeline.d.ts +7 -1
- package/lib/zhin-agent/turn-pipeline.d.ts.map +1 -1
- package/lib/zhin-agent/turn-pipeline.js +136 -450
- package/lib/zhin-agent/turn-pipeline.js.map +1 -1
- package/lib/zhin-agent/turn-user-message.d.ts +8 -0
- package/lib/zhin-agent/turn-user-message.d.ts.map +1 -0
- package/lib/zhin-agent/turn-user-message.js +10 -0
- package/lib/zhin-agent/turn-user-message.js.map +1 -0
- package/lib/zhin-agent/zhin-agent-private.d.ts +17 -4
- package/lib/zhin-agent/zhin-agent-private.d.ts.map +1 -1
- package/lib/zhin-agent/zhin-agent-private.js.map +1 -1
- package/package.json +4 -3
- package/lib/zhin-agent/llm-runner.d.ts +0 -18
- package/lib/zhin-agent/llm-runner.d.ts.map +0 -1
- package/lib/zhin-agent/llm-runner.js +0 -163
- package/lib/zhin-agent/llm-runner.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,19 +6,20 @@ Zhin AI Agent 组合层:在 `@zhin.js/core` 的类型与 Provider 之上,提
|
|
|
6
6
|
|
|
7
7
|
## 功能特性
|
|
8
8
|
|
|
9
|
-
- 🤖 **
|
|
9
|
+
- 🤖 **agentLoop 统一路径**:ZhinAgent、Subagent、Deferred Worker、AIService 均经 `agentLoop`(legacy `Agent.run` 仅保留在 `@zhin.js/ai` 供单测)
|
|
10
10
|
- 📝 **会话管理**:`SessionManager`、内存/数据库会话、`SessionManager.generateId`
|
|
11
11
|
- 🧠 **ZhinAgent**:与 Zhin 消息流集成的智能体(SOUL/TOOLS/AGENTS、工具收集、执行策略)
|
|
12
|
-
- 🔍
|
|
13
|
-
- 🔄
|
|
12
|
+
- 🔍 **模型自动发现**:`ModelRegistry` 调用 `listModels()`(OpenAI 兼容 `/v1/models`、Ollama `/api/tags`);结果写入 `provider.models` 并供 `getModel()` 校验;yaml 显式 `models` 时以配置为准
|
|
13
|
+
- 🔄 **模型自动降级**:首选模型失败时按 `resolveModelCandidates` 候选链 fallback(文本 / 多模态 / standalone 均走 agentLoop)
|
|
14
14
|
- 🛡️ **6 层 Bash 安全**:`ExecPolicy` 纵深防御(危险黑名单、环境变量剥离、wrapper 剥离、复合命令拆分、只读放行、交互式审批)
|
|
15
15
|
- 📂 **文件访问安全**:`FilePolicy` 路径检查、设备路径拦截、命令读写分类
|
|
16
16
|
- 📋 **精简系统提示词**:`PromptBuilder` 组装 Context、Style、Tools、Safety,并按需注入 Platform、Skills、Memory、Bootstrap
|
|
17
17
|
- 🔌 **框架挂载**:`initAgentModule()` 注册 `ctx.ai`、`ctx.agent`、定时任务、DB 模型等
|
|
18
|
-
- 📦 **上下文与记忆**:`ContextManager`、`ConversationMemory`、`UserProfileStore`
|
|
18
|
+
- 📦 **上下文与记忆**:`ContextRepository`(`agent_messages`)、`AgentSessionStore`、`ImTranscriptStore`(`im_transcripts` + `chat_history`);辅助:`ContextManager`、`ConversationMemory`、`UserProfileStore`
|
|
19
19
|
- ⏰ **跟进与定时**:`FollowUpManager`、`PersistentCronEngine`、cron 工具
|
|
20
|
-
- 🔧 **内置工具**:bash、read_file、write_file、ask_user、web_search
|
|
21
|
-
- 📐
|
|
20
|
+
- 🔧 **内置工具**:bash、read_file、write_file、ask_user、web_search、`chat_history`(按关键词/最近条数查 `im_transcripts`)等
|
|
21
|
+
- 📐 **Compaction(ADR 0010)**:生产 `agentLoop` 接线 L1 micro + L2 LLM;IM `/compact`;yaml `ai.agent.compaction`
|
|
22
|
+
- 🌳 **会话树**:`parent_id` + `active_leaf`;IM `/tree`、`/reset`;branch summarization;Console `GET/POST /api/agent/sessions/...`
|
|
22
23
|
- 🪝 **Hook 系统**:`registerAIHook`、`triggerAIHook` 等
|
|
23
24
|
|
|
24
25
|
## 依赖关系
|
|
@@ -44,8 +45,6 @@ npm install zhin.js
|
|
|
44
45
|
import {
|
|
45
46
|
initAgentModule,
|
|
46
47
|
ZhinAgent,
|
|
47
|
-
Agent,
|
|
48
|
-
createAgent,
|
|
49
48
|
AIService,
|
|
50
49
|
SessionManager,
|
|
51
50
|
registerAIHook,
|
|
@@ -64,16 +63,19 @@ useContext('ai', async (ai) => {
|
|
|
64
63
|
仅在需要单独集成 Agent 能力时使用:
|
|
65
64
|
|
|
66
65
|
```javascript
|
|
67
|
-
import { initAgentModule,
|
|
66
|
+
import { initAgentModule, AIService } from '@zhin.js/agent'
|
|
68
67
|
import { OllamaProvider } from '@zhin.js/core'
|
|
69
68
|
|
|
70
|
-
// 初始化(需先有 DatabaseFeature 等)
|
|
71
69
|
initAgentModule()
|
|
72
70
|
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
71
|
+
// 程序化 Agent(agentLoop 隔离 context)
|
|
72
|
+
useContext('ai', async (ai) => {
|
|
73
|
+
const result = await ai.runAgent('你好', {
|
|
74
|
+
provider: 'ollama',
|
|
75
|
+
systemPrompt: '你是一个助手',
|
|
76
|
+
})
|
|
77
|
+
console.log(result.content)
|
|
78
|
+
})
|
|
77
79
|
```
|
|
78
80
|
|
|
79
81
|
## 核心导出
|
|
@@ -81,13 +83,13 @@ const result = await agent.run('你好')
|
|
|
81
83
|
| 类别 | 导出 |
|
|
82
84
|
|------|------|
|
|
83
85
|
| 初始化 | `initAgentModule` |
|
|
84
|
-
| Agent | `Agent
|
|
86
|
+
| Agent | `ServiceAgent`、`CreateServiceAgentOptions`(`AIService.createAgent`);legacy `Agent` / `createAgent` re-export 自 `@zhin.js/ai` |
|
|
85
87
|
| Model harness | `MODEL_HARNESS_DEFAULTS`, `resolveModelHarness`, `mergeModelHarnessValues` |
|
|
86
88
|
| 服务与会话 | `AIService`, `SessionManager`, `MemorySessionManager`, `DatabaseSessionManager`, `createMemorySessionManager`, `createDatabaseSessionManager` |
|
|
87
89
|
| ZhinAgent | `ZhinAgent`,以及 config / exec-policy / file-policy / tool-runtime / prompt / builtin-tools 等子模块 |
|
|
88
90
|
| 安全策略 | `checkExecPolicy`, `applyExecPolicyToTools`, `isDangerousCommand`, `stripEnvVarPrefix`, `stripSafeWrappers`, `splitCompoundCommand`, `extractCommandName`, `ExecPolicyResult`, `checkFileAccess`, `classifyBashCommand`, `isBlockedDevicePath` |
|
|
89
91
|
| 提示词构建 | `buildRichSystemPrompt`, `buildEnhancedPersona`, `buildUserMessageWithHistory`, `buildContextHint` |
|
|
90
|
-
| 上下文与记忆 | `
|
|
92
|
+
| 上下文与记忆 | `ContextRepository`, `AgentSessionStore`, `ImTranscriptStore`(经 ZhinAgent 注入);`ContextManager`, `ConversationMemory`, `UserProfileStore` |
|
|
91
93
|
| 跟进与定时 | `FollowUpManager`, `PersistentCronEngine`, `createCronTools`, `setCronManager`, `getCronManager` |
|
|
92
94
|
| 压缩与 Bootstrap | `compactSession`, `estimateTokens`, `loadBootstrapFiles`, `loadSoulPersona`, `loadToolsGuide`, `loadAgentsMemory` |
|
|
93
95
|
| Hook | `registerAIHook`, `unregisterAIHook`, `triggerAIHook`, `createAIHookEvent` |
|
|
@@ -118,7 +120,7 @@ declare module '@zhin.js/core' {
|
|
|
118
120
|
|
|
119
121
|
| Context | 用途 |
|
|
120
122
|
|---------|------|
|
|
121
|
-
| `ctx.ai` | 业务侧 AI 服务:会话、`createAgent`
|
|
123
|
+
| `ctx.ai` | 业务侧 AI 服务:会话、`createAgent`(→ `ServiceAgent`)/ `runAgent`、全局 ZhinAgent |
|
|
122
124
|
| `ctx.agent` | 扩展编排资源:`orchestrator.addTool`、`addSkill`、`addMcp` 等;内置注册走 `root.inject('agent')` |
|
|
123
125
|
|
|
124
126
|
主包 `zhin.js` 的 `Plugin.Contexts` 类型已包含上述两项。
|
|
@@ -127,7 +129,7 @@ declare module '@zhin.js/core' {
|
|
|
127
129
|
|
|
128
130
|
默认**不**注册 `@modelcontextprotocol/server-memory`;设 `ai.memoryMcp: true` 启用(`data/knowledge-graph.jsonl`)。另可通过 `ai.mcpServers`(或 `ctx.agent.addMcp`)注册更多 Server;每次 AI 回合前懒连接,`mcp_{server}_{tool}` 并入 ZhinAgent 工具池。需可选安装 `@modelcontextprotocol/sdk`(peer dependency)。
|
|
129
131
|
|
|
130
|
-
|
|
132
|
+
**记忆**:默认 **文件三层**(`ai.memory` → `data/memory/`);内置 `read_memory` / `write_memory` 已移除。`ai.memoryMcp: true` 时另注册 MCP 图谱(弃用路径)。工作区 `AGENTS.md` / `TOOLS.md` 由 bootstrap 注入。
|
|
131
133
|
|
|
132
134
|
```yaml
|
|
133
135
|
ai:
|
|
@@ -155,23 +157,20 @@ ai:
|
|
|
155
157
|
|
|
156
158
|
### 2. 用 AIService 创建多个不同配置的 Agent
|
|
157
159
|
|
|
158
|
-
`ctx.ai`(AIService)可以按需创建**多个互不共享状态的 Agent
|
|
160
|
+
`ctx.ai`(AIService)可以按需创建**多个互不共享状态的 Agent**(`ServiceAgent`),每个可指定不同 provider、model、systemPrompt、tools;底层均为 **`runAgentLoopStandaloneTurn`**:
|
|
159
161
|
|
|
160
162
|
```javascript
|
|
161
163
|
import { useContext } from 'zhin.js'
|
|
162
164
|
|
|
163
165
|
useContext('ai', async (ai) => {
|
|
164
|
-
// 专用「代码助手」Agent
|
|
165
166
|
const codeAgent = ai.createAgent({
|
|
166
167
|
provider: 'openai',
|
|
167
168
|
model: 'gpt-4o',
|
|
168
169
|
systemPrompt: '你只负责代码审查与建议,不闲聊。',
|
|
169
170
|
useBuiltinTools: true,
|
|
170
|
-
tools: [/* 可选:额外工具 */],
|
|
171
171
|
})
|
|
172
172
|
const codeResult = await codeAgent.run('审查这段 TypeScript 的类型安全')
|
|
173
173
|
|
|
174
|
-
// 专用「翻译」Agent,不用内置工具
|
|
175
174
|
const translateAgent = ai.createAgent({
|
|
176
175
|
provider: 'ollama',
|
|
177
176
|
model: 'qwen2.5',
|
|
@@ -201,7 +200,7 @@ useContext('ai', async (ai) => {
|
|
|
201
200
|
|
|
202
201
|
### 4. 多 Agent 协作/编排(由 zhin.js 层实现)
|
|
203
202
|
|
|
204
|
-
本包只提供基础能力:`
|
|
203
|
+
本包只提供基础能力:`ZhinAgent`、`ai.createAgent`(`ServiceAgent`)、`ai.runAgent` 等。**多 Agent 串联/并联编排**(例如 A 的输出作为 B 的输入、按条件路由到不同专业 Agent)在 **zhin.js 主包** `runPipeline` / `runParallel` / `route` 实现;插件侧通过 zhin.js 暴露的 API 使用即可。
|
|
205
204
|
|
|
206
205
|
## 工具命名策略
|
|
207
206
|
|
|
@@ -209,6 +208,60 @@ useContext('ai', async (ai) => {
|
|
|
209
208
|
- 非保留工具同名时采用 **后注册覆盖前注册**。
|
|
210
209
|
- 冲突统一以 warn 记录:包含 `name`、`source`、`action`(`ignored`/`overridden`)。
|
|
211
210
|
|
|
211
|
+
## Provider 与模型列表
|
|
212
|
+
|
|
213
|
+
`AIService` 构造时:
|
|
214
|
+
|
|
215
|
+
1. 按 `ai.providers.<别名>` 实例化 Provider(须配置 `api`,如 `openai-completions`)。
|
|
216
|
+
2. `registerLlmApiFromProviders`:**未写 `models` 的 provider** 在 ApiRegistry 注册为空白名单,由后台 `ModelRegistry.discover()` 填充 `provider.models`;**写了 `models`** 则用 yaml 白名单。
|
|
217
|
+
3. `createZhinAgent` 启动时 `loadCache()` 先恢复上次发现结果,再异步刷新 `/v1/models`。
|
|
218
|
+
|
|
219
|
+
`agents.<name>.model`(如 `mimo-v2.5-pro`)须在发现列表中,或在中转 API 的 `/v1/models` 响应里出现;无需为每个模型手写 yaml,除非要锁定白名单。
|
|
220
|
+
|
|
221
|
+
```yaml
|
|
222
|
+
ai:
|
|
223
|
+
providers:
|
|
224
|
+
openai-main:
|
|
225
|
+
api: openai-completions
|
|
226
|
+
baseUrl: ${OPENAI_BASE_URL}
|
|
227
|
+
apiKey: ${OPENAI_API_KEY}
|
|
228
|
+
# models 省略 → 自动 GET /v1/models
|
|
229
|
+
cloudflare-flash:
|
|
230
|
+
api: cloudflare-workers-ai
|
|
231
|
+
models: ["@cf/zai-org/glm-4.7-flash"] # 显式列表
|
|
232
|
+
agents:
|
|
233
|
+
zhin:
|
|
234
|
+
provider: openai-main
|
|
235
|
+
model: mimo-v2.5-pro
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Provider 与模型列表
|
|
239
|
+
|
|
240
|
+
`AIService` 构造时:
|
|
241
|
+
|
|
242
|
+
1. 按 `ai.providers.<别名>` 实例化 Provider(须配置 `api`,如 `openai-completions`)。
|
|
243
|
+
2. `registerLlmApiFromProviders`:**未写 `models` 的 provider** 在 ApiRegistry 注册为空白名单,由后台 `ModelRegistry.discover()` 填充 `provider.models`;**写了 `models`** 则用 yaml 白名单。
|
|
244
|
+
3. `createZhinAgent` 启动时 `loadCache()` 先恢复上次发现结果,再异步刷新 `/v1/models`。
|
|
245
|
+
|
|
246
|
+
`agents.<name>.model`(如 `mimo-v2.5-pro`)须在发现列表中,或在中转 API 的 `/v1/models` 响应里出现;无需为每个模型手写 yaml,除非要锁定白名单。
|
|
247
|
+
|
|
248
|
+
```yaml
|
|
249
|
+
ai:
|
|
250
|
+
providers:
|
|
251
|
+
openai-main:
|
|
252
|
+
api: openai-completions
|
|
253
|
+
baseUrl: ${OPENAI_BASE_URL}
|
|
254
|
+
apiKey: ${OPENAI_API_KEY}
|
|
255
|
+
# models 省略 → 自动 GET /v1/models
|
|
256
|
+
cloudflare-flash:
|
|
257
|
+
api: cloudflare-workers-ai
|
|
258
|
+
models: ["@cf/zai-org/glm-4.7-flash"] # 显式列表
|
|
259
|
+
agents:
|
|
260
|
+
zhin:
|
|
261
|
+
provider: openai-main
|
|
262
|
+
model: mimo-v2.5-pro
|
|
263
|
+
```
|
|
264
|
+
|
|
212
265
|
## Model harness
|
|
213
266
|
|
|
214
267
|
按 provider / model 覆盖 Agent 循环默认参数(当前主要为 **`maxIterations`**)。
|
|
@@ -237,6 +290,18 @@ ai:
|
|
|
237
290
|
|
|
238
291
|
增补内置默认值:在 `model-harness.ts` 增加 `ModelHarnessRow` 并附测试;YAML 只做覆盖,不替代 TS 约定层。
|
|
239
292
|
|
|
293
|
+
## IM 管理命令
|
|
294
|
+
|
|
295
|
+
由 `register-management-tools.ts` / `register-introspection-commands.ts` 注册(master / 有权限用户):
|
|
296
|
+
|
|
297
|
+
| 类别 | 命令 |
|
|
298
|
+
|------|------|
|
|
299
|
+
| 会话 | `/compact` · `/tree` · `/tree N` · `/reset` |
|
|
300
|
+
| 运维 | `/models` · `/health` |
|
|
301
|
+
| 内省 | `/cmd` · `/bots` · `/bindings` · `/tools` · `/mcp` |
|
|
302
|
+
|
|
303
|
+
zhin-package CLI:`zhin packages`(`basic/cli`)。详见 [ADR 0010](../../docs/adr/0010-pi-coding-agent-harness-alignment.md)。
|
|
304
|
+
|
|
240
305
|
## 开发
|
|
241
306
|
|
|
242
307
|
### 项目结构
|
|
@@ -267,7 +332,7 @@ src/
|
|
|
267
332
|
│ ├── config.ts
|
|
268
333
|
│ ├── prompt.ts
|
|
269
334
|
│ ├── tool-runtime.ts # 运行时工具收集与执行路径规划
|
|
270
|
-
│ └──
|
|
335
|
+
│ └── builtin-tools.ts # chat_history(im_transcripts), user_profile, spawn_task
|
|
271
336
|
│
|
|
272
337
|
├── discovery/ # ★ 文件化资源发现
|
|
273
338
|
│ ├── index.ts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-search-tool.d.ts","sourceRoot":"","sources":["../../src/builtin/memory-search-tool.ts"],"names":[],"mappings":"AAoEA,wBAAgB,sBAAsB,sDAErC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolveIMSessionIdFromToolContext } from '@zhin.js/ai';
|
|
2
|
+
import { parseMemoryTags } from '@zhin.js/ai';
|
|
3
|
+
import { BuiltinBaseTool } from './builtin-base-tool.js';
|
|
4
|
+
import { getMemoryEntryRepository } from '../memory-entry-registry.js';
|
|
5
|
+
const PARAMS = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
query: { type: 'string', description: '检索关键词或短语' },
|
|
9
|
+
scope: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
enum: ['global', 'platform', 'session', 'user'],
|
|
12
|
+
description: '可选:限定记忆范围',
|
|
13
|
+
},
|
|
14
|
+
limit: { type: 'number', description: '最多返回条数(默认 5)' },
|
|
15
|
+
},
|
|
16
|
+
required: ['query'],
|
|
17
|
+
};
|
|
18
|
+
function sessionScopeKey(ctx) {
|
|
19
|
+
return resolveIMSessionIdFromToolContext({
|
|
20
|
+
platform: ctx.platform || '',
|
|
21
|
+
botId: ctx.botId || '',
|
|
22
|
+
scope: ctx.scope,
|
|
23
|
+
sceneId: ctx.sceneId || '',
|
|
24
|
+
senderId: ctx.senderId || '',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
class MemorySearchTool extends BuiltinBaseTool {
|
|
28
|
+
name = 'memory_search';
|
|
29
|
+
description = '在语义记忆库中检索与 query 相关的事实条目(memory_entries)。';
|
|
30
|
+
parameters = PARAMS;
|
|
31
|
+
keywords = ['memory', 'recall', 'remember', '记忆', '回忆'];
|
|
32
|
+
async run(args, context) {
|
|
33
|
+
const repo = getMemoryEntryRepository();
|
|
34
|
+
if (!repo)
|
|
35
|
+
return '语义记忆未启用(ai.memory.semantic.enabled)或未初始化数据库。';
|
|
36
|
+
const query = String(args.query ?? '').trim();
|
|
37
|
+
if (!query)
|
|
38
|
+
return '请提供 query';
|
|
39
|
+
const scope = typeof args.scope === 'string' ? args.scope : undefined;
|
|
40
|
+
const limit = typeof args.limit === 'number' ? args.limit : 5;
|
|
41
|
+
const scopeKey = scope === 'session' && context ? sessionScopeKey(context) : undefined;
|
|
42
|
+
const hits = await repo.search({
|
|
43
|
+
query,
|
|
44
|
+
scope: scope,
|
|
45
|
+
scope_key: scopeKey,
|
|
46
|
+
limit,
|
|
47
|
+
});
|
|
48
|
+
if (!hits.length)
|
|
49
|
+
return `未找到与 "${query}" 相关的记忆条目。`;
|
|
50
|
+
const lines = hits.map((e) => {
|
|
51
|
+
const tags = parseMemoryTags(e.tags);
|
|
52
|
+
return `- [${e.scope}${e.scope_key ? `:${e.scope_key}` : ''}] ${e.key}=${e.content}`
|
|
53
|
+
+ (tags.length ? ` (tags: ${tags.join(', ')})` : '');
|
|
54
|
+
});
|
|
55
|
+
return `找到 ${hits.length} 条记忆:\n${lines.join('\n')}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function createMemorySearchTool() {
|
|
59
|
+
return new MemorySearchTool().toTool();
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=memory-search-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-search-tool.js","sourceRoot":"","sources":["../../src/builtin/memory-search-tool.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,MAAM,MAAM,GAAyB;IACnC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV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AC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-upsert-tool.d.ts","sourceRoot":"","sources":["../../src/builtin/memory-upsert-tool.ts"],"names":[],"mappings":"AAkFA,wBAAgB,sBAAsB,sDAErC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { resolveIMSessionIdFromToolContext } from '@zhin.js/ai';
|
|
2
|
+
import { BuiltinBaseTool } from './builtin-base-tool.js';
|
|
3
|
+
import { getMemoryEntryRepository } from '../memory-entry-registry.js';
|
|
4
|
+
const PARAMS = {
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
key: { type: 'string', description: '记忆键(如 capability:hard_orchestration_v1)' },
|
|
8
|
+
content: { type: 'string', description: '记忆内容(简短事实陈述)' },
|
|
9
|
+
scope: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
enum: ['global', 'platform', 'session', 'user'],
|
|
12
|
+
description: '范围,默认 global',
|
|
13
|
+
},
|
|
14
|
+
tags: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: { type: 'string' },
|
|
17
|
+
description: '可选标签',
|
|
18
|
+
},
|
|
19
|
+
source: { type: 'string', description: '来源说明(如 skill:memory-consolidate)' },
|
|
20
|
+
confidence: { type: 'number', description: '置信度 0–1,默认 1' },
|
|
21
|
+
},
|
|
22
|
+
required: ['key', 'content'],
|
|
23
|
+
};
|
|
24
|
+
function sessionScopeKey(ctx) {
|
|
25
|
+
return resolveIMSessionIdFromToolContext({
|
|
26
|
+
platform: ctx.platform || '',
|
|
27
|
+
botId: ctx.botId || '',
|
|
28
|
+
scope: ctx.scope,
|
|
29
|
+
sceneId: ctx.sceneId || '',
|
|
30
|
+
senderId: ctx.senderId || '',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
class MemoryUpsertTool extends BuiltinBaseTool {
|
|
34
|
+
name = 'memory_upsert';
|
|
35
|
+
description = '写入或更新一条语义记忆(memory_entries),供 memory_search 召回。';
|
|
36
|
+
parameters = PARAMS;
|
|
37
|
+
keywords = ['memory', 'remember', 'store', '记忆', '记住'];
|
|
38
|
+
async run(args, context) {
|
|
39
|
+
const repo = getMemoryEntryRepository();
|
|
40
|
+
if (!repo)
|
|
41
|
+
return '语义记忆未启用(ai.memory.semantic.enabled)或未初始化数据库。';
|
|
42
|
+
const key = String(args.key ?? '').trim();
|
|
43
|
+
const content = String(args.content ?? '').trim();
|
|
44
|
+
if (!key || !content)
|
|
45
|
+
return '请提供 key 与 content';
|
|
46
|
+
const scope = (typeof args.scope === 'string' ? args.scope : 'global');
|
|
47
|
+
let scopeKey = '';
|
|
48
|
+
if (scope === 'session' && context) {
|
|
49
|
+
scopeKey = sessionScopeKey(context);
|
|
50
|
+
}
|
|
51
|
+
else if (scope === 'platform' && context?.platform) {
|
|
52
|
+
scopeKey = context.platform;
|
|
53
|
+
}
|
|
54
|
+
else if (scope === 'user' && context?.senderId) {
|
|
55
|
+
scopeKey = context.senderId;
|
|
56
|
+
}
|
|
57
|
+
const tags = Array.isArray(args.tags) ? args.tags.map(String) : undefined;
|
|
58
|
+
const source = typeof args.source === 'string' ? args.source : 'tool:memory_upsert';
|
|
59
|
+
const confidence = typeof args.confidence === 'number' ? args.confidence : 1;
|
|
60
|
+
const record = await repo.upsert({
|
|
61
|
+
scope,
|
|
62
|
+
scope_key: scopeKey,
|
|
63
|
+
key,
|
|
64
|
+
content,
|
|
65
|
+
tags,
|
|
66
|
+
source,
|
|
67
|
+
confidence,
|
|
68
|
+
});
|
|
69
|
+
return `已写入记忆 ${record.id}: [${record.scope}] ${record.key}=${record.content}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createMemoryUpsertTool() {
|
|
73
|
+
return new MemoryUpsertTool().toTool();
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=memory-upsert-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-upsert-tool.js","sourceRoot":"","sources":["../../src/builtin/mem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AC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1E,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC;QACpF,MAAM,UAAU,GAAG,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAE7E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;YAC/B,KAAK;YACL,SAAS,EAAE,QAAQ;YACnB,GAAG;YACH,OAAO;YACP,IAAI;YACJ,MAAM;YACN,UAAU;SACX,CAAC,CAAC;QAEH,OAAO,SAAS,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACjF,CAAC;CACF;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,gBAAgB,EAAE,CAAC,MAAM,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project director orchestration tools — Agent Mesh hard orchestration v1.
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentTool, ToolContext } from '@zhin.js/core';
|
|
5
|
+
export declare function createOrchestrationTools(context: ToolContext): AgentTool[];
|
|
6
|
+
export declare const ORCHESTRATION_TOOL_NAMES: readonly ["orchestration_start", "orchestration_add_task", "orchestration_status", "orchestration_complete", "orchestration_retry_task", "orchestration_skip_task", "orchestration_patch_state"];
|
|
7
|
+
//# sourceMappingURL=orchestration-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestration-tools.d.ts","sourceRoot":"","sources":["../../src/builtin/orchestration-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAoC,MAAM,eAAe,CAAC;AAyR9F,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,CAU1E;AAED,eAAO,MAAM,wBAAwB,kMAQ3B,CAAC"}
|