trail-it/moonstream/session does not have a README file

    SessionError

    pub(all) suberror SessionError {
    UnknownCall(key~ : CallKey)
    CallIdConflict(key~ : CallKey, existing~ : String, incoming~ : String)
    CallNameConflict(key~ : CallKey, existing~ : String, incoming~ : String)
    InvalidLimits(error~ :
    ParseError
    )
    ParseFailed(key~ : CallKey, error~ :
    ParseError
    )
    } derive(Eq, ToJson,
    Debug
    )

    路由层面的错误。适配层应当把它们当作"输入流组织方式不对"来报告, 而不是当作模型输出不合法。

    CallKey

    pub(all) struct CallKey {
    response : String
    choice : Int
    index : Int
    } derive(Eq, ToJson,
    Debug
    )

    一个 tool call 的稳定复合键。

    只用 index 不够:同一响应里不同 choice 可以各有 index 0,不同响应也会重号。

    CallKey::new

    fn CallKey::new(response? : String, choice? : Int, index? : Int) -> CallKey

    Session

    pub struct Session {
    inner : SessionState
    }

    多 tool call 会话。

    Session::call_count

    fn Session::call_count(self : Session) -> Int

    已注册调用的数量(含已结束的)。

    Session::call_id

    fn Session::call_id(self : Session, key : CallKey) -> String?

    该调用已知的 id。

    Session::call_name

    fn Session::call_name(self : Session, key : CallKey) -> String?

    该调用已知的函数名。

    Session::calls

    fn Session::calls(self : Session) -> Array[CallKey]

    全部已注册的调用键(含已结束的),按注册顺序。

    Session::failure

    返回使该调用终止的原始解析错误。

    Session::feed

    fn Session::feed(self : Session, key : CallKey, bytes : Bytes) -> Array[
    Event
    ] raise SessionError

    把一段参数片段交给该调用自己的解析器。

    Session::finish

    结束该调用,返回它的收尾事件与结果。其它调用不受影响。

    Session::is_failed

    fn Session::is_failed(self : Session, key : CallKey) -> Bool

    该调用是否因解析错误进入不可恢复状态。

    Session::is_finished

    fn Session::is_finished(self : Session, key : CallKey) -> Bool

    该调用是否已经 finish

    Session::is_open

    fn Session::is_open(self : Session, key : CallKey) -> Bool

    该调用是否仍可继续接收输入。

    Session::new

    创建会话。限制在创建时校验,之后传给每个调用的解析器。

    限制是每个调用各自计数的max_total_bytes 约束的是单个调用的参数字节数, 不是整个会话的累计量。会话里能开多少调用由调用方自己控制。

    限制非法时抛 SessionError::InvalidLimits(本包只有一个错误通道)。

    Session::offset

    fn Session::offset(self : Session, key : CallKey) -> Int?

    该调用已经消费的字节数。

    Session::open

    fn Session::open(self : Session, key : CallKey, id? : String?, name? : String?) -> Unit raise SessionError

    注册一个调用的起始上下文。

    idname 是带默认值的标签参数,类型都是 String?,因此适配层可以直接透传 SDK 的 Option 字段:open(key, id=delta.id, name=delta.name) 重复注册同一个键是允许的(id / name 可以只在第一帧出现), 但 id 或函数名冲突会报错,避免把两个不同调用混在一起。

    Session::open_calls

    fn Session::open_calls(self : Session) -> Array[CallKey]

    仍可继续接收输入的调用键,按注册顺序;失败与已结束调用不包含在内。

    SessionState

    type SessionState

    会话的全部状态。私有实现细节,不是可用 API。

    Source Files