dsh-tavern-bundle 0.1.0
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/LICENSE +21 -0
- package/README.md +216 -0
- package/cordis.patch.yml +14 -0
- package/lib/adapters/model-gateway.d.ts +4 -0
- package/lib/adapters/model-gateway.d.ts.map +1 -0
- package/lib/adapters/model-gateway.js +3 -0
- package/lib/adapters/model-gateway.js.map +1 -0
- package/lib/adapters/prestep-spike.d.ts +16 -0
- package/lib/adapters/prestep-spike.d.ts.map +1 -0
- package/lib/adapters/prestep-spike.js +114 -0
- package/lib/adapters/prestep-spike.js.map +1 -0
- package/lib/adapters/runtime-probe.d.ts +67 -0
- package/lib/adapters/runtime-probe.d.ts.map +1 -0
- package/lib/adapters/runtime-probe.js +106 -0
- package/lib/adapters/runtime-probe.js.map +1 -0
- package/lib/adapters/session-agent-provider.d.ts +3 -0
- package/lib/adapters/session-agent-provider.d.ts.map +1 -0
- package/lib/adapters/session-agent-provider.js +3 -0
- package/lib/adapters/session-agent-provider.js.map +1 -0
- package/lib/adapters/subagent-gateway.d.ts +3 -0
- package/lib/adapters/subagent-gateway.d.ts.map +1 -0
- package/lib/adapters/subagent-gateway.js +3 -0
- package/lib/adapters/subagent-gateway.js.map +1 -0
- package/lib/application/chat/chat-application-service.d.ts +94 -0
- package/lib/application/chat/chat-application-service.d.ts.map +1 -0
- package/lib/application/chat/chat-application-service.js +291 -0
- package/lib/application/chat/chat-application-service.js.map +1 -0
- package/lib/application/companion/agent-orchestrator.d.ts +91 -0
- package/lib/application/companion/agent-orchestrator.d.ts.map +1 -0
- package/lib/application/companion/agent-orchestrator.js +298 -0
- package/lib/application/companion/agent-orchestrator.js.map +1 -0
- package/lib/application/companion/companion-child-service.d.ts +47 -0
- package/lib/application/companion/companion-child-service.d.ts.map +1 -0
- package/lib/application/companion/companion-child-service.js +30 -0
- package/lib/application/companion/companion-child-service.js.map +1 -0
- package/lib/application/companion/companion-invocation-service.d.ts +42 -0
- package/lib/application/companion/companion-invocation-service.d.ts.map +1 -0
- package/lib/application/companion/companion-invocation-service.js +50 -0
- package/lib/application/companion/companion-invocation-service.js.map +1 -0
- package/lib/application/companion/companion-profile-service.d.ts +32 -0
- package/lib/application/companion/companion-profile-service.d.ts.map +1 -0
- package/lib/application/companion/companion-profile-service.js +112 -0
- package/lib/application/companion/companion-profile-service.js.map +1 -0
- package/lib/application/companion/companion-promotion-service.d.ts +69 -0
- package/lib/application/companion/companion-promotion-service.d.ts.map +1 -0
- package/lib/application/companion/companion-promotion-service.js +129 -0
- package/lib/application/companion/companion-promotion-service.js.map +1 -0
- package/lib/application/group-chat/group-chat-execution-service.d.ts +22 -0
- package/lib/application/group-chat/group-chat-execution-service.d.ts.map +1 -0
- package/lib/application/group-chat/group-chat-execution-service.js +110 -0
- package/lib/application/group-chat/group-chat-execution-service.js.map +1 -0
- package/lib/application/group-chat/group-chat-orchestrator.d.ts +51 -0
- package/lib/application/group-chat/group-chat-orchestrator.d.ts.map +1 -0
- package/lib/application/group-chat/group-chat-orchestrator.js +57 -0
- package/lib/application/group-chat/group-chat-orchestrator.js.map +1 -0
- package/lib/application/memory/memory-retriever.d.ts +37 -0
- package/lib/application/memory/memory-retriever.d.ts.map +1 -0
- package/lib/application/memory/memory-retriever.js +91 -0
- package/lib/application/memory/memory-retriever.js.map +1 -0
- package/lib/application/memory/memory-service.d.ts +128 -0
- package/lib/application/memory/memory-service.d.ts.map +1 -0
- package/lib/application/memory/memory-service.js +346 -0
- package/lib/application/memory/memory-service.js.map +1 -0
- package/lib/application/ports/companion-runtime-port.d.ts +72 -0
- package/lib/application/ports/companion-runtime-port.d.ts.map +1 -0
- package/lib/application/ports/companion-runtime-port.js +2 -0
- package/lib/application/ports/companion-runtime-port.js.map +1 -0
- package/lib/application/ports/llm-port.d.ts +7 -0
- package/lib/application/ports/llm-port.d.ts.map +1 -0
- package/lib/application/ports/llm-port.js +2 -0
- package/lib/application/ports/llm-port.js.map +1 -0
- package/lib/application/ports/message-source.d.ts +4 -0
- package/lib/application/ports/message-source.d.ts.map +1 -0
- package/lib/application/ports/message-source.js +5 -0
- package/lib/application/ports/message-source.js.map +1 -0
- package/lib/application/ports/session-context-port.d.ts +13 -0
- package/lib/application/ports/session-context-port.d.ts.map +1 -0
- package/lib/application/ports/session-context-port.js +2 -0
- package/lib/application/ports/session-context-port.js.map +1 -0
- package/lib/application/ports/subagent-port.d.ts +31 -0
- package/lib/application/ports/subagent-port.d.ts.map +1 -0
- package/lib/application/ports/subagent-port.js +2 -0
- package/lib/application/ports/subagent-port.js.map +1 -0
- package/lib/application/ports/user-resolver-port.d.ts +5 -0
- package/lib/application/ports/user-resolver-port.d.ts.map +1 -0
- package/lib/application/ports/user-resolver-port.js +2 -0
- package/lib/application/ports/user-resolver-port.js.map +1 -0
- package/lib/application/relationship/relationship-event-service.d.ts +31 -0
- package/lib/application/relationship/relationship-event-service.d.ts.map +1 -0
- package/lib/application/relationship/relationship-event-service.js +43 -0
- package/lib/application/relationship/relationship-event-service.js.map +1 -0
- package/lib/application/relationship/relationship-policy.d.ts +20 -0
- package/lib/application/relationship/relationship-policy.d.ts.map +1 -0
- package/lib/application/relationship/relationship-policy.js +24 -0
- package/lib/application/relationship/relationship-policy.js.map +1 -0
- package/lib/application/relationship/relationship-projection.d.ts +14 -0
- package/lib/application/relationship/relationship-projection.d.ts.map +1 -0
- package/lib/application/relationship/relationship-projection.js +25 -0
- package/lib/application/relationship/relationship-projection.js.map +1 -0
- package/lib/application/relationship/relationship-service.d.ts +95 -0
- package/lib/application/relationship/relationship-service.d.ts.map +1 -0
- package/lib/application/relationship/relationship-service.js +254 -0
- package/lib/application/relationship/relationship-service.js.map +1 -0
- package/lib/application/workspace/workspace-service.d.ts +106 -0
- package/lib/application/workspace/workspace-service.d.ts.map +1 -0
- package/lib/application/workspace/workspace-service.js +44 -0
- package/lib/application/workspace/workspace-service.js.map +1 -0
- package/lib/bootstrap/create-domain.d.ts +5 -0
- package/lib/bootstrap/create-domain.d.ts.map +1 -0
- package/lib/bootstrap/create-domain.js +14 -0
- package/lib/bootstrap/create-domain.js.map +1 -0
- package/lib/bootstrap/create-repositories.d.ts +403 -0
- package/lib/bootstrap/create-repositories.d.ts.map +1 -0
- package/lib/bootstrap/create-repositories.js +39 -0
- package/lib/bootstrap/create-repositories.js.map +1 -0
- package/lib/bootstrap/create-runtime.d.ts +8 -0
- package/lib/bootstrap/create-runtime.d.ts.map +1 -0
- package/lib/bootstrap/create-runtime.js +10 -0
- package/lib/bootstrap/create-runtime.js.map +1 -0
- package/lib/bootstrap/create-services.d.ts +52 -0
- package/lib/bootstrap/create-services.d.ts.map +1 -0
- package/lib/bootstrap/create-services.js +79 -0
- package/lib/bootstrap/create-services.js.map +1 -0
- package/lib/bootstrap/install-commands.d.ts +4 -0
- package/lib/bootstrap/install-commands.d.ts.map +1 -0
- package/lib/bootstrap/install-commands.js +322 -0
- package/lib/bootstrap/install-commands.js.map +1 -0
- package/lib/bootstrap/install-http.d.ts +7 -0
- package/lib/bootstrap/install-http.d.ts.map +1 -0
- package/lib/bootstrap/install-http.js +265 -0
- package/lib/bootstrap/install-http.js.map +1 -0
- package/lib/bootstrap/lifecycle.d.ts +14 -0
- package/lib/bootstrap/lifecycle.d.ts.map +1 -0
- package/lib/bootstrap/lifecycle.js +56 -0
- package/lib/bootstrap/lifecycle.js.map +1 -0
- package/lib/bootstrap/types.d.ts +9 -0
- package/lib/bootstrap/types.d.ts.map +1 -0
- package/lib/bootstrap/types.js +2 -0
- package/lib/bootstrap/types.js.map +1 -0
- package/lib/client.js +6 -0
- package/lib/client.js.map +1 -0
- package/lib/core/audit-service.d.ts +43 -0
- package/lib/core/audit-service.d.ts.map +1 -0
- package/lib/core/audit-service.js +75 -0
- package/lib/core/audit-service.js.map +1 -0
- package/lib/core/candidate-extractor.d.ts +31 -0
- package/lib/core/candidate-extractor.d.ts.map +1 -0
- package/lib/core/candidate-extractor.js +83 -0
- package/lib/core/candidate-extractor.js.map +1 -0
- package/lib/core/candidate-service.d.ts +72 -0
- package/lib/core/candidate-service.d.ts.map +1 -0
- package/lib/core/candidate-service.js +283 -0
- package/lib/core/candidate-service.js.map +1 -0
- package/lib/core/character-service.d.ts +26 -0
- package/lib/core/character-service.d.ts.map +1 -0
- package/lib/core/character-service.js +68 -0
- package/lib/core/character-service.js.map +1 -0
- package/lib/core/chat-file-io.d.ts +28 -0
- package/lib/core/chat-file-io.d.ts.map +1 -0
- package/lib/core/chat-file-io.js +114 -0
- package/lib/core/chat-file-io.js.map +1 -0
- package/lib/core/chat-service.d.ts +4 -0
- package/lib/core/chat-service.d.ts.map +1 -0
- package/lib/core/chat-service.js +3 -0
- package/lib/core/chat-service.js.map +1 -0
- package/lib/core/command-arguments.d.ts +2 -0
- package/lib/core/command-arguments.d.ts.map +1 -0
- package/lib/core/command-arguments.js +42 -0
- package/lib/core/command-arguments.js.map +1 -0
- package/lib/core/companion-child-agent-service.d.ts +3 -0
- package/lib/core/companion-child-agent-service.d.ts.map +1 -0
- package/lib/core/companion-child-agent-service.js +3 -0
- package/lib/core/companion-child-agent-service.js.map +1 -0
- package/lib/core/companion-invocation-service.d.ts +3 -0
- package/lib/core/companion-invocation-service.d.ts.map +1 -0
- package/lib/core/companion-invocation-service.js +3 -0
- package/lib/core/companion-invocation-service.js.map +1 -0
- package/lib/core/companion-profile-service.d.ts +3 -0
- package/lib/core/companion-profile-service.d.ts.map +1 -0
- package/lib/core/companion-profile-service.js +3 -0
- package/lib/core/companion-profile-service.js.map +1 -0
- package/lib/core/companion-promotion-service.d.ts +3 -0
- package/lib/core/companion-promotion-service.d.ts.map +1 -0
- package/lib/core/companion-promotion-service.js +3 -0
- package/lib/core/companion-promotion-service.js.map +1 -0
- package/lib/core/context-assembler.d.ts +92 -0
- package/lib/core/context-assembler.d.ts.map +1 -0
- package/lib/core/context-assembler.js +185 -0
- package/lib/core/context-assembler.js.map +1 -0
- package/lib/core/conversation-repository.d.ts +42 -0
- package/lib/core/conversation-repository.d.ts.map +1 -0
- package/lib/core/conversation-repository.js +94 -0
- package/lib/core/conversation-repository.js.map +1 -0
- package/lib/core/group-chat-execution-service.d.ts +3 -0
- package/lib/core/group-chat-execution-service.d.ts.map +1 -0
- package/lib/core/group-chat-execution-service.js +3 -0
- package/lib/core/group-chat-execution-service.js.map +1 -0
- package/lib/core/group-chat-orchestrator.d.ts +3 -0
- package/lib/core/group-chat-orchestrator.d.ts.map +1 -0
- package/lib/core/group-chat-orchestrator.js +3 -0
- package/lib/core/group-chat-orchestrator.js.map +1 -0
- package/lib/core/memory-retriever.d.ts +3 -0
- package/lib/core/memory-retriever.d.ts.map +1 -0
- package/lib/core/memory-retriever.js +3 -0
- package/lib/core/memory-retriever.js.map +1 -0
- package/lib/core/memory-service.d.ts +3 -0
- package/lib/core/memory-service.d.ts.map +1 -0
- package/lib/core/memory-service.js +3 -0
- package/lib/core/memory-service.js.map +1 -0
- package/lib/core/personality-candidate-service.d.ts +46 -0
- package/lib/core/personality-candidate-service.d.ts.map +1 -0
- package/lib/core/personality-candidate-service.js +65 -0
- package/lib/core/personality-candidate-service.js.map +1 -0
- package/lib/core/prompt-assembler.d.ts +43 -0
- package/lib/core/prompt-assembler.d.ts.map +1 -0
- package/lib/core/prompt-assembler.js +67 -0
- package/lib/core/prompt-assembler.js.map +1 -0
- package/lib/core/relationship-event-service.d.ts +3 -0
- package/lib/core/relationship-event-service.d.ts.map +1 -0
- package/lib/core/relationship-event-service.js +3 -0
- package/lib/core/relationship-event-service.js.map +1 -0
- package/lib/core/relationship-policy.d.ts +3 -0
- package/lib/core/relationship-policy.d.ts.map +1 -0
- package/lib/core/relationship-policy.js +3 -0
- package/lib/core/relationship-policy.js.map +1 -0
- package/lib/core/relationship-projection.d.ts +3 -0
- package/lib/core/relationship-projection.d.ts.map +1 -0
- package/lib/core/relationship-projection.js +3 -0
- package/lib/core/relationship-projection.js.map +1 -0
- package/lib/core/relationship-service.d.ts +3 -0
- package/lib/core/relationship-service.d.ts.map +1 -0
- package/lib/core/relationship-service.js +3 -0
- package/lib/core/relationship-service.js.map +1 -0
- package/lib/core/roleplay-contract.d.ts +11 -0
- package/lib/core/roleplay-contract.d.ts.map +1 -0
- package/lib/core/roleplay-contract.js +27 -0
- package/lib/core/roleplay-contract.js.map +1 -0
- package/lib/core/runtime-binding-service.d.ts +19 -0
- package/lib/core/runtime-binding-service.d.ts.map +1 -0
- package/lib/core/runtime-binding-service.js +66 -0
- package/lib/core/runtime-binding-service.js.map +1 -0
- package/lib/core/scene-service.d.ts +60 -0
- package/lib/core/scene-service.d.ts.map +1 -0
- package/lib/core/scene-service.js +212 -0
- package/lib/core/scene-service.js.map +1 -0
- package/lib/core/session-binding-service.d.ts +51 -0
- package/lib/core/session-binding-service.d.ts.map +1 -0
- package/lib/core/session-binding-service.js +106 -0
- package/lib/core/session-binding-service.js.map +1 -0
- package/lib/core/skill-service.d.ts +82 -0
- package/lib/core/skill-service.d.ts.map +1 -0
- package/lib/core/skill-service.js +45 -0
- package/lib/core/skill-service.js.map +1 -0
- package/lib/core/tavern-session-bridge.d.ts +3 -0
- package/lib/core/tavern-session-bridge.d.ts.map +1 -0
- package/lib/core/tavern-session-bridge.js +3 -0
- package/lib/core/tavern-session-bridge.js.map +1 -0
- package/lib/core/user-resolver.d.ts +15 -0
- package/lib/core/user-resolver.d.ts.map +1 -0
- package/lib/core/user-resolver.js +17 -0
- package/lib/core/user-resolver.js.map +1 -0
- package/lib/core/workspace-service.d.ts +3 -0
- package/lib/core/workspace-service.d.ts.map +1 -0
- package/lib/core/workspace-service.js +3 -0
- package/lib/core/workspace-service.js.map +1 -0
- package/lib/core/workspace-session-service.d.ts +11 -0
- package/lib/core/workspace-session-service.d.ts.map +1 -0
- package/lib/core/workspace-session-service.js +14 -0
- package/lib/core/workspace-session-service.js.map +1 -0
- package/lib/domain/schemas.d.ts +1173 -0
- package/lib/domain/schemas.d.ts.map +1 -0
- package/lib/domain/schemas.js +590 -0
- package/lib/domain/schemas.js.map +1 -0
- package/lib/domain/spec.d.ts +494 -0
- package/lib/domain/spec.d.ts.map +1 -0
- package/lib/domain/spec.js +63 -0
- package/lib/domain/spec.js.map +1 -0
- package/lib/import/artifact-service.d.ts +33 -0
- package/lib/import/artifact-service.d.ts.map +1 -0
- package/lib/import/artifact-service.js +67 -0
- package/lib/import/artifact-service.js.map +1 -0
- package/lib/import/import-service.d.ts +30 -0
- package/lib/import/import-service.d.ts.map +1 -0
- package/lib/import/import-service.js +154 -0
- package/lib/import/import-service.js.map +1 -0
- package/lib/import/parser.d.ts +81 -0
- package/lib/import/parser.d.ts.map +1 -0
- package/lib/import/parser.js +423 -0
- package/lib/import/parser.js.map +1 -0
- package/lib/index.d.ts +60 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +111 -0
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/dsh/llm/llm-port.d.ts +3 -0
- package/lib/infrastructure/dsh/llm/llm-port.d.ts.map +1 -0
- package/lib/infrastructure/dsh/llm/llm-port.js +2 -0
- package/lib/infrastructure/dsh/llm/llm-port.js.map +1 -0
- package/lib/infrastructure/dsh/llm/model-gateway.d.ts +10 -0
- package/lib/infrastructure/dsh/llm/model-gateway.d.ts.map +1 -0
- package/lib/infrastructure/dsh/llm/model-gateway.js +21 -0
- package/lib/infrastructure/dsh/llm/model-gateway.js.map +1 -0
- package/lib/infrastructure/dsh/session/session-agent-provider.d.ts +28 -0
- package/lib/infrastructure/dsh/session/session-agent-provider.d.ts.map +1 -0
- package/lib/infrastructure/dsh/session/session-agent-provider.js +40 -0
- package/lib/infrastructure/dsh/session/session-agent-provider.js.map +1 -0
- package/lib/infrastructure/dsh/session/tavern-session-bridge.d.ts +142 -0
- package/lib/infrastructure/dsh/session/tavern-session-bridge.d.ts.map +1 -0
- package/lib/infrastructure/dsh/session/tavern-session-bridge.js +544 -0
- package/lib/infrastructure/dsh/session/tavern-session-bridge.js.map +1 -0
- package/lib/infrastructure/dsh/subagent/subagent-gateway.d.ts +63 -0
- package/lib/infrastructure/dsh/subagent/subagent-gateway.d.ts.map +1 -0
- package/lib/infrastructure/dsh/subagent/subagent-gateway.js +70 -0
- package/lib/infrastructure/dsh/subagent/subagent-gateway.js.map +1 -0
- package/lib/infrastructure/runtime/companion-runtime.d.ts +128 -0
- package/lib/infrastructure/runtime/companion-runtime.d.ts.map +1 -0
- package/lib/infrastructure/runtime/companion-runtime.js +127 -0
- package/lib/infrastructure/runtime/companion-runtime.js.map +1 -0
- package/lib/infrastructure/runtime/runtime-factory.d.ts +10 -0
- package/lib/infrastructure/runtime/runtime-factory.d.ts.map +1 -0
- package/lib/infrastructure/runtime/runtime-factory.js +14 -0
- package/lib/infrastructure/runtime/runtime-factory.js.map +1 -0
- package/lib/interfaces/http/chat/chat-http.d.ts +23 -0
- package/lib/interfaces/http/chat/chat-http.d.ts.map +1 -0
- package/lib/interfaces/http/chat/chat-http.js +310 -0
- package/lib/interfaces/http/chat/chat-http.js.map +1 -0
- package/lib/interfaces/http/companion/companion-http.d.ts +8 -0
- package/lib/interfaces/http/companion/companion-http.d.ts.map +1 -0
- package/lib/interfaces/http/companion/companion-http.js +76 -0
- package/lib/interfaces/http/companion/companion-http.js.map +1 -0
- package/lib/interfaces/http/companion/promotion-http.d.ts +6 -0
- package/lib/interfaces/http/companion/promotion-http.d.ts.map +1 -0
- package/lib/interfaces/http/companion/promotion-http.js +25 -0
- package/lib/interfaces/http/companion/promotion-http.js.map +1 -0
- package/lib/interfaces/http/companion/runtime-http.d.ts +13 -0
- package/lib/interfaces/http/companion/runtime-http.d.ts.map +1 -0
- package/lib/interfaces/http/companion/runtime-http.js +51 -0
- package/lib/interfaces/http/companion/runtime-http.js.map +1 -0
- package/lib/interfaces/http/companion/stage4-companion-http.d.ts +30 -0
- package/lib/interfaces/http/companion/stage4-companion-http.d.ts.map +1 -0
- package/lib/interfaces/http/companion/stage4-companion-http.js +149 -0
- package/lib/interfaces/http/companion/stage4-companion-http.js.map +1 -0
- package/lib/interfaces/http/group/group-http.d.ts +11 -0
- package/lib/interfaces/http/group/group-http.d.ts.map +1 -0
- package/lib/interfaces/http/group/group-http.js +77 -0
- package/lib/interfaces/http/group/group-http.js.map +1 -0
- package/lib/interfaces/http/memory/candidate-http.d.ts +8 -0
- package/lib/interfaces/http/memory/candidate-http.d.ts.map +1 -0
- package/lib/interfaces/http/memory/candidate-http.js +86 -0
- package/lib/interfaces/http/memory/candidate-http.js.map +1 -0
- package/lib/interfaces/http/relationship/companion-relationship-http.d.ts +7 -0
- package/lib/interfaces/http/relationship/companion-relationship-http.d.ts.map +1 -0
- package/lib/interfaces/http/relationship/companion-relationship-http.js +30 -0
- package/lib/interfaces/http/relationship/companion-relationship-http.js.map +1 -0
- package/lib/interfaces/http/workspace/workspace-http.d.ts +19 -0
- package/lib/interfaces/http/workspace/workspace-http.d.ts.map +1 -0
- package/lib/interfaces/http/workspace/workspace-http.js +78 -0
- package/lib/interfaces/http/workspace/workspace-http.js.map +1 -0
- package/lib/interfaces/read-model/tavern-read-api.d.ts +44 -0
- package/lib/interfaces/read-model/tavern-read-api.d.ts.map +1 -0
- package/lib/interfaces/read-model/tavern-read-api.js +189 -0
- package/lib/interfaces/read-model/tavern-read-api.js.map +1 -0
- package/lib/remote/candidate-api.d.ts +3 -0
- package/lib/remote/candidate-api.d.ts.map +1 -0
- package/lib/remote/candidate-api.js +3 -0
- package/lib/remote/candidate-api.js.map +1 -0
- package/lib/remote/chat-api.d.ts +3 -0
- package/lib/remote/chat-api.d.ts.map +1 -0
- package/lib/remote/chat-api.js +3 -0
- package/lib/remote/chat-api.js.map +1 -0
- package/lib/remote/companion-api.d.ts +3 -0
- package/lib/remote/companion-api.d.ts.map +1 -0
- package/lib/remote/companion-api.js +3 -0
- package/lib/remote/companion-api.js.map +1 -0
- package/lib/remote/companion-promotion-api.d.ts +3 -0
- package/lib/remote/companion-promotion-api.d.ts.map +1 -0
- package/lib/remote/companion-promotion-api.js +3 -0
- package/lib/remote/companion-promotion-api.js.map +1 -0
- package/lib/remote/import-http.d.ts +29 -0
- package/lib/remote/import-http.d.ts.map +1 -0
- package/lib/remote/import-http.js +106 -0
- package/lib/remote/import-http.js.map +1 -0
- package/lib/remote/stage4-api.d.ts +6 -0
- package/lib/remote/stage4-api.d.ts.map +1 -0
- package/lib/remote/stage4-api.js +4 -0
- package/lib/remote/stage4-api.js.map +1 -0
- package/lib/remote/stage5-runtime-api.d.ts +4 -0
- package/lib/remote/stage5-runtime-api.d.ts.map +1 -0
- package/lib/remote/stage5-runtime-api.js +2 -0
- package/lib/remote/stage5-runtime-api.js.map +1 -0
- package/lib/remote/stage6-group-api.d.ts +4 -0
- package/lib/remote/stage6-group-api.d.ts.map +1 -0
- package/lib/remote/stage6-group-api.js +2 -0
- package/lib/remote/stage6-group-api.js.map +1 -0
- package/lib/remote/tavern-api.d.ts +3 -0
- package/lib/remote/tavern-api.d.ts.map +1 -0
- package/lib/remote/tavern-api.js +3 -0
- package/lib/remote/tavern-api.js.map +1 -0
- package/lib/runtime/agent-orchestrator.d.ts +3 -0
- package/lib/runtime/agent-orchestrator.d.ts.map +1 -0
- package/lib/runtime/agent-orchestrator.js +3 -0
- package/lib/runtime/agent-orchestrator.js.map +1 -0
- package/lib/runtime/companion-runtime.d.ts +3 -0
- package/lib/runtime/companion-runtime.d.ts.map +1 -0
- package/lib/runtime/companion-runtime.js +3 -0
- package/lib/runtime/companion-runtime.js.map +1 -0
- package/lib/runtime/langgraph-graph.d.ts +32 -0
- package/lib/runtime/langgraph-graph.d.ts.map +1 -0
- package/lib/runtime/langgraph-graph.js +32 -0
- package/lib/runtime/langgraph-graph.js.map +1 -0
- package/lib/runtime/state.d.ts +38 -0
- package/lib/runtime/state.d.ts.map +1 -0
- package/lib/runtime/state.js +16 -0
- package/lib/runtime/state.js.map +1 -0
- package/lib/seed/elaine.d.ts +9 -0
- package/lib/seed/elaine.d.ts.map +1 -0
- package/lib/seed/elaine.js +27 -0
- package/lib/seed/elaine.js.map +1 -0
- package/lib/tools/import-character.d.ts +16 -0
- package/lib/tools/import-character.d.ts.map +1 -0
- package/lib/tools/import-character.js +98 -0
- package/lib/tools/import-character.js.map +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatService —— 普通角色卡聊天(阶段 1,ADR-002)。
|
|
3
|
+
*
|
|
4
|
+
* 非 Agent 模型调用链路:conversation 持久化(事实源)→ PromptAssembler →
|
|
5
|
+
* LlmPort(ctx.llm.stream)→ 流式回复落盘。
|
|
6
|
+
*
|
|
7
|
+
* 约束:本服务**禁止**调用 startContinuable / SubagentGateway / LangGraph /
|
|
8
|
+
* 工作工具;角色卡默认 chat-only(ADR-005,CapabilityGrant 阶段 4 落地)。
|
|
9
|
+
*/
|
|
10
|
+
import type { Conversation, ConversationMessage } from '../../domain/schemas.js';
|
|
11
|
+
import type { LlmPort } from '../ports/llm-port.js';
|
|
12
|
+
import type { CharacterService } from '../../core/character-service.js';
|
|
13
|
+
import type { ConversationRepository } from '../../core/conversation-repository.js';
|
|
14
|
+
import type { PromptAssembler } from '../../core/prompt-assembler.js';
|
|
15
|
+
import type { UserResolverPort } from '../../application/ports/user-resolver-port.js';
|
|
16
|
+
export interface ModelSelection {
|
|
17
|
+
readonly provider: string;
|
|
18
|
+
readonly model: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class ChatApplicationService {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(userResolver: UserResolverPort, characters: CharacterService, conversationRepo: ConversationRepository, promptAssembler: PromptAssembler, modelGateway: LlmPort, modelSelection: () => ModelSelection, afterAssistantPersisted?: (ownerUserId: string, conversationId: string) => Promise<void>, afterConversationChanged?: (ownerUserId: string, conversationId: string) => Promise<void>);
|
|
23
|
+
/** 当前用户的全部会话(按更新时间倒序)。 */
|
|
24
|
+
listConversations(): Promise<Conversation[]>;
|
|
25
|
+
/** 读取当前用户拥有的一个聊天文件;不存在或跨用户时返回 null。 */
|
|
26
|
+
getConversation(conversationId: string): Promise<Conversation | null>;
|
|
27
|
+
/** 更新聊天文件显示名称;空白名称会清除自定义名称并回退显示日期。 */
|
|
28
|
+
renameConversation(conversationId: string, title: string): Promise<Conversation>;
|
|
29
|
+
/** 删除聊天文件:移入 Tavern 回收站,消息历史仍完整保留。 */
|
|
30
|
+
trashConversation(conversationId: string): Promise<Conversation>;
|
|
31
|
+
restoreConversation(conversationId: string): Promise<Conversation>;
|
|
32
|
+
/** 角色进入回收站时,连带隐藏其聊天文件但不删除消息。 */
|
|
33
|
+
trashCharacterConversations(characterId: string): Promise<number>;
|
|
34
|
+
restoreCharacterConversations(characterId: string): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* 发送一条消息并流式生成回复。
|
|
37
|
+
* - 无 conversationId 时创建新会话(消息树根);
|
|
38
|
+
* - 用户消息落盘并成为 active leaf;
|
|
39
|
+
* - 返回外层流:消费模型 chunk → 文本 delta 流,结束时 assistant 消息落盘。
|
|
40
|
+
*/
|
|
41
|
+
stream(params: {
|
|
42
|
+
characterId: string;
|
|
43
|
+
message: string;
|
|
44
|
+
conversationId?: string;
|
|
45
|
+
sceneId?: string;
|
|
46
|
+
/** 伙伴 Agent 会话 persona;缺省用角色卡 persona。 */
|
|
47
|
+
systemOverride?: string;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
conversationId: string;
|
|
50
|
+
messageId: string;
|
|
51
|
+
stream: AsyncIterable<string>;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* 重新生成(swipe sibling,§9.3):目标 assistant 消息的 parent 为分支点,
|
|
55
|
+
* 生成新的 sibling assistant 消息(旧消息保留 active 可回切,active leaf 指向新的)。
|
|
56
|
+
* 返回流式文本;结束时新消息落盘并推进 leaf(消息 id 由 UI 重拉消息树获取)。
|
|
57
|
+
*/
|
|
58
|
+
regenerate(params: {
|
|
59
|
+
conversationId: string;
|
|
60
|
+
messageId: string;
|
|
61
|
+
sceneId?: string;
|
|
62
|
+
}): Promise<{
|
|
63
|
+
stream: AsyncIterable<string>;
|
|
64
|
+
}>;
|
|
65
|
+
/** 编辑用户消息(§9.3/9.4):原消息 superseded(保留历史),新消息同 parent 成为分支点。 */
|
|
66
|
+
editMessage(params: {
|
|
67
|
+
conversationId: string;
|
|
68
|
+
messageId: string;
|
|
69
|
+
newContent: string;
|
|
70
|
+
}): Promise<{
|
|
71
|
+
messageId: string;
|
|
72
|
+
}>;
|
|
73
|
+
/** 会话全部消息(消息树,UI 渲染用;createdAt 升序)。 */
|
|
74
|
+
listMessages(conversationId: string): Promise<ConversationMessage[]>;
|
|
75
|
+
/** 角色开场白候选(first_mes + alternate_greetings,新建对话时选择)。 */
|
|
76
|
+
greetings(characterId: string): readonly string[];
|
|
77
|
+
/**
|
|
78
|
+
* 新建会话(§9.5):可选以角色开场白作为首条 assistant 消息(无生成调用)。
|
|
79
|
+
* 返回 conversationId;greetingIndex 省略则不写开场(用户发首条消息)。
|
|
80
|
+
*/
|
|
81
|
+
startConversation(params: {
|
|
82
|
+
characterId: string;
|
|
83
|
+
greetingIndex?: number;
|
|
84
|
+
sceneId?: string;
|
|
85
|
+
}): Promise<{
|
|
86
|
+
conversationId: string;
|
|
87
|
+
}>;
|
|
88
|
+
/** 切换 active leaf(分支继续;乐观并发由 repository CAS 保证)。 */
|
|
89
|
+
switchBranch(params: {
|
|
90
|
+
conversationId: string;
|
|
91
|
+
messageId: string;
|
|
92
|
+
}): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=chat-application-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-application-service.d.ts","sourceRoot":"","sources":["../../../src/application/chat/chat-application-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAEhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MA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CAAC;IA4BvI,oDAAoD;IAC9C,YAAY,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAOzF"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatService —— 普通角色卡聊天(阶段 1,ADR-002)。
|
|
3
|
+
*
|
|
4
|
+
* 非 Agent 模型调用链路:conversation 持久化(事实源)→ PromptAssembler →
|
|
5
|
+
* LlmPort(ctx.llm.stream)→ 流式回复落盘。
|
|
6
|
+
*
|
|
7
|
+
* 约束:本服务**禁止**调用 startContinuable / SubagentGateway / LangGraph /
|
|
8
|
+
* 工作工具;角色卡默认 chat-only(ADR-005,CapabilityGrant 阶段 4 落地)。
|
|
9
|
+
*/
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
import { createMessage } from '@deepseek-ai/dsh-llm';
|
|
12
|
+
import { tavernMessageSource } from '../ports/message-source.js';
|
|
13
|
+
export class ChatApplicationService {
|
|
14
|
+
#userResolver;
|
|
15
|
+
#characters;
|
|
16
|
+
#conversationRepo;
|
|
17
|
+
#promptAssembler;
|
|
18
|
+
#modelGateway;
|
|
19
|
+
/** 模型默认来源(agentDefaultModel.currentSelection),可配置覆盖。 */
|
|
20
|
+
#modelSelection;
|
|
21
|
+
/** 候选提取是 best-effort 后处理:绝不可阻断普通聊天。 */
|
|
22
|
+
#afterAssistantPersisted;
|
|
23
|
+
/** 分支切换/编辑后重验候选证据;同样是 best-effort,不能阻断聊天操作。 */
|
|
24
|
+
#afterConversationChanged;
|
|
25
|
+
constructor(userResolver, characters, conversationRepo, promptAssembler, modelGateway, modelSelection, afterAssistantPersisted, afterConversationChanged) {
|
|
26
|
+
this.#userResolver = userResolver;
|
|
27
|
+
this.#characters = characters;
|
|
28
|
+
this.#conversationRepo = conversationRepo;
|
|
29
|
+
this.#promptAssembler = promptAssembler;
|
|
30
|
+
this.#modelGateway = modelGateway;
|
|
31
|
+
this.#modelSelection = modelSelection;
|
|
32
|
+
this.#afterAssistantPersisted = afterAssistantPersisted;
|
|
33
|
+
this.#afterConversationChanged = afterConversationChanged;
|
|
34
|
+
}
|
|
35
|
+
/** 当前用户的全部会话(按更新时间倒序)。 */
|
|
36
|
+
async listConversations() {
|
|
37
|
+
const userId = await this.#userResolver.getCurrentUserId();
|
|
38
|
+
return this.#conversationRepo.listByUser(userId);
|
|
39
|
+
}
|
|
40
|
+
/** 读取当前用户拥有的一个聊天文件;不存在或跨用户时返回 null。 */
|
|
41
|
+
async getConversation(conversationId) {
|
|
42
|
+
const conversation = await this.#conversationRepo.get(conversationId);
|
|
43
|
+
if (conversation === null)
|
|
44
|
+
return null;
|
|
45
|
+
const userId = await this.#userResolver.getCurrentUserId();
|
|
46
|
+
return conversation.ownerUserId === userId ? conversation : null;
|
|
47
|
+
}
|
|
48
|
+
/** 更新聊天文件显示名称;空白名称会清除自定义名称并回退显示日期。 */
|
|
49
|
+
async renameConversation(conversationId, title) {
|
|
50
|
+
const conversation = await this.getConversation(conversationId);
|
|
51
|
+
if (conversation === null)
|
|
52
|
+
throw new Error(`[Tavern] 聊天文件不存在:${conversationId}`);
|
|
53
|
+
if (conversation.status !== 'active')
|
|
54
|
+
throw new Error('[Tavern] 已删除的聊天文件不可重命名');
|
|
55
|
+
return this.#conversationRepo.update(conversationId, { ...(title.trim() === '' ? { title: undefined } : { title: title.trim().slice(0, 120) }) });
|
|
56
|
+
}
|
|
57
|
+
/** 删除聊天文件:移入 Tavern 回收站,消息历史仍完整保留。 */
|
|
58
|
+
async trashConversation(conversationId) {
|
|
59
|
+
const conversation = await this.getConversation(conversationId);
|
|
60
|
+
if (conversation === null)
|
|
61
|
+
throw new Error(`[Tavern] 聊天文件不存在:${conversationId}`);
|
|
62
|
+
return this.#conversationRepo.update(conversationId, { status: 'trashed' });
|
|
63
|
+
}
|
|
64
|
+
async restoreConversation(conversationId) {
|
|
65
|
+
const conversation = await this.getConversation(conversationId);
|
|
66
|
+
if (conversation === null)
|
|
67
|
+
throw new Error(`[Tavern] 聊天文件不存在:${conversationId}`);
|
|
68
|
+
return this.#conversationRepo.update(conversationId, { status: 'active' });
|
|
69
|
+
}
|
|
70
|
+
/** 角色进入回收站时,连带隐藏其聊天文件但不删除消息。 */
|
|
71
|
+
async trashCharacterConversations(characterId) {
|
|
72
|
+
return this.#conversationRepo.updateByCharacter(characterId, { status: 'trashed' });
|
|
73
|
+
}
|
|
74
|
+
async restoreCharacterConversations(characterId) {
|
|
75
|
+
return this.#conversationRepo.updateByCharacter(characterId, { status: 'active' });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 发送一条消息并流式生成回复。
|
|
79
|
+
* - 无 conversationId 时创建新会话(消息树根);
|
|
80
|
+
* - 用户消息落盘并成为 active leaf;
|
|
81
|
+
* - 返回外层流:消费模型 chunk → 文本 delta 流,结束时 assistant 消息落盘。
|
|
82
|
+
*/
|
|
83
|
+
async stream(params) {
|
|
84
|
+
const userId = await this.#userResolver.getCurrentUserId();
|
|
85
|
+
let conversation;
|
|
86
|
+
if (params.conversationId !== undefined) {
|
|
87
|
+
const existing = await this.#conversationRepo.get(params.conversationId);
|
|
88
|
+
if (existing === null)
|
|
89
|
+
throw new Error(`[Tavern] Conversation 不存在:${params.conversationId}`);
|
|
90
|
+
conversation = existing;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
conversation = await this.#conversationRepo.create({
|
|
94
|
+
id: randomUUID(),
|
|
95
|
+
ownerUserId: userId,
|
|
96
|
+
characterId: params.characterId,
|
|
97
|
+
characterRevision: 1, // revision 固化:完整版本策略 v0.2
|
|
98
|
+
...(params.sceneId === undefined ? {} : { sceneId: params.sceneId }),
|
|
99
|
+
status: 'active',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// 用户消息落盘(挂在当前 leaf 下,形成消息树)。
|
|
103
|
+
const parentId = conversation.activeLeafMessageId;
|
|
104
|
+
const userMessage = await this.#conversationRepo.addMessage({
|
|
105
|
+
id: randomUUID(),
|
|
106
|
+
conversationId: conversation.id,
|
|
107
|
+
...(parentId === undefined ? {} : { parentMessageId: parentId }),
|
|
108
|
+
role: 'user',
|
|
109
|
+
content: params.message,
|
|
110
|
+
status: 'active',
|
|
111
|
+
});
|
|
112
|
+
await this.#conversationRepo.updateActiveLeaf(conversation.id, userMessage.id);
|
|
113
|
+
// 组装 prompt(世界书/记忆注入 + 历史 + 本轮消息)。
|
|
114
|
+
const prompt = await this.#promptAssembler.assemble({
|
|
115
|
+
characterId: params.characterId,
|
|
116
|
+
conversationId: conversation.id,
|
|
117
|
+
userMessage: params.message,
|
|
118
|
+
...(params.sceneId === undefined ? {} : { sceneId: params.sceneId }),
|
|
119
|
+
activeLeafMessageId: userMessage.id,
|
|
120
|
+
...(params.systemOverride === undefined ? {} : { systemOverride: params.systemOverride }),
|
|
121
|
+
});
|
|
122
|
+
const selection = this.#modelSelection();
|
|
123
|
+
const chunks = this.#modelGateway.stream({
|
|
124
|
+
provider: selection.provider,
|
|
125
|
+
model: selection.model,
|
|
126
|
+
system: prompt.system,
|
|
127
|
+
messages: prompt.messages
|
|
128
|
+
.filter(message => message.role !== 'system')
|
|
129
|
+
.map(message => createMessage({
|
|
130
|
+
role: message.role,
|
|
131
|
+
content: [{ type: 'text', text: message.content }],
|
|
132
|
+
source: tavernMessageSource(),
|
|
133
|
+
})),
|
|
134
|
+
});
|
|
135
|
+
const conversationId = conversation.id;
|
|
136
|
+
return {
|
|
137
|
+
conversationId,
|
|
138
|
+
messageId: userMessage.id,
|
|
139
|
+
stream: this.#consume(chunks, conversationId, userMessage.id, userId),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** 消费模型 chunk 流:产出文本 delta,结束时把 assistant 消息写入消息树。 */
|
|
143
|
+
async *#consume(chunks, conversationId, parentMessageId, ownerUserId) {
|
|
144
|
+
let text = '';
|
|
145
|
+
for await (const chunk of chunks) {
|
|
146
|
+
if (chunk.type === 'text-delta') {
|
|
147
|
+
text += chunk.text;
|
|
148
|
+
yield chunk.text;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (text !== '') {
|
|
152
|
+
const assistant = await this.#conversationRepo.addMessage({
|
|
153
|
+
id: randomUUID(),
|
|
154
|
+
conversationId,
|
|
155
|
+
...(parentMessageId === undefined ? {} : { parentMessageId }),
|
|
156
|
+
role: 'assistant',
|
|
157
|
+
content: text,
|
|
158
|
+
status: 'active',
|
|
159
|
+
});
|
|
160
|
+
await this.#conversationRepo.updateActiveLeaf(conversationId, assistant.id);
|
|
161
|
+
if (ownerUserId !== undefined) {
|
|
162
|
+
// 新 assistant(特别是 regenerate 的 sibling)也会改变 active leaf:
|
|
163
|
+
// 先重验旧候选的分支证据,再 best-effort 提取当前分支的新候选。
|
|
164
|
+
void (async () => {
|
|
165
|
+
await this.#afterConversationChanged?.(ownerUserId, conversationId);
|
|
166
|
+
await this.#afterAssistantPersisted?.(ownerUserId, conversationId);
|
|
167
|
+
})().catch(() => { });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 重新生成(swipe sibling,§9.3):目标 assistant 消息的 parent 为分支点,
|
|
173
|
+
* 生成新的 sibling assistant 消息(旧消息保留 active 可回切,active leaf 指向新的)。
|
|
174
|
+
* 返回流式文本;结束时新消息落盘并推进 leaf(消息 id 由 UI 重拉消息树获取)。
|
|
175
|
+
*/
|
|
176
|
+
async regenerate(params) {
|
|
177
|
+
const target = await this.#conversationRepo.getMessage(params.messageId);
|
|
178
|
+
if (target === null)
|
|
179
|
+
throw new Error(`[Tavern] 消息不存在:${params.messageId}`);
|
|
180
|
+
if (target.role !== 'assistant')
|
|
181
|
+
throw new Error('[Tavern] 只能重新生成 assistant 消息');
|
|
182
|
+
const conversation = await this.#conversationRepo.get(params.conversationId);
|
|
183
|
+
if (conversation === null)
|
|
184
|
+
throw new Error(`[Tavern] Conversation 不存在:${params.conversationId}`);
|
|
185
|
+
const branchPointId = target.parentMessageId;
|
|
186
|
+
// 分支点消息(用户消息)作为本轮上下文锚点;无父消息(root assistant)则用空开场。
|
|
187
|
+
const branchUserContent = branchPointId === undefined
|
|
188
|
+
? ''
|
|
189
|
+
: (await this.#conversationRepo.getMessage(branchPointId))?.content ?? '';
|
|
190
|
+
const prompt = await this.#promptAssembler.assemble({
|
|
191
|
+
characterId: conversation.characterId,
|
|
192
|
+
conversationId: conversation.id,
|
|
193
|
+
userMessage: branchUserContent,
|
|
194
|
+
...(params.sceneId === undefined ? {} : { sceneId: params.sceneId }),
|
|
195
|
+
...(branchPointId === undefined ? {} : { activeLeafMessageId: branchPointId }),
|
|
196
|
+
});
|
|
197
|
+
const selection = this.#modelSelection();
|
|
198
|
+
const chunks = this.#modelGateway.stream({
|
|
199
|
+
provider: selection.provider,
|
|
200
|
+
model: selection.model,
|
|
201
|
+
system: prompt.system,
|
|
202
|
+
messages: prompt.messages
|
|
203
|
+
.filter(message => message.role !== 'system')
|
|
204
|
+
.map(message => createMessage({
|
|
205
|
+
role: message.role,
|
|
206
|
+
content: [{ type: 'text', text: message.content }],
|
|
207
|
+
source: tavernMessageSource(),
|
|
208
|
+
})),
|
|
209
|
+
});
|
|
210
|
+
return { stream: this.#consume(chunks, conversation.id, branchPointId, conversation.ownerUserId) };
|
|
211
|
+
}
|
|
212
|
+
/** 编辑用户消息(§9.3/9.4):原消息 superseded(保留历史),新消息同 parent 成为分支点。 */
|
|
213
|
+
async editMessage(params) {
|
|
214
|
+
const target = await this.#conversationRepo.getMessage(params.messageId);
|
|
215
|
+
if (target === null)
|
|
216
|
+
throw new Error(`[Tavern] 消息不存在:${params.messageId}`);
|
|
217
|
+
if (target.role !== 'user')
|
|
218
|
+
throw new Error('[Tavern] 只能编辑用户消息');
|
|
219
|
+
await this.#conversationRepo.updateMessage(params.messageId, { status: 'superseded' });
|
|
220
|
+
const edited = await this.#conversationRepo.addMessage({
|
|
221
|
+
id: randomUUID(),
|
|
222
|
+
conversationId: params.conversationId,
|
|
223
|
+
...(target.parentMessageId === undefined ? {} : { parentMessageId: target.parentMessageId }),
|
|
224
|
+
role: 'user',
|
|
225
|
+
content: params.newContent,
|
|
226
|
+
status: 'active',
|
|
227
|
+
});
|
|
228
|
+
await this.#conversationRepo.updateActiveLeaf(params.conversationId, edited.id);
|
|
229
|
+
const conversation = await this.#conversationRepo.get(params.conversationId);
|
|
230
|
+
if (conversation !== null && this.#afterConversationChanged !== undefined) {
|
|
231
|
+
void this.#afterConversationChanged(conversation.ownerUserId, conversation.id).catch(() => { });
|
|
232
|
+
}
|
|
233
|
+
return { messageId: edited.id };
|
|
234
|
+
}
|
|
235
|
+
/** 会话全部消息(消息树,UI 渲染用;createdAt 升序)。 */
|
|
236
|
+
async listMessages(conversationId) {
|
|
237
|
+
return this.#conversationRepo.getMessageTree(conversationId);
|
|
238
|
+
}
|
|
239
|
+
/** 角色开场白候选(first_mes + alternate_greetings,新建对话时选择)。 */
|
|
240
|
+
greetings(characterId) {
|
|
241
|
+
const character = this.#characters.get(characterId);
|
|
242
|
+
if (character === null)
|
|
243
|
+
throw new Error(`[Tavern] 角色不存在:${characterId}`);
|
|
244
|
+
return [
|
|
245
|
+
...(character.firstMessage === undefined ? [] : [character.firstMessage]),
|
|
246
|
+
...character.alternateGreetings,
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 新建会话(§9.5):可选以角色开场白作为首条 assistant 消息(无生成调用)。
|
|
251
|
+
* 返回 conversationId;greetingIndex 省略则不写开场(用户发首条消息)。
|
|
252
|
+
*/
|
|
253
|
+
async startConversation(params) {
|
|
254
|
+
const userId = await this.#userResolver.getCurrentUserId();
|
|
255
|
+
const character = this.#characters.get(params.characterId);
|
|
256
|
+
if (character === null)
|
|
257
|
+
throw new Error(`[Tavern] 角色不存在:${params.characterId}`);
|
|
258
|
+
const conversation = await this.#conversationRepo.create({
|
|
259
|
+
id: randomUUID(),
|
|
260
|
+
ownerUserId: userId,
|
|
261
|
+
characterId: params.characterId,
|
|
262
|
+
characterRevision: character.revision,
|
|
263
|
+
...(params.sceneId === undefined ? {} : { sceneId: params.sceneId }),
|
|
264
|
+
status: 'active',
|
|
265
|
+
});
|
|
266
|
+
if (params.greetingIndex !== undefined) {
|
|
267
|
+
const greetings = this.greetings(params.characterId);
|
|
268
|
+
const greeting = greetings[params.greetingIndex];
|
|
269
|
+
if (greeting === undefined)
|
|
270
|
+
throw new Error(`[Tavern] 开场白索引越界:${params.greetingIndex}`);
|
|
271
|
+
const assistant = await this.#conversationRepo.addMessage({
|
|
272
|
+
id: randomUUID(),
|
|
273
|
+
conversationId: conversation.id,
|
|
274
|
+
role: 'assistant',
|
|
275
|
+
content: greeting,
|
|
276
|
+
status: 'active',
|
|
277
|
+
});
|
|
278
|
+
await this.#conversationRepo.updateActiveLeaf(conversation.id, assistant.id);
|
|
279
|
+
}
|
|
280
|
+
return { conversationId: conversation.id };
|
|
281
|
+
}
|
|
282
|
+
/** 切换 active leaf(分支继续;乐观并发由 repository CAS 保证)。 */
|
|
283
|
+
async switchBranch(params) {
|
|
284
|
+
await this.#conversationRepo.updateActiveLeaf(params.conversationId, params.messageId);
|
|
285
|
+
const conversation = await this.#conversationRepo.get(params.conversationId);
|
|
286
|
+
if (conversation !== null && this.#afterConversationChanged !== undefined) {
|
|
287
|
+
void this.#afterConversationChanged(conversation.ownerUserId, conversation.id).catch(() => { });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=chat-application-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-application-service.js","sourceRoot":"","sources":["../../../src/application/chat/chat-application-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAoB,MAAM,sBAAsB,CAAA;AAEtE,OAAO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CAAC,iBAAiB,CAAC,gBAAgB,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,SAAS,CAAC,CAAA;QACtF,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QAC5E,IAAI,YAAY,KAAK,IAAI,IAAI,IAAI,CAAC,yBAAyB,KAAK,SAAS,EAAE,CAAC;YAC1E,KAAK,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAChG,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentOrchestrator —— 实例编排器(阶段 1 起,5.3 场景化)。
|
|
3
|
+
*
|
|
4
|
+
* 职责:summon(创建角色的 continuable 子 Agent 并归属场景)与 followup
|
|
5
|
+
* (向该子 Agent 续推,验证场景归属),并记录 parent/child session 关系。
|
|
6
|
+
* 调用方**不需要**传 parentAgent:当前会话的 Agent 由 SessionAgentProvider
|
|
7
|
+
* 从调用上下文(命令入口)解析。
|
|
8
|
+
*
|
|
9
|
+
* 场景模型(阶段 5.3):
|
|
10
|
+
* - 实例按 `characterId@sceneId` 索引(单实例每角色每场景;同一角色可在
|
|
11
|
+
* 不同场景各有实例,记忆/关系按场景隔离);
|
|
12
|
+
* - summon 解析场景:显式 sceneId(须存在)→ 用户首个 active 场景 →
|
|
13
|
+
* 自动创建(sceneTitle 或「{角色} 的场景」);
|
|
14
|
+
* - followup 解析场景:显式 sceneId → 最后活跃场景 → 该用户唯一候选实例;
|
|
15
|
+
* 多场景同角色且无显式 sceneId 时抛错(需显式指定);
|
|
16
|
+
* - 场景归属验证:followup 要求当前用户是该场景的 active 参与者(否则
|
|
17
|
+
* 跨场景调用被拒绝)。
|
|
18
|
+
*
|
|
19
|
+
* 持久化:summon 成功后把实例(含 sceneId)写入 instances 表;构造时从表
|
|
20
|
+
* 恢复 active 实例(Host 重启后 followup 可直接继续)。
|
|
21
|
+
*
|
|
22
|
+
* 状态语义:followup 成功仅表示 inbox 已接受(accepted),绝不等于角色已
|
|
23
|
+
* 回复完成(completed)——completed 需要可验证的运行时完成信号(turn/end)。
|
|
24
|
+
*/
|
|
25
|
+
import type { MessageId } from '@deepseek-ai/dsh-llm';
|
|
26
|
+
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
27
|
+
import type { KvTable } from '@deepseek-ai/dsh-storage-domain';
|
|
28
|
+
import type { CharacterAgentInstance } from '../../domain/schemas.js';
|
|
29
|
+
import type { AuditService } from '../../core/audit-service.js';
|
|
30
|
+
import type { CharacterService } from '../../core/character-service.js';
|
|
31
|
+
import { ContextAssembler } from '../../core/context-assembler.js';
|
|
32
|
+
import type { RelationshipService } from '../relationship/relationship-service.js';
|
|
33
|
+
import type { SceneService } from '../../core/scene-service.js';
|
|
34
|
+
import type { SessionContextPort } from '../ports/session-context-port.js';
|
|
35
|
+
import type { SubagentPort } from '../ports/subagent-port.js';
|
|
36
|
+
/** 编排器日志门面(结构兼容 cordis Logger,便于单测注入)。 */
|
|
37
|
+
export interface OrchestratorLogger {
|
|
38
|
+
info(message: string): void;
|
|
39
|
+
}
|
|
40
|
+
/** Legacy profile metadata is retained, but every Tavern child is tool-free. */
|
|
41
|
+
/** 一次已建立的角色实例(内存 registry 条目)。 */
|
|
42
|
+
export interface TavernInstance {
|
|
43
|
+
readonly characterId: string;
|
|
44
|
+
readonly sceneId: string;
|
|
45
|
+
readonly parentSessionId: SessionId;
|
|
46
|
+
readonly childId: SessionId;
|
|
47
|
+
readonly createdAt: string;
|
|
48
|
+
}
|
|
49
|
+
/** summon 参数:无需 parentAgent(由 SessionAgentProvider 解析当前会话 Agent)。 */
|
|
50
|
+
export interface SummonParams {
|
|
51
|
+
readonly characterId: string;
|
|
52
|
+
/** 首条消息;缺省用角色卡 firstMessage。 */
|
|
53
|
+
readonly initialMessage?: string;
|
|
54
|
+
/** 场景归属(阶段 5.3):显式加入指定场景;缺省复用用户 active 场景或新建。 */
|
|
55
|
+
readonly sceneId?: string;
|
|
56
|
+
/** 自动创建场景时的标题。 */
|
|
57
|
+
readonly sceneTitle?: string;
|
|
58
|
+
readonly signal?: AbortSignal;
|
|
59
|
+
}
|
|
60
|
+
export interface SummonResult {
|
|
61
|
+
readonly childId: SessionId;
|
|
62
|
+
readonly messageId: MessageId;
|
|
63
|
+
/** 实例归属的场景 id(复用或新建)。 */
|
|
64
|
+
readonly sceneId: string;
|
|
65
|
+
}
|
|
66
|
+
/** followup 参数:无需 parentAgent(由 SessionAgentProvider 解析)。 */
|
|
67
|
+
export interface FollowupParams {
|
|
68
|
+
readonly characterId: string;
|
|
69
|
+
readonly message: string;
|
|
70
|
+
/** 场景归属:缺省用最后活跃场景或该用户唯一候选实例。 */
|
|
71
|
+
readonly sceneId?: string;
|
|
72
|
+
readonly signal?: AbortSignal;
|
|
73
|
+
}
|
|
74
|
+
export interface FollowupResult {
|
|
75
|
+
/** 恒为 true:仅表示 inbox 已接受(accepted ≠ completed)。 */
|
|
76
|
+
readonly accepted: true;
|
|
77
|
+
readonly messageId: MessageId;
|
|
78
|
+
}
|
|
79
|
+
export declare class AgentOrchestrator {
|
|
80
|
+
#private;
|
|
81
|
+
constructor(characters: CharacterService, gateway: SubagentPort, sessionAgents: SessionContextPort, instanceStore: KvTable<string, CharacterAgentInstance>, contextAssembler: ContextAssembler, relationships: RelationshipService, scenes: SceneService, audit: AuditService, logger: OrchestratorLogger);
|
|
82
|
+
/** 实例 registry 键:`characterId@sceneId`(单实例每角色每场景)。 */
|
|
83
|
+
static instanceKey(characterId: string, sceneId: string): string;
|
|
84
|
+
/** 已召唤实例快照(只读)。 */
|
|
85
|
+
listInstances(): readonly TavernInstance[];
|
|
86
|
+
/** 召唤角色:解析/创建场景 → 登记参与者 → 建立 continuable 子 Agent。 */
|
|
87
|
+
summon(params: SummonParams): Promise<SummonResult>;
|
|
88
|
+
/** 向角色实例续推一条消息。返回仅表示 accepted,不是 completed。 */
|
|
89
|
+
followup(params: FollowupParams): Promise<FollowupResult>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=agent-orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/application/companion/agent-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,iCAAiC,CAAA;AACzF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAQ7D,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,gFAAgF;AAChF,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,C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