mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 20:10:42 +00:00
Add shared native chat handling for /new, /reset, and /clear. This also aligns main session key handling in the shared chat UI and includes follow-up test and CI fixes needed to keep the branch mergeable. Co-authored-by: Nachx639 <71144023+Nachx639@users.noreply.github.com> Co-authored-by: Luke <92253590+ImLukeF@users.noreply.github.com>
94 lines
2.7 KiB
Swift
94 lines
2.7 KiB
Swift
import Foundation
|
|
|
|
public struct OpenClawChatModelChoice: Identifiable, Codable, Sendable, Hashable {
|
|
public var id: String { self.selectionID }
|
|
|
|
public let modelID: String
|
|
public let name: String
|
|
public let provider: String
|
|
public let contextWindow: Int?
|
|
|
|
public init(modelID: String, name: String, provider: String, contextWindow: Int?) {
|
|
self.modelID = modelID
|
|
self.name = name
|
|
self.provider = provider
|
|
self.contextWindow = contextWindow
|
|
}
|
|
|
|
/// Provider-qualified model ref used for picker identity and selection tags.
|
|
public var selectionID: String {
|
|
let trimmedProvider = self.provider.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !trimmedProvider.isEmpty else { return self.modelID }
|
|
let providerPrefix = "\(trimmedProvider)/"
|
|
if self.modelID.hasPrefix(providerPrefix) {
|
|
return self.modelID
|
|
}
|
|
return "\(trimmedProvider)/\(self.modelID)"
|
|
}
|
|
|
|
public var displayLabel: String {
|
|
self.selectionID
|
|
}
|
|
}
|
|
|
|
public struct OpenClawChatSessionsDefaults: Codable, Sendable {
|
|
public let model: String?
|
|
public let contextTokens: Int?
|
|
public let mainSessionKey: String?
|
|
|
|
public init(model: String?, contextTokens: Int?, mainSessionKey: String? = nil) {
|
|
self.model = model
|
|
self.contextTokens = contextTokens
|
|
self.mainSessionKey = mainSessionKey
|
|
}
|
|
}
|
|
|
|
public struct OpenClawChatSessionEntry: Codable, Identifiable, Sendable, Hashable {
|
|
public var id: String { self.key }
|
|
|
|
public let key: String
|
|
public let kind: String?
|
|
public let displayName: String?
|
|
public let surface: String?
|
|
public let subject: String?
|
|
public let room: String?
|
|
public let space: String?
|
|
public let updatedAt: Double?
|
|
public let sessionId: String?
|
|
|
|
public let systemSent: Bool?
|
|
public let abortedLastRun: Bool?
|
|
public let thinkingLevel: String?
|
|
public let verboseLevel: String?
|
|
|
|
public let inputTokens: Int?
|
|
public let outputTokens: Int?
|
|
public let totalTokens: Int?
|
|
|
|
public let modelProvider: String?
|
|
public let model: String?
|
|
public let contextTokens: Int?
|
|
}
|
|
|
|
public struct OpenClawChatSessionsListResponse: Codable, Sendable {
|
|
public let ts: Double?
|
|
public let path: String?
|
|
public let count: Int?
|
|
public let defaults: OpenClawChatSessionsDefaults?
|
|
public let sessions: [OpenClawChatSessionEntry]
|
|
|
|
public init(
|
|
ts: Double?,
|
|
path: String?,
|
|
count: Int?,
|
|
defaults: OpenClawChatSessionsDefaults?,
|
|
sessions: [OpenClawChatSessionEntry])
|
|
{
|
|
self.ts = ts
|
|
self.path = path
|
|
self.count = count
|
|
self.defaults = defaults
|
|
self.sessions = sessions
|
|
}
|
|
}
|