dify/dify-agent-runtime/internal/server/runtime.go
Yunlu Wen 302d7b1e1b
feat(agent): shellctl rewritten in go (#38841)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-15 01:58:36 +00:00

36 lines
870 B
Go

package server
import (
"crypto/rand"
"encoding/hex"
"fmt"
"time"
)
// GenerateJobID produces a short random hex job identifier.
func GenerateJobID() string {
b := make([]byte, 8)
_, _ = rand.Read(b)
return hex.EncodeToString(b)
}
// FormatTimestamp returns an ISO-8601 UTC timestamp string.
func FormatTimestamp(t time.Time) string {
return t.UTC().Truncate(time.Second).Format("2006-01-02T15:04:05Z")
}
// ParseTimestamp parses an ISO-8601 UTC timestamp.
func ParseTimestamp(s string) (time.Time, error) {
return time.Parse("2006-01-02T15:04:05Z", s)
}
// JobSessionName returns the tmux session name for a job.
func JobSessionName(jobID string) string {
return fmt.Sprintf("shellctl-%s", jobID)
}
// JobPaneTarget returns the tmux pane target for a job.
func JobPaneTarget(jobID string) string {
return fmt.Sprintf("%s:0.0", JobSessionName(jobID))
}