载入中...
搜索中...
未找到
DialogueState.cpp
浏览该文件的文档.
14std::optional<T> queryProviders(const std::string& subject, eve::IStateQuery* explicitProvider, Query&& query) {
32eve::Result<eve::decision::Condition> conditionError(std::string message, std::string path = {}) {
81 return eve::Result<eve::decision::Condition>::success(eve::decision::Condition::all(std::move(children)));
83 if (!specification.isObject()) return conditionError("dialogue condition must be an object or array");
94 return eve::Result<eve::decision::Condition>::success(eve::decision::Condition::all(std::move(children)));
105 return eve::Result<eve::decision::Condition>::success(eve::decision::Condition::any(std::move(children)));
118 return eve::Result<eve::decision::Condition>::success(eve::decision::Condition::hasTag(tag->asString()));
123 if (!authority->isString()) return conditionError("authority condition requires a string scope", "authority");
131 if (!policy->isString()) return conditionError("policy condition requires a string name", "policy");
161 return eve::Result<eve::decision::Condition>::success(eve::decision::Condition::hasAttribute(key));
166 if (!readOperator(op, parsed)) return conditionError("unknown condition operator: " + op, "op");
179 if (!readString(*state, "key", key)) return conditionError("state condition is missing key", "state.key");
188 if (!compare->isObject()) return conditionError("compare condition must be an object", "compare");
197 eve::DiagnosticCode::Unsupported, "dialogue world mutation requires an IStateMutation capability",
213 for (std::size_t i = 0; i < value.arraySize(); ++i) result.push_back(toCanonicalValue(value.at(i)));
234 for (std::size_t i = 0; i < value.arraySize(); ++i) result.pushBack(toDialogueStateValue(value.at(i)));
252 return queryProviders<eve::Value>(subject_, provider_, [&](eve::IStateQuery* provider, const std::string& subject) {
258 return queryProviders<bool>(subject_, provider_, [&](eve::IStateQuery* provider, const std::string& subject) {
266 [&](eve::IStateQuery* provider, const std::string& subject) { return provider->attribute(subject, key); });
272 return queryProviders<eve::Value>(subject_, provider_, [&](eve::IStateQuery* provider, const std::string& subject) {
280 [&](eve::IStateQuery* provider, const std::string& subject) { return provider->state(subject, key); });
286 return queryProviders<bool>(subject_, provider_, [&](eve::IStateQuery* provider, const std::string& subject) {
291std::optional<eve::decision::ConditionResult> StateEvaluationContext::policy(std::string_view name,
297DialogueStateContext::DialogueStateContext(std::string subject) : subject_(std::move(subject)) {}
332eve::Result<eve::decision::Condition> DialogueStateContext::compileCondition(const eve::Value& specification) const {
341eve::decision::ConditionResult DialogueStateContext::evaluate(const eve::Value& specification) const {
353eve::Result<eve::MutationReceipt> DialogueStateContext::apply(std::span<const eve::StateMutation> mutations,
Dialogue's state boundary, condition adapter, and command request protocol.
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
@ Float
@ String
@ Array
@ Object
void set(const std::string &key, StateValue v)
Insert or replace key; only valid on objects.
Definition StateValue.cpp:64
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:87
static Value string(std::string value)
Compatibility factory for a string value.
Definition Value.h:110
@ String
@ Array
@ Object
@ Null
@ Bool
@ Double
@ Int64
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
Definition Value.h:104
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:124
Explain one condition evaluation in a UI- and log-friendly form.
Definition Condition.h:129
static ConditionResult failed(ConditionReasonCode reason, Value evidence={}, Value details=Value::Object{})
Construct a rejected result with a stable reason and explanation.
Definition Condition.cpp:137
static Condition hasAttribute(std::string attribute)
Require an attribute to exist.
Definition Condition.cpp:173
static Condition all(std::vector< Condition > children)
Construct a conjunction of child conditions.
Definition Condition.cpp:141
static Condition not_(Condition child)
Construct a logical negation of one child condition.
Definition Condition.cpp:153
static Condition stateEquals(std::string key, Value expected)
Require a named state value to equal the expected value.
Definition Condition.cpp:185
static Condition policyCall(std::string name, Value arguments=Value::Object{}, std::optional< ScriptConditionDeclaration > scriptDeclaration=std::nullopt)
Call a named read-only policy and use its ConditionResult.
Definition Condition.cpp:198
static Condition compare(std::string key, CompareOperator op, Value expected)
Compare a context value against an expected scalar value.
Definition Condition.cpp:159
static Condition authorityCheck(std::string scope)
Require read-only authority for a scope.
Definition Condition.cpp:192
static Condition any(std::vector< Condition > children)
Construct a disjunction of child conditions.
Definition Condition.cpp:147
std::optional< eve::Value > value(std::string_view key) const
Query a canonical world value without creating a local copy in Dialogue.
Definition DialogueState.cpp:307
eve::Result< eve::decision::Condition > compileCondition(const eve::Value &specification) const
Compile a canonical condition specification to decision::Condition.
Definition DialogueState.cpp:332
DialogueStateContext(std::string subject={})
Construct a context for one stable world subject.
Definition DialogueState.cpp:297
eve::Result< eve::MutationReceipt > apply(std::span< const eve::StateMutation > mutations, const eve::MutationContext &context) const
Apply a complete mutation set through one authoritative provider.
Definition DialogueState.cpp:353
eve::decision::ConditionResult evaluate(const eve::decision::Condition &condition) const
Evaluate an already compiled shared condition with explanation.
Definition DialogueState.cpp:336
std::optional< eve::Value > state(std::string_view key) const
Query one persistent state value.
Definition DialogueState.cpp:327
std::optional< eve::Value > resource(std::string_view key) const
Query one resource value.
Definition DialogueState.cpp:322
std::optional< bool > hasTag(std::string_view tag) const
Query exact world tag membership.
Definition DialogueState.cpp:312
std::optional< eve::Value > attribute(std::string_view key) const
Query one attribute or reputation value.
Definition DialogueState.cpp:317
void setSubject(std::string subject)
Set the subject used for all future condition queries.
Definition DialogueState.cpp:299
const std::string & subject() const noexcept
Return the currently selected subject id.
Definition DialogueState.h:147
Decision EvaluationContext backed by one dialogue subject.
Definition DialogueState.h:86
std::optional< eve::decision::ConditionResult > policy(std::string_view name, const eve::Value &arguments) const override
Evaluate a named read-only policy with owned arguments.
Definition DialogueState.cpp:291
std::optional< bool > authority(std::string_view scope) const override
Query authority without changing grants, leases, or state.
Definition DialogueState.cpp:285
std::optional< eve::Value > resource(std::string_view key) const override
Query a resource amount or resource marker.
Definition DialogueState.cpp:271
std::optional< eve::Value > state(std::string_view key) const override
Query a state value for StateEquals nodes.
Definition DialogueState.cpp:277
std::optional< eve::Value > value(std::string_view key) const override
Query a named scalar or structured value for Compare nodes.
Definition DialogueState.cpp:251
std::optional< eve::Value > attribute(std::string_view key) const override
Query an attribute value; nullopt means the attribute is absent.
Definition DialogueState.cpp:263
void setSubject(std::string subject)
Change the subject used by subsequent synchronous queries.
Definition DialogueState.cpp:249
std::optional< bool > hasTag(std::string_view tag) const override
Query tag membership; nullopt means the tag source is unavailable.
Definition DialogueState.cpp:257
StateEvaluationContext(std::string subject={}, eve::IStateQuery *provider=nullptr)
Construct a context for a stable subject id and optional provider.
Definition DialogueState.cpp:246
All-or-nothing mutation boundary owned by the consumer.
Definition StateAccess.h:107
virtual eve::Result< MutationReceipt > apply(std::span< const StateMutation > mutations, const MutationContext &context)=0
Apply a complete mutation set atomically.
Read-only world-state boundary owned by consumers such as Dialogue.
Definition StateAccess.h:79
virtual std::optional< eve::Value > state(std::string_view subject, std::string_view key) const =0
Query a persistent/world state value.
virtual std::optional< bool > hasTag(std::string_view subject, std::string_view tag) const =0
Query exact tag membership.
virtual std::optional< eve::Value > resource(std::string_view subject, std::string_view key) const =0
Query a resource value or marker.
virtual std::optional< bool > authority(std::string_view subject, std::string_view scope) const =0
Query read-only authority for a scope.
virtual std::optional< eve::Value > value(std::string_view subject, std::string_view key) const =0
Query a generic world value.
virtual std::optional< eve::Value > attribute(std::string_view subject, std::string_view key) const =0
Query a numeric or structured attribute.
@ NotEqual
@ GreaterEqual
@ LessEqual
@ InvalidCondition
Definition ConversationAuthoring.cpp:12
eve::Value toCanonicalValue(const eve::StateValue &value)
Convert the legacy reload value into the canonical common value.
Definition DialogueState.cpp:203
eve::StateValue toDialogueStateValue(const eve::Value &value)
Convert a canonical value to the legacy reload representation.
Definition DialogueState.cpp:225
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Definition ArtifactProvider.cpp:20
WidgetDesc child(std::string id, std::vector< WidgetDesc > children, float width, float height)
Scrollable child region with an explicit size.
Definition Widget.cpp:635
@ InvalidArgument
@ Unsupported
Definition Container.h:602
Correlation metadata shared by a mutation transaction.
Definition StateAccess.h:57