载入中...
搜索中...
未找到
DialogueState.cpp
浏览该文件的文档.
15std::optional<T> queryProviders(const std::string& subject, eve::IStateQuery* explicitProvider, Query&& query) {
33eve::Result<eve::condition::Condition> conditionError(std::string message, std::string path = {}) {
35 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, std::move(message), std::move(path)));
86 return eve::Result<eve::condition::Condition>::success(eve::condition::Condition::all(std::move(children)));
88 if (!specification.isObject()) return conditionError("dialogue condition must be an object or array");
99 return eve::Result<eve::condition::Condition>::success(eve::condition::Condition::all(std::move(children)));
110 return eve::Result<eve::condition::Condition>::success(eve::condition::Condition::any(std::move(children)));
123 return eve::Result<eve::condition::Condition>::success(eve::condition::tagPresent(tag->asString()));
128 if (!authority->isString()) return conditionError("authority condition requires a string scope", "authority");
129 return eve::Result<eve::condition::Condition>::success(eve::condition::authorityAllow(authority->asString()));
135 if (!policy->isString()) return conditionError("policy condition requires a string name", "policy");
147 return eve::Result<eve::condition::Condition>::success(eve::condition::attributeExists(state->asString()));
163 if (op == "has") return eve::Result<eve::condition::Condition>::success(eve::condition::attributeExists(key));
168 if (!readOperator(op, parsed)) return conditionError("unknown condition operator: " + op, "op");
176 return eve::Result<eve::condition::Condition>::success(eve::condition::attributeExists(attribute->asString()));
180 if (!readString(*state, "key", key)) return conditionError("state condition is missing key", "state.key");
184 return eve::Result<eve::condition::Condition>::success(eve::condition::stateEquals(std::move(key), *expected));
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)));
225eve::StateValue toDialogueStateValue(const eve::Value& value) { return eve::toLegacyStateValue(value); }
236 [&](eve::IStateQuery* provider, const std::string& subject) { return provider->hasTag(subject, *tag); });
247 [&](eve::IStateQuery* provider, const std::string& subject) { return provider->value(subject, *attr); });
258 [&](eve::IStateQuery* provider, const std::string& subject) { return provider->state(subject, *state); });
262 [&](eve::IStateQuery* provider, const std::string& subject) { return provider->value(subject, *state); });
264 return queryProviders<eve::Value>(subject_, provider_, [&](eve::IStateQuery* provider, const std::string& subject) {
269std::optional<eve::condition::ConditionResult> StateEvaluationContext::policy(std::string_view name,
271 if (auto authority = eve::condition::resolveAuthorityAllow(name, arguments, [this](std::string_view scope) {
283DialogueStateContext::DialogueStateContext(std::string subject) : subject_(std::move(subject)) {}
320eve::Result<eve::condition::Condition> DialogueStateContext::compileCondition(const eve::Value& specification) const {
324eve::condition::ConditionResult DialogueStateContext::evaluate(const eve::condition::Condition& condition) const {
329eve::condition::ConditionResult DialogueStateContext::evaluate(const eve::Value& specification) const {
342eve::Result<eve::MutationReceipt> DialogueStateContext::apply(std::span<const eve::StateMutation> mutations,
Canonical Compare key prefixes and PolicyCall names for thin conditions.
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={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
@ Float
@ String
@ Array
@ Object
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:207
static Value string(std::string value)
Compatibility factory for a string value.
Definition Value.h:121
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
Definition Value.h:115
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:244
Explain one condition evaluation in a UI- and log-friendly form.
Definition Condition.h:137
static ConditionResult failed(ConditionReasonCode reason, Value evidence={}, Value details=Value::Object{})
Construct a rejected result with a stable reason and explanation.
Definition Condition.cpp:135
static Condition compare(std::string key, CompareOperator op, Value expected={})
Compare a context value against an expected scalar value.
Definition Condition.cpp:157
static Condition any(std::vector< Condition > children)
Construct a disjunction of child conditions.
Definition Condition.cpp:145
static Condition all(std::vector< Condition > children)
Construct a conjunction of child conditions.
Definition Condition.cpp:139
static Condition not_(Condition child)
Construct a logical negation of one child condition.
Definition Condition.cpp:151
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:165
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:293
eve::Result< eve::condition::Condition > compileCondition(const eve::Value &specification) const
Compile a canonical condition specification to condition::Condition.
Definition DialogueState.cpp:320
DialogueStateContext(std::string subject={})
Construct a context for one stable world subject.
Definition DialogueState.cpp:283
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:342
eve::condition::ConditionResult evaluate(const eve::condition::Condition &condition) const
Evaluate an already compiled shared condition with explanation.
Definition DialogueState.cpp:324
std::optional< eve::Value > state(std::string_view key) const
Query one persistent state value.
Definition DialogueState.cpp:314
std::optional< eve::Value > resource(std::string_view key) const
Query one resource value.
Definition DialogueState.cpp:310
std::optional< bool > hasTag(std::string_view tag) const
Query exact world tag membership.
Definition DialogueState.cpp:298
std::optional< eve::Value > attribute(std::string_view key) const
Query one attribute or reputation value.
Definition DialogueState.cpp:304
void setSubject(std::string subject)
Set the subject used for all future condition queries.
Definition DialogueState.cpp:285
const std::string & subject() const noexcept
Return the currently selected subject id.
Definition DialogueState.h:132
Decision EvaluationContext backed by one dialogue subject.
Definition DialogueState.h:86
std::optional< eve::Value > value(std::string_view key) const override
Query a named scalar or structured value for Compare nodes.
Definition DialogueState.cpp:232
void setSubject(std::string subject)
Change the subject used by subsequent synchronous queries.
Definition DialogueState.cpp:230
std::optional< eve::condition::ConditionResult > policy(std::string_view name, const eve::Value &arguments) const override
Evaluate a named read-only policy with owned arguments.
Definition DialogueState.cpp:269
StateEvaluationContext(std::string subject={}, eve::IStateQuery *provider=nullptr)
Construct a context for a stable subject id and optional provider.
Definition DialogueState.cpp:227
All-or-nothing mutation boundary owned by the consumer.
Definition StateAccess.h:107
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.
Condition stateEquals(std::string name, Value expected)
Compare that a state key equals an expected value.
Definition ConditionKeys.h:123
std::string resourceKey(std::string_view name)
Build a resource:<name> Compare key.
Definition ConditionKeys.h:59
@ InvalidCondition
Condition attributeExists(std::string name)
Compare that an attribute key exists (attr:<name> Exists).
Definition ConditionKeys.h:106
constexpr std::string_view kResourcePrefix
Prefix for resource values (resource:<name>).
Definition ConditionKeys.h:25
constexpr std::string_view kStatePrefix
Prefix for state values (state:<name>).
Definition ConditionKeys.h:27
constexpr std::string_view kTagPrefix
Prefix for tag membership booleans (tag:<name>).
Definition ConditionKeys.h:21
std::optional< ConditionResult > resolveAuthorityAllow(std::string_view name, const Value &arguments, AuthorityQuery &&authorityQuery)
Resolve the built-in authority.allow policy when name matches.
Definition ConditionKeys.h:158
Condition tagPresent(std::string tag)
Compare that a tag key is present (tag:<name> == true).
Definition ConditionKeys.h:98
std::string stateKey(std::string_view name)
Build a state:<name> Compare key.
Definition ConditionKeys.h:69
std::optional< std::string_view > stripPrefix(std::string_view key, std::string_view prefix)
Strip a known domain prefix from a key.
Definition ConditionKeys.h:89
constexpr std::string_view kAttrPrefix
Prefix for attribute values (attr:<name>).
Definition ConditionKeys.h:23
std::string attrKey(std::string_view name)
Build an attr:<name> Compare key.
Definition ConditionKeys.h:49
@ GreaterEqual
@ LessEqual
Condition authorityAllow(std::string scope)
PolicyCall for read-only authority (authority.allow).
Definition ConditionKeys.h:131
std::string tagKey(std::string_view tag)
Build a tag:<name> Compare key.
Definition ConditionKeys.h:39
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:21
ShapeState * child(const JPH::Body &body, const JPH::SubShapeID &id)
Resolves a native child record for a synchronous callback or query. @ownership Borrowed from the worl...
Definition JoltInternal.h:138
@ InvalidArgument
@ Unsupported
StateValue toLegacyStateValue(const Value &value)
Project a canonical value into the legacy reload snapshot format.
Definition StateValue.cpp:60
Definition Container.h:602
Correlation metadata shared by a mutation transaction.
Definition StateAccess.h:57