message

package
v0.1.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const InterruptWithoutMessage = "__nexus_interrupt_without_message__"

InterruptWithoutMessage 表示用户主动停止但不需要把默认停止文案写入结果正文。

View Source
const SystemMessageSubtypeGuidedInput = "guided_input"

Variables

This section is empty.

Functions

func AssistantHasCountedToolProgress added in v0.1.15

func AssistantHasCountedToolProgress(message protocol.Message) bool

AssistantHasCountedToolProgress 判断 assistant 快照里是否包含应计为 Goal 进展的工具完成。

func AssistantMissedGoalCompletionTool added in v0.1.15

func AssistantMissedGoalCompletionTool(message protocol.Message) bool

AssistantMissedGoalCompletionTool 判断 assistant 是否声称目标已完成,但把 Goal 完成工具误判为不可用。

func AttachResultSummary added in v0.1.2

func AttachResultSummary(assistant protocol.Message, result protocol.Message) (protocol.Message, bool)

AttachResultSummary 把 runtime result 摘要挂到 assistant 上。

func BuildAssistantResultSummary added in v0.1.2

func BuildAssistantResultSummary(result protocol.Message, assistantText string) map[string]any

BuildAssistantResultSummary 只保留 assistant 终态需要的结果摘要。

func BuildSyntheticAssistantFromResult added in v0.1.2

func BuildSyntheticAssistantFromResult(result protocol.Message) protocol.Message

BuildSyntheticAssistantFromResult 在没有 assistant 可挂时构造一个终态 assistant。

func CanonicalToolName added in v0.1.15

func CanonicalToolName(name string) string

CanonicalToolName 把 SDK/MCP 展示名规整为模型工具短名。

func ExtractAssistantDisplayText added in v0.1.2

func ExtractAssistantDisplayText(message protocol.Message) string

ExtractAssistantDisplayText 提取 assistant 主正文文本,用于去重 result 文本。

func IsInternalTranscriptInterruptPrompt added in v0.1.2

func IsInternalTranscriptInterruptPrompt(content string) bool

IsInternalTranscriptInterruptPrompt 判断是否为 SDK 内部注入的中断哨兵文案。

func NewGuidedInputMessage added in v0.1.2

func NewGuidedInputMessage(input GuidedInputMessageInput) protocol.Message

NewGuidedInputMessage 构造不会进入普通用户气泡的引导消息。

func NormalizeDisplayText added in v0.1.2

func NormalizeDisplayText(value string) string

NormalizeDisplayText 统一正文比较用的文本格式。

func NormalizeInterruptedOutput

func NormalizeInterruptedOutput(output *Output, interruptReason string)

NormalizeInterruptedOutput 统一把“用户主动停止后 SDK 仍返回 error”的结果收口成 interrupted。

func NormalizeResultSubtype added in v0.1.2

func NormalizeResultSubtype(subtype string) string

NormalizeResultSubtype 统一 result subtype。

func ProjectResultMessage added in v0.1.2

func ProjectResultMessage(assistant protocol.Message, result protocol.Message) protocol.Message

ProjectResultMessage 把 result 投影成前端统一使用的 assistant 终态形态。

Types

type AssistantSegment

type AssistantSegment struct {
	// contains filtered or unexported fields
}

AssistantSegment 维护单段 assistant 输出状态。

func (*AssistantSegment) AppendTaskProgress

func (s *AssistantSegment) AppendTaskProgress(block map[string]any)

AppendTaskProgress 追加或更新任务进度块。

func (*AssistantSegment) AppendToolResults

func (s *AssistantSegment) AppendToolResults(content []map[string]any)

AppendToolResults 追加工具结果块。

func (*AssistantSegment) ApplyBlock

func (s *AssistantSegment) ApplyBlock(index int, block map[string]any) int

ApplyBlock 按索引设置内容块。

func (*AssistantSegment) ApplyDelta

func (s *AssistantSegment) ApplyDelta(index int, delta map[string]any) (int, bool)

ApplyDelta 应用流式增量。

func (*AssistantSegment) BuildAssistantMessage

func (s *AssistantSegment) BuildAssistantMessage(ctx MessageContext, sessionID string, isComplete bool) map[string]any

BuildAssistantMessage 构建 assistant 消息。

func (*AssistantSegment) CurrentBlock

func (s *AssistantSegment) CurrentBlock(index int) map[string]any

CurrentBlock 返回指定索引的当前块。

func (*AssistantSegment) EnsureStarted

func (s *AssistantSegment) EnsureStarted()

EnsureStarted 确保段已经初始化。

func (*AssistantSegment) FindToolName

func (s *AssistantSegment) FindToolName(toolUseID string) string

FindToolName 根据 tool_use_id 在已累积的 content 中反查工具名称。

func (*AssistantSegment) FindToolUse added in v0.1.6

func (s *AssistantSegment) FindToolUse(toolUseID string) map[string]any

FindToolUse 返回指定 tool_use 的完整内容块。

func (*AssistantSegment) HasContent

func (s *AssistantSegment) HasContent() bool

HasContent 表示当前段是否已有内容。

func (*AssistantSegment) HasToolUse added in v0.1.3

func (s *AssistantSegment) HasToolUse(toolUseID string) bool

HasToolUse 表示当前段是否包含指定工具调用。

func (*AssistantSegment) IsStarted

func (s *AssistantSegment) IsStarted() bool

IsStarted 表示当前段是否已经初始化。

func (*AssistantSegment) MessageID

func (s *AssistantSegment) MessageID() string

MessageID 返回当前 assistant message_id。

func (*AssistantSegment) Model

func (s *AssistantSegment) Model() string

Model 返回当前段 model。

func (*AssistantSegment) ReplaceFromSnapshot

func (s *AssistantSegment) ReplaceFromSnapshot(content []map[string]any, model string, usage map[string]any, stopReason string)

ReplaceFromSnapshot 用 SDK assistant 快照补齐当前段。

func (*AssistantSegment) Reset

func (s *AssistantSegment) Reset()

Reset 重置当前段。

func (*AssistantSegment) Start

func (s *AssistantSegment) Start(messageID string, model string, usage map[string]any, timestamp int64)

Start 开始新的 assistant 段。

func (*AssistantSegment) StopReason

func (s *AssistantSegment) StopReason() string

StopReason 返回当前 stop_reason。

func (*AssistantSegment) UpdateMeta

func (s *AssistantSegment) UpdateMeta(model string, usage map[string]any, stopReason string)

UpdateMeta 更新消息级元信息。

func (*AssistantSegment) Usage

func (s *AssistantSegment) Usage() map[string]any

Usage 返回 usage 快照。

type EventMapResult added in v0.1.2

type EventMapResult struct {
	Events          []protocol.EventMessage
	DurableMessages []protocol.Message
	TerminalStatus  string
	ResultSubtype   string
}

EventMapResult 表示一次 SDK 消息映射后的事件与持久消息。

type EventMapper added in v0.1.2

type EventMapper struct {
	// contains filtered or unexported fields
}

EventMapper 基于统一 Processor 生成场景化 protocol event。

func NewEventMapper added in v0.1.2

func NewEventMapper(options EventMapperOptions) *EventMapper

NewEventMapper 创建通用 SDK 消息映射器。

func (*EventMapper) CurrentMessageID added in v0.1.2

func (m *EventMapper) CurrentMessageID() string

CurrentMessageID 返回当前 assistant message_id。

func (*EventMapper) LastAssistantMessage added in v0.1.2

func (m *EventMapper) LastAssistantMessage() protocol.Message

LastAssistantMessage 返回最近一条 assistant 快照。

func (*EventMapper) Map added in v0.1.2

func (m *EventMapper) Map(incoming sdkprotocol.ReceivedMessage, interruptReason ...string) (EventMapResult, error)

Map 将一条 SDK 消息映射为 protocol event 与 durable message。

func (*EventMapper) ProjectResultMessage added in v0.1.2

func (m *EventMapper) ProjectResultMessage(message protocol.Message) protocol.Message

ProjectResultMessage 将 result 投影回最近一条 assistant 快照。

func (*EventMapper) SessionID added in v0.1.2

func (m *EventMapper) SessionID() string

SessionID 返回当前 SDK session_id。

type EventMapperOptions added in v0.1.2

type EventMapperOptions struct {
	Context                MessageContext
	InitialSessionID       string
	IncludeStreamLifecycle bool
}

EventMapperOptions 描述 SDK 消息到 Nexus 事件的映射策略。

type GuidedInputMessageInput added in v0.1.2

type GuidedInputMessageInput struct {
	MessageID      string
	SessionKey     string
	RoomID         string
	ConversationID string
	AgentID        string
	RoundID        string
	SourceRoundID  string
	Content        string
	SessionID      string
	Timestamp      int64
}

GuidedInputMessageInput 描述一条运行中 round 的用户引导消息。

type MessageContext

type MessageContext struct {
	SessionKey     string
	RoomID         string
	ConversationID string
	AgentID        string
	WorkspacePath  string
	RoundID        string
	AgentRoundID   string
	ParentID       string
}

MessageContext 表示单轮消息处理上下文。

type Output

type Output struct {
	StreamEvents        []StreamPayload
	DurableMessages     []protocol.Message
	EphemeralMessages   []protocol.Message
	RegisteredSessionID string
	TerminalStatus      string
	ResultSubtype       string
	StreamStarted       bool
	AssistantCompleted  bool
	Err                 error
}

Output 表示处理单条 SDK 消息后的统一输出。

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor 负责把 SDK 消息转换成统一协议语义。

func NewProcessor

func NewProcessor(ctx MessageContext, sessionID string) *Processor

NewProcessor 创建统一消息处理器。

func (*Processor) CurrentMessageID

func (p *Processor) CurrentMessageID() string

CurrentMessageID 返回当前 assistant message_id。

func (*Processor) Process

func (p *Processor) Process(message sdkprotocol.ReceivedMessage) Output

Process 处理一条 SDK 消息。

func (*Processor) SessionID

func (p *Processor) SessionID() string

SessionID 返回当前 SDK session_id。

type StreamPayload

type StreamPayload struct {
	MessageID string
	Data      map[string]any
}

StreamPayload 表示统一 stream 数据。

type ToolResultObservation added in v0.1.15

type ToolResultObservation struct {
	ToolUseID string
	ToolName  string
	ErrorCode string
	IsError   bool
}

ToolResultObservation 表示 assistant 快照中一次已物化的工具结果。

func AssistantToolResults added in v0.1.15

func AssistantToolResults(message protocol.Message) []ToolResultObservation

AssistantToolResults 从 assistant 快照里提取 tool_result,并用同快照中的 tool_use 补齐工具名。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL