载入中...
搜索中...
未找到
SequenceRuntime.cpp
浏览该文件的文档.
61eve::Value captureFrame(const SequenceAsset* asset, const std::string& node, const eve::Value& bindings,
110eve::Result<void> SequenceRuntime::fail(eve::DiagnosticCode code, std::string message, std::string path) {
116void SequenceRuntime::emit(EventKind kind, const SequenceNode* node, const std::string& detail) const {
140void SequenceRuntime::unregisterCommand(std::string_view name) { commandHandlers_.erase(std::string(name)); }
145 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: bindings must be an object", "bindings");
205 if (!asset_) return fail(eve::DiagnosticCode::PreconditionViolation, "sequence: no active asset", "node");
234 eve::Diagnostic::error(eve::DiagnosticCode::Failed, outcome.error, "condition", {}, "dnut.runtime"));
251 return fail(eve::DiagnosticCode::InvariantViolation, "sequence: execution budget exceeded", "budget");
253 if (!node) return fail(eve::DiagnosticCode::InvariantViolation, "sequence: invalid execution cursor", "cursor");
319 if (const eve::Value* arguments = node->payload.find("arguments"); arguments && arguments->isObject())
343 if (const eve::Value* arguments = node->payload.find("arguments"); arguments && arguments->isObject())
399 return fail(eve::DiagnosticCode::PreconditionViolation, "sequence: runtime is not blocked", "advance");
418eve::Result<void> SequenceRuntime::select(std::string_view routeLabel) { return selectImpl(routeLabel); }
438 if (!outcome.error.empty()) return fail(eve::DiagnosticCode::Failed, outcome.error, "route.condition");
492eve::Result<void> SequenceRuntime::resumeCommand(std::string_view requestId, eve::StateValue result) {
496eve::Result<void> SequenceRuntime::resumeCommand(std::string_view requestId, eve::Value result) {
500eve::Result<void> SequenceRuntime::resumeCommandImpl(std::string_view requestId, eve::Value result) {
503 return fail(eve::DiagnosticCode::DialogueNotWaitingForCommand, "sequence: runtime is not waiting for a command",
506 return fail(eve::DiagnosticCode::Conflict, "sequence: command request id is stale or does not match",
530 return fail(eve::DiagnosticCode::Failed, error.empty() ? "sequence: command resume failed" : std::move(error),
556 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: runtime state must be an object", "state");
561 return fail(eve::DiagnosticCode::UnknownVersion, "sequence: unsupported runtime save schema or version",
565 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: runtime state is missing 'active'", "state");
576 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: runtime state is missing 'current'", "state");
580 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: saved frame is malformed", "state.current");
584 return fail(eve::DiagnosticCode::NotFound, "sequence: saved asset '" + assetId + "' is missing", "state.asset");
592 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: saved values are malformed", "state.current");
596 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: runtime state is missing 'stack'", "state");
614 return fail(eve::DiagnosticCode::Conflict, "sequence: saved call frame cannot be restored", "state.stack");
619 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: runtime state is missing 'blocked'", "state");
622 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: waitingStep is malformed", "state");
625 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: waitingCommand is malformed", "state");
628 if (!pendingRequestId || !pendingRequestId->isString() || !commandSequence || !commandSequence->isInt64() ||
630 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: pending command state is malformed", "state");
636 return fail(eve::DiagnosticCode::NotFound, "sequence: saved node '" + nodeId + "' is missing", "state.node");
639 return fail(eve::DiagnosticCode::InvalidArgument, "sequence: pending command cursor is not a command node",
660 if (const eve::Value* arguments = restoredNode->payload.find("arguments"); arguments && arguments->isObject())
Cross-frame interpreter for compiled `.dnut` sequences.
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
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:480
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
@ Float
@ String
@ Array
@ Object
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:87
std::vector< std::string > keys() const
Return object member names in deterministic order.
Definition Value.cpp:138
void set(const std::string &key, Value value)
Insert or replace an object member.
Definition Value.cpp:118
static Value string(std::string value)
Compatibility factory for a string value.
Definition Value.h:110
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:69
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
Definition Value.h:104
bool asBool() const
Return the boolean payload; the caller must have checked the kind.
Definition Value.cpp:81
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:124
eve::Result< void > runUntilBlocked()
Execute nodes until the sequence blocks, ends or fails.
Definition SequenceRuntime.cpp:240
const SequenceNode * currentNode() const
Borrowed current node, or nullptr. @lifetime Invalidated by the next transition.
Definition SequenceRuntime.cpp:74
void stop()
Stop and clear the active sequence without emitting Ended.
Definition SequenceRuntime.cpp:121
static constexpr std::string_view SaveSchema
Stable cursor save schema retained across the L1 ownership migration.
Definition SequenceRuntime.h:70
eve::Result< void > captureState(eve::Value &out) const
Capture the complete cursor, bindings, locals and call stack.
Definition SequenceRuntime.cpp:534
static constexpr std::int64_t SaveVersion
Current cursor save schema version.
Definition SequenceRuntime.h:72
static constexpr int kExecutionBudget
Upper bound on nodes executed by one runUntilBlocked call.
Definition SequenceRuntime.h:105
eve::Result< void > advance()
Acknowledge a host-presented wait or handler-less Await step.
Definition SequenceRuntime.cpp:396
@ NodeEntered
eve::Result< void > resumeCommand(std::string_view requestId, eve::StateValue result)
Resume the exact blocked command with a legacy state value.
Definition SequenceRuntime.cpp:492
eve::Result< void > start(const SequenceAsset *asset, eve::Value bindings=eve::Value::Object{})
Begin a sequence at the asset entry node.
Definition SequenceRuntime.cpp:142
void unregisterCommand(std::string_view name)
Remove a named generic command handler.
Definition SequenceRuntime.cpp:140
void registerCommand(std::string name, SequenceCommandHandler handler)
Register a named generic command handler.
Definition SequenceRuntime.cpp:136
eve::Result< void > resumeStep(eve::Value result)
Resume a step whose handler returned Blocked.
Definition SequenceRuntime.cpp:465
const SequenceAsset * asset() const
Borrowed active asset, or nullptr. @lifetime Owned by the caller of start.
Definition SequenceRuntime.h:218
const eve::Value & bindings() const
Definition SequenceRuntime.h:222
eve::Result< void > selectRouteForTransaction(std::string_view routeLabel)
Enter one already prepared choice route transactionally.
Definition SequenceRuntime.cpp:420
eve::Result< void > select(std::string_view routeLabel)
Answer a blocked choice node by route label.
Definition SequenceRuntime.cpp:418
eve::Result< void > restoreState(const eve::Value &in)
Restore a captured cursor through the configured asset resolver.
Definition SequenceRuntime.cpp:554
StepOutcome dispatch(const SequenceNode &node, const StepContext &context) const
Route one already validated node to its handler.
Definition StepKindRegistry.cpp:150
eve::Value toCanonicalValue(const eve::StateValue &value)
Convert the legacy reload value into the canonical common value.
Definition DialogueState.cpp:203
Definition ConversationDialect.cpp:13
@ Blocked
@ Failed
const char * sequenceParameterTypeName(SequenceParameterType type) noexcept
Return the stable lowercase spelling of a parameter type.
Definition SequenceAsset.cpp:18
SequenceParameterType
Declared value kind for one sequence invocation parameter.
Definition SequenceAsset.h:18
std::function< SequenceCommandResponse(const SequenceCommandRequest &)> SequenceCommandHandler
Synchronous owner-thread handler for one command request.
Definition SequenceRuntime.h:54
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Definition ArtifactProvider.cpp:20
@ InvalidArgument
@ NotFound
@ UnknownVersion
@ PreconditionViolation
@ DialogueNotWaitingForCommand
Dialogue runner is not positioned at an asynchronous command.
@ InvariantViolation
@ Failed
@ Conflict
@ Applied
Definition Container.h:602
Immutable, parameterized and versioned compiled sequence.
Definition SequenceAsset.h:77
eve::Result< void > validate() const
Validate stable identifiers, the entry point and every graph reference.
Definition SequenceAsset.cpp:36
const SequenceNode * findNode(const std::string &nodeId) const noexcept
Find one node by its stable identifier.
Definition SequenceAsset.cpp:29
std::vector< SequenceParameter > parameters
Definition SequenceAsset.h:82
Immutable request emitted by a generic command node.
Definition SequenceRuntime.h:33
Outcome of one authored condition, as seen by the language core.
Definition SequenceRuntime.h:24
std::string error
Evaluation failure; non-empty means no route may be selected.
Definition SequenceRuntime.h:29
std::string reason
Stable machine-readable reason; empty when passed is true.
Definition SequenceRuntime.h:27