2026-06-12 13:33:12 +02:00
|
|
|
package chatd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"database/sql"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"charm.land/fantasy"
|
|
|
|
|
|
2026-07-21 10:58:08 +02:00
|
|
|
"github.com/coder/coder/v2/coderd/x/chatd/chatloop"
|
2026-06-12 13:33:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type runnerActionKind string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
runnerActionKindEnterRequiresAction runnerActionKind = "enter_requires_action"
|
|
|
|
|
runnerActionKindFinishTurn runnerActionKind = "finish_turn"
|
|
|
|
|
runnerActionKindFinishError runnerActionKind = "finish_error"
|
|
|
|
|
runnerActionKindFinishInterruption runnerActionKind = "finish_interruption"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// stepData is the durable content produced by one provider attempt.
|
|
|
|
|
type stepData struct {
|
2026-07-06 11:57:12 +01:00
|
|
|
Content []fantasy.Content
|
|
|
|
|
Usage fantasy.Usage
|
|
|
|
|
ContextLimit sql.NullInt64
|
|
|
|
|
Runtime time.Duration
|
2026-06-12 13:33:12 +02:00
|
|
|
|
2026-08-25 16:40:41 +07:00
|
|
|
// BatchRuntime is the local-tool batch window. Model steps use Runtime.
|
|
|
|
|
BatchRuntime time.Duration
|
|
|
|
|
// BatchBilledCalls counts the calls whose intervals produced
|
|
|
|
|
// BatchRuntime. Audit metadata for the batch usage record.
|
|
|
|
|
BatchBilledCalls int
|
|
|
|
|
|
2026-06-12 13:33:12 +02:00
|
|
|
ToolCallCreatedAt map[string]time.Time
|
|
|
|
|
ToolResultCreatedAt map[string]time.Time
|
|
|
|
|
ReasoningStartedAt []time.Time
|
|
|
|
|
ReasoningCompletedAt []time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pendingDynamicToolCall describes a dynamic tool call parked for a user.
|
|
|
|
|
type pendingDynamicToolCall struct {
|
|
|
|
|
ToolCallID string
|
|
|
|
|
ToolName string
|
|
|
|
|
Args string
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-06 16:09:38 +07:00
|
|
|
// compactionOutcome contains a generated context summary. It must stay
|
|
|
|
|
// field-compatible with chatloop.CompactionResult; generateCompaction
|
|
|
|
|
// converts between the two directly.
|
2026-06-12 13:33:12 +02:00
|
|
|
type compactionOutcome struct {
|
|
|
|
|
SystemSummary string
|
|
|
|
|
SummaryReport string
|
2026-07-21 10:58:08 +02:00
|
|
|
Source chatloop.CompactionSource
|
2026-06-12 13:33:12 +02:00
|
|
|
ThresholdPercent int32
|
|
|
|
|
UsagePercent float64
|
|
|
|
|
ContextTokens int64
|
|
|
|
|
ContextLimit int64
|
2026-08-06 16:09:38 +07:00
|
|
|
Runtime time.Duration
|
2026-06-12 13:33:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type compactionStatus int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
compactionStatusNotNeeded compactionStatus = iota
|
|
|
|
|
compactionStatusNeeded
|
|
|
|
|
compactionStatusAfterCompaction
|
|
|
|
|
compactionStatusStillOverLimit
|
|
|
|
|
)
|