Files
DeepSeek-Reasonix/internal/transcript/message.go
T
SivanCola 65067d2bbd Fix compaction ownership, cancellation, and durable operation recovery
Problem: manual compaction could appear stuck, ignore Stop, lose its outcome after reload, or overlap other foreground work. Automatic recovery could install a projection after cancellation.

Root cause: maintenance bypassed shared runtime ownership and turn-independent persistence; client history and snapshots lacked consistent operation ordering.

Fix: centralize maintenance admission, cancellation, commit fencing, durable lifecycle records, and queue handoff. Reconcile versioned operation cards across desktop, remote, and CLI; classify empty history safely and preserve recovery details.

Verification: root and Desktop Go suites, deterministic maintenance regressions, focused Go race tests, frontend typechecks, transcript tests, production build, contract checks, and Chromium interaction/scroll benchmarks passed. Updated English and Chinese behavior documentation.
2026-09-21 02:44:15 +08:00

116 lines
6.7 KiB
Go

// Package transcript owns the display projection shared by local and remote sessions.
// Its records are never used to construct provider requests.
package transcript
import (
"reasonix/internal/event"
"reasonix/internal/eventwire"
"reasonix/internal/provider"
)
type Message struct {
RecordID string `json:"recordId,omitempty"`
AttemptID string `json:"attemptId,omitempty"`
SubmissionID string `json:"submissionId,omitempty"`
Source string `json:"source,omitempty"`
MessageID string `json:"messageId,omitempty"`
CompletionReceipt *eventwire.CompletionReceipt `json:"completionReceipt,omitempty"`
CompletionSummary *eventwire.CompletionSummary `json:"completionSummary,omitempty"`
TurnID string `json:"turnId,omitempty"`
Role string `json:"role"`
Content string `json:"content"`
Detail string `json:"detail,omitempty"`
Code string `json:"code,omitempty"`
SubmitText string `json:"submitText,omitempty"`
CheckpointTurn *int `json:"checkpointTurn,omitempty"`
HistoryTurn int `json:"historyTurn,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
MemoryCitations []provider.MemoryCitation `json:"memoryCitations,omitempty"`
WorkDurationMs int64 `json:"workDurationMs,omitempty"`
// TurnDurationMs and TurnUsage are display-only, per-turn facts used by the
// chat footer. They never participate in provider messages or prompt caches.
TurnDurationMs int64 `json:"turnDurationMs,omitempty"`
TurnUsage *TurnUsage `json:"turnUsage,omitempty"`
Level string `json:"level,omitempty"`
ToolCalls []ToolCall `json:"toolCalls,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolResultArchived bool `json:"toolResultArchived,omitempty"`
ToolResultError string `json:"toolResultError,omitempty"`
// Execution is local shell metadata restored onto ToolCards after history
// reload. Omitted when absent so older frontends ignore it safely.
Execution *provider.ToolExecution `json:"execution,omitempty"`
PresentedFiles []provider.PresentedFile `json:"presentedFiles,omitempty"`
Pending bool `json:"pending,omitempty"`
Trigger string `json:"trigger,omitempty"`
Messages int `json:"messages,omitempty"`
Summary string `json:"summary,omitempty"`
Archive string `json:"archive,omitempty"`
OperationID string `json:"operationId,omitempty"`
OperationRevision uint64 `json:"operationRevision,omitempty"`
RuntimeEpoch string `json:"runtimeEpoch,omitempty"`
OperationKind string `json:"operationKind,omitempty"`
OperationStatus string `json:"operationStatus,omitempty"`
OperationActivity string `json:"operationActivity,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
Applied bool `json:"applied,omitempty"`
InputTokens int `json:"inputTokens,omitempty"`
ResultTokens int `json:"resultTokens,omitempty"`
DecisionReceipt *provider.DecisionReceipt `json:"decisionReceipt,omitempty"`
Readiness *event.FinalReadiness `json:"readiness,omitempty"`
ReadPause *provider.ReadPause `json:"readPause,omitempty"`
ReadCompletion *provider.ReadCompletion `json:"readCompletion,omitempty"`
ProtocolRecovery *provider.ProtocolRecoveryAction `json:"protocolRecovery,omitempty"`
Diagnostic *provider.FailureDiagnostic `json:"diagnostic,omitempty"`
ServerSearch []provider.ServerSearchCall `json:"serverSearch,omitempty"`
// Attachments are display-only facts for admitted session images. They never
// participate in provider requests; the frontend loads bytes through a
// digest-only session read authorized from this session's content graph.
Attachments []Attachment `json:"attachments,omitempty"`
}
// Attachment is the history-card identity of one admitted image. Digest is the
// SHA-256 of the original bytes; clients must not supply size or index fields.
type Attachment struct {
Kind string `json:"kind,omitempty"`
Digest string `json:"digest,omitempty"`
Name string `json:"name,omitempty"`
MIME string `json:"mime,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Bytes int64 `json:"bytes,omitempty"`
}
// TurnUsage is the exact sum of the usage events emitted during one UI turn.
// CacheReadTokens is present whenever at least one usage event was observed;
// zero is therefore a reported value rather than an unknown value.
type TurnUsage struct {
UncachedInputTokens int `json:"uncachedInputTokens"`
OutputTokens int `json:"outputTokens"`
TotalTokens int `json:"totalTokens"`
CacheReadTokens *int `json:"cacheReadTokens,omitempty"`
ReasoningTokens *int `json:"reasoningTokens,omitempty"`
Routes []string `json:"routes,omitempty"`
}
type ToolCall struct {
Partial bool `json:"partial,omitempty"`
ArgChars int `json:"argChars,omitempty"`
Pending bool `json:"pending,omitempty"`
ParentID string `json:"parentId,omitempty"`
StartedAt int64 `json:"startedAt,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Arguments string `json:"arguments"`
ResolvedName string `json:"resolvedName,omitempty"`
CapabilityID string `json:"capabilityId,omitempty"`
ResolvedReadOnly *bool `json:"resolvedReadOnly,omitempty"`
Subject string `json:"subject,omitempty"`
Summary string `json:"summary,omitempty"`
Diff string `json:"diff,omitempty"`
Added int `json:"added,omitempty"`
Removed int `json:"removed,omitempty"`
ArgumentsArchived bool `json:"argumentsArchived,omitempty"`
}