mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(context): migrate running flow context to source/status/info model, and update related modules
This commit is contained in:
@@ -51,10 +51,9 @@ object AgentRuntime {
|
||||
for (modules in runningModules.values) {
|
||||
executeOrder(modules, runningFlowContext)
|
||||
}
|
||||
runningFlowContext.ok = 1
|
||||
} catch (e: Exception) {
|
||||
runningFlowContext.ok = 0
|
||||
runningFlowContext.errMsg.add(e.localizedMessage)
|
||||
runningFlowContext.status.ok = false
|
||||
runningFlowContext.status.errMsg.add(e.localizedMessage)
|
||||
}
|
||||
|
||||
return runningFlowContext
|
||||
|
||||
@@ -1,18 +1,63 @@
|
||||
package work.slhaf.partner.api.agent.runtime.interaction.flow;
|
||||
package work.slhaf.partner.api.agent.runtime.interaction.flow
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import work.slhaf.partner.api.common.entity.PersistableObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.alibaba.fastjson2.JSONObject
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 流程上下文
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public abstract class RunningFlowContext extends PersistableObject {
|
||||
protected int ok;
|
||||
protected List<String> errMsg = new ArrayList<>();
|
||||
abstract class RunningFlowContext {
|
||||
/**
|
||||
* 消息来源: 由谁发出
|
||||
*/
|
||||
abstract val source: String
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
abstract val input: String
|
||||
|
||||
/**
|
||||
* 消息回应对象,默认与 source 一致
|
||||
*/
|
||||
var target = source
|
||||
|
||||
private val _additionalUserInfo = mutableMapOf<String, String>()
|
||||
val additionalUserInfo: Map<String, String>
|
||||
get() = _additionalUserInfo
|
||||
|
||||
val status = Status()
|
||||
val info = Info()
|
||||
|
||||
fun putUserInfo(key: String, value: String) {
|
||||
_additionalUserInfo[key] = value
|
||||
}
|
||||
|
||||
fun putUserInfo(key: String, value: Any) {
|
||||
_additionalUserInfo[key] = try {
|
||||
JSONObject.toJSONString(value)
|
||||
} catch (e: Exception) {
|
||||
value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
class Info {
|
||||
val uuid = UUID.randomUUID().toString()
|
||||
val dateTime: LocalDateTime = ZonedDateTime.now().toLocalDateTime()
|
||||
}
|
||||
|
||||
class Status {
|
||||
/**
|
||||
* 本次 runningFlow 是否正常执行
|
||||
*/
|
||||
val ok: Boolean
|
||||
get() = errors.isEmpty()
|
||||
|
||||
/**
|
||||
* 本次执行时收集到的异常信息
|
||||
*/
|
||||
var errors = mutableListOf<String>()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user