summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-12 13:01:59 -0500
committeradamdottv <[email protected]>2025-05-12 13:01:59 -0500
commit8270a1e4b133b44b4b68c8b52567200fc69343e6 (patch)
tree73369cc977081f3b5c60d14d27a75aa6149fae4d
parent7f9c992993b56c0c3f2895632d81b64f209a4d94 (diff)
downloadopencode-8270a1e4b133b44b4b68c8b52567200fc69343e6.tar.gz
opencode-8270a1e4b133b44b4b68c8b52567200fc69343e6.zip
chore: cleanup
-rw-r--r--internal/history/history.go19
-rw-r--r--internal/logging/logging.go2
-rw-r--r--internal/message/message.go45
-rw-r--r--internal/session/session.go4
4 files changed, 20 insertions, 50 deletions
diff --git a/internal/history/history.go b/internal/history/history.go
index 807b0e75b..4a72cb043 100644
--- a/internal/history/history.go
+++ b/internal/history/history.go
@@ -323,7 +323,6 @@ func (s *service) Delete(ctx context.Context, id string) error {
return nil
}
-// getServiceForPublish is an internal helper for Delete
func (s *service) getServiceForPublish(ctx context.Context, id string) (*File, error) {
// Assumes outer lock is NOT held or caller manages it.
// For GetFile, it has its own RLock.
@@ -368,45 +367,55 @@ func (s *service) fromDBItem(item db.File) File {
Path: item.Path,
Content: item.Content,
Version: item.Version,
- CreatedAt: item.CreatedAt * 1000, // DB stores seconds, Go struct uses milliseconds
- UpdatedAt: item.UpdatedAt * 1000, // DB stores seconds, Go struct uses milliseconds
+ CreatedAt: item.CreatedAt * 1000,
+ UpdatedAt: item.UpdatedAt * 1000,
}
}
-// --- Package-Level Wrapper Functions ---
func Create(ctx context.Context, sessionID, path, content string) (File, error) {
return GetService().Create(ctx, sessionID, path, content)
}
+
func CreateVersion(ctx context.Context, sessionID, path, content string) (File, error) {
return GetService().CreateVersion(ctx, sessionID, path, content)
}
+
func Get(ctx context.Context, id string) (File, error) {
return GetService().Get(ctx, id)
}
+
func GetByPathAndVersion(ctx context.Context, sessionID, path, version string) (File, error) {
return GetService().GetByPathAndVersion(ctx, sessionID, path, version)
}
+
func GetLatestByPathAndSession(ctx context.Context, path, sessionID string) (File, error) {
return GetService().GetLatestByPathAndSession(ctx, path, sessionID)
}
+
func ListBySession(ctx context.Context, sessionID string) ([]File, error) {
return GetService().ListBySession(ctx, sessionID)
}
+
func ListLatestSessionFiles(ctx context.Context, sessionID string) ([]File, error) {
return GetService().ListLatestSessionFiles(ctx, sessionID)
}
+
func ListVersionsByPath(ctx context.Context, path string) ([]File, error) {
return GetService().ListVersionsByPath(ctx, path)
}
+
func Update(ctx context.Context, file File) (File, error) {
return GetService().Update(ctx, file)
}
+
func Delete(ctx context.Context, id string) error {
return GetService().Delete(ctx, id)
}
+
func DeleteSessionFiles(ctx context.Context, sessionID string) error {
return GetService().DeleteSessionFiles(ctx, sessionID)
}
-func SubscribeToEvents(ctx context.Context) <-chan pubsub.Event[File] {
+
+func Subscribe(ctx context.Context) <-chan pubsub.Event[File] {
return GetService().Subscribe(ctx)
}
diff --git a/internal/logging/logging.go b/internal/logging/logging.go
index 850fd85d6..54f33989f 100644
--- a/internal/logging/logging.go
+++ b/internal/logging/logging.go
@@ -165,7 +165,7 @@ func ListAll(ctx context.Context, limit int) ([]Log, error) {
return GetService().ListAll(ctx, limit)
}
-func SubscribeToEvents(ctx context.Context) <-chan pubsub.Event[Log] {
+func Subscribe(ctx context.Context) <-chan pubsub.Event[Log] {
return GetService().Subscribe(ctx)
}
diff --git a/internal/message/message.go b/internal/message/message.go
index 417121750..4c6726ca1 100644
--- a/internal/message/message.go
+++ b/internal/message/message.go
@@ -286,53 +286,14 @@ func (s *service) fromDBItem(item db.Message) (Message, error) {
return Message{}, fmt.Errorf("unmarshallParts for message ID %s: %w. Raw parts: %s", item.ID, err, item.Parts)
}
- // DB stores created_at, updated_at, finished_at as Unix seconds.
- // Go struct Message stores them as Unix milliseconds.
- createdAtMillis := item.CreatedAt * 1000
- updatedAtMillis := item.UpdatedAt * 1000
-
msg := Message{
ID: item.ID,
SessionID: item.SessionID,
Role: MessageRole(item.Role),
Parts: parts,
Model: models.ModelID(item.Model.String),
- CreatedAt: createdAtMillis,
- UpdatedAt: updatedAtMillis,
- }
-
- // Ensure Finish part in msg.Parts reflects the item.FinishedAt state
- // if item.FinishedAt is the source of truth for the "overall message finished time".
- // The `unmarshallParts` should already create a Finish part if it's in the JSON.
- // This logic reconciles the DB column with the JSON parts.
- var existingFinishPart *Finish
- var finishPartIndex = -1
-
- for i, p := range msg.Parts {
- if fp, ok := p.(Finish); ok {
- existingFinishPart = &fp
- finishPartIndex = i
- break
- }
- }
-
- if item.FinishedAt.Valid && item.FinishedAt.Int64 > 0 {
- dbFinishTimeMillis := item.FinishedAt.Int64 * 1000
- if existingFinishPart != nil {
- // If a Finish part exists from JSON, update its time if DB's time is different.
- // This assumes DB `finished_at` is the ultimate source of truth for when the message truly finished.
- if existingFinishPart.Time != dbFinishTimeMillis {
- slog.Debug("Aligning Finish part time with DB finished_at", "message_id", msg.ID, "json_finish_time", existingFinishPart.Time, "db_finish_time", dbFinishTimeMillis)
- existingFinishPart.Time = dbFinishTimeMillis
- msg.Parts[finishPartIndex] = *existingFinishPart
- }
- } else {
- // If no Finish part in JSON but DB says it's finished, add one.
- // We might not know the original FinishReason here, so use a sensible default or leave it to be set by Update.
- // This scenario should be less common if `Update` always ensures a Finish part for finished messages.
- slog.Debug("Synthesizing Finish part from DB finished_at", "message_id", msg.ID)
- msg.Parts = append(msg.Parts, Finish{Reason: FinishReasonEndTurn, Time: dbFinishTimeMillis})
- }
+ CreatedAt: item.CreatedAt * 1000,
+ UpdatedAt: item.UpdatedAt * 1000,
}
return msg, nil
@@ -366,7 +327,7 @@ func DeleteSessionMessages(ctx context.Context, sessionID string) error {
return GetService().DeleteSessionMessages(ctx, sessionID)
}
-func SubscribeToEvents(ctx context.Context) <-chan pubsub.Event[Message] {
+func Subscribe(ctx context.Context) <-chan pubsub.Event[Message] {
return GetService().Subscribe(ctx)
}
diff --git a/internal/session/session.go b/internal/session/session.go
index e377bfd21..c3c4cf56e 100644
--- a/internal/session/session.go
+++ b/internal/session/session.go
@@ -209,8 +209,8 @@ func (s *service) fromDBItem(item db.Session) Session {
Cost: item.Cost,
Summary: item.Summary.String,
SummarizedAt: item.SummarizedAt.Int64,
- CreatedAt: item.CreatedAt,
- UpdatedAt: item.UpdatedAt,
+ CreatedAt: item.CreatedAt * 1000,
+ UpdatedAt: item.UpdatedAt * 1000,
}
}