Skip to content

Commit

Permalink
Merge branch 'release/0.26.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
intitni committed Oct 22, 2023
2 parents 3a08d0e + f9d2241 commit cd41739
Show file tree
Hide file tree
Showing 34 changed files with 567 additions and 187 deletions.
9 changes: 7 additions & 2 deletions Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ let isProIncluded: Bool = {
return false
}
do {
if let content = String(
data: try Data(contentsOf: confURL),
if let content = try String(
data: Data(contentsOf: confURL),
encoding: .utf8
) {
if content.hasPrefix("YES") {
Expand Down Expand Up @@ -98,6 +98,9 @@ let package = Package(
url: "https://github.com/pointfreeco/swift-composable-architecture",
from: "0.55.0"
),
// quick hack to support custom UserDefaults
// https://github.com/sindresorhus/KeyboardShortcuts
.package(url: "https://github.com/intitni/KeyboardShortcuts", branch: "main"),
].pro,
targets: [
// MARK: - Main
Expand Down Expand Up @@ -134,6 +137,7 @@ let package = Package(
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "KeyboardShortcuts", package: "KeyboardShortcuts"),
].pro([
"ProService",
])
Expand Down Expand Up @@ -168,6 +172,7 @@ let package = Package(
.product(name: "OpenAIService", package: "Tool"),
.product(name: "Preferences", package: "Tool"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "KeyboardShortcuts", package: "KeyboardShortcuts"),
].pro([
"ProHostApp",
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public final class SystemInfoChatContextCollector: ChatContextCollector {
) -> ChatContext {
return .init(
systemPrompt: """
Current Time: \(
Self.dateFormatter.string(from: Date())
) (You can use it to calculate time in another time zone)
""",
## System Info
Current Time: \(
Self.dateFormatter.string(from: Date())
) (You can use it to calculate time in another time zone)
""",
retrievedContent: [],
functions: []
)
Expand Down
11 changes: 11 additions & 0 deletions Core/Sources/ChatGPTChatTab/ChatGPTChatTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public class ChatGPTChatTab: ChatTab {
ChatTabItemView(chat: chat)
}

public func buildIcon() -> any View {
WithViewStore(chat, observe: \.isReceivingMessage) { viewStore in
if viewStore.state {
Image(systemName: "ellipsis.message")
} else {
Image(systemName: "message")
}
}
}

public func buildMenu() -> any View {
ChatContextMenu(store: chat.scope(state: \.chatMenu, action: Chat.Action.chatMenu))
}
Expand Down Expand Up @@ -125,3 +135,4 @@ public class ChatGPTChatTab: ChatTab {
}.store(in: &cancellable)
}
}

1 change: 1 addition & 0 deletions Core/Sources/ChatGPTChatTab/ChatPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ struct ChatPanelMessages: View {
.foregroundStyle(.secondary)
.padding(4)
}
.keyboardShortcut(.downArrow, modifiers: [.command])
.opacity(pinnedToBottom ? 0 : 1)
.buttonStyle(.plain)
.onChange(of: viewStore.state) { _ in
Expand Down
11 changes: 9 additions & 2 deletions Core/Sources/ChatService/CustomCommandTemplateProcessor.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import AppKit
import Foundation
import SuggestionModel
import XcodeInspector

struct CustomCommandTemplateProcessor {
func process(_ text: String) -> String {
public struct CustomCommandTemplateProcessor {
public init() {}

public func process(_ text: String) -> String {
let info = getEditorInformation()
let editorContent = info.editorContent
let updatedText = text
Expand All @@ -22,6 +25,10 @@ struct CustomCommandTemplateProcessor {
of: "{{active_editor_file_name}}",
with: info.documentURL?.lastPathComponent ?? ""
)
.replacingOccurrences(
of: "{{clipboard}}",
with: NSPasteboard.general.string(forType: .string) ?? ""
)
return updatedText
}

Expand Down
35 changes: 6 additions & 29 deletions Core/Sources/ChatService/DynamicContextController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ChatContextCollector
import Foundation
import OpenAIService
import Parsing
import Preferences
import XcodeInspector

Expand Down Expand Up @@ -65,17 +64,17 @@ final class DynamicContextController {
}
return contexts
}

let extraSystemPrompt = contexts
.map(\.systemPrompt)
.filter { !$0.isEmpty }
.joined(separator: "\n")
.joined(separator: "\n\n")

let contextPrompts = contexts
.flatMap(\.retrievedContent)
.filter { !$0.content.isEmpty }
.sorted { $0.priority > $1.priority }

let contextualSystemPrompt = """
\(language.isEmpty ? "" : "You must always reply in \(language)")
\(systemPrompt)\(extraSystemPrompt.isEmpty ? "" : "\n\(extraSystemPrompt)")
Expand All @@ -88,30 +87,8 @@ final class DynamicContextController {

extension DynamicContextController {
static func parseScopes(_ prompt: inout String) -> Set<String> {
guard !prompt.isEmpty else { return [] }
do {
let parser = Parse {
"@"
Many {
Prefix { $0.isLetter }
} separator: {
"+"
} terminator: {
" "
}
Skip {
Many {
" "
}
}
Rest()
}
let (scopes, rest) = try parser.parse(prompt)
prompt = String(rest)
return Set(scopes.map(String.init))
} catch {
return []
}
let parser = MessageScopeParser()
return parser(&prompt)
}
}

14 changes: 13 additions & 1 deletion Core/Sources/HostApp/GeneralView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Client
import ComposableArchitecture
import KeyboardShortcuts
import LaunchAgentManager
import Preferences
import SwiftUI
Expand Down Expand Up @@ -224,6 +225,8 @@ struct GeneralSettingsView: View {
var preferWidgetToStayInsideEditorWhenWidthGreaterThan
@AppStorage(\.hideCircularWidget)
var hideCircularWidget
@AppStorage(\.showHideWidgetShortcutGlobally)
var showHideWidgetShortcutGlobally
}

@StateObject var settings = Settings()
Expand Down Expand Up @@ -286,6 +289,15 @@ struct GeneralSettingsView: View {
Text("pt")
}

KeyboardShortcuts.Recorder("Hotkey to Toggle Widgets", name: .showHideWidget) { _ in
// It's not used in this app!
KeyboardShortcuts.disable(.showHideWidget)
}

Toggle(isOn: $settings.showHideWidgetShortcutGlobally) {
Text("Enable the Hotkey Globally")
}

Toggle(isOn: $settings.hideCircularWidget) {
Text("Hide circular widget")
}
Expand Down Expand Up @@ -342,7 +354,7 @@ struct LargeIconPicker<
}
}
}

var body: some View {
if #available(macOS 13.0, *) {
LabeledContent {
Expand Down
25 changes: 18 additions & 7 deletions Core/Sources/HostApp/HostApp.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Client
import ComposableArchitecture
import Foundation
import KeyboardShortcuts

#if canImport(LicenseManagement)
import LicenseManagement
#endif

extension KeyboardShortcuts.Name {
static let showHideWidget = Self("ShowHideWidget")
}

struct HostApp: ReducerProtocol {
struct State: Equatable {
var general = General.State()
Expand All @@ -22,16 +27,20 @@ struct HostApp: ReducerProtocol {
}

@Dependency(\.toast) var toast

init() {
KeyboardShortcuts.userDefaults = .shared
}

var body: some ReducerProtocol<State, Action> {
Scope(state: \.general, action: /Action.general) {
General()
}

Scope(state: \.chatModelManagement, action: /Action.chatModelManagement) {
ChatModelManagement()
}

Scope(state: \.embeddingModelManagement, action: /Action.embeddingModelManagement) {
EmbeddingModelManagement()
}
Expand All @@ -40,7 +49,7 @@ struct HostApp: ReducerProtocol {
switch action {
case .appear:
return .none

case .informExtensionServiceAboutLicenseKeyChange:
#if canImport(LicenseManagement)
return .run { _ in
Expand All @@ -55,13 +64,13 @@ struct HostApp: ReducerProtocol {
#else
return .none
#endif

case .general:
return .none

case .chatModelManagement:
return .none

case .embeddingModelManagement:
return .none
}
Expand All @@ -70,8 +79,8 @@ struct HostApp: ReducerProtocol {
}

import Dependencies
import Preferences
import Keychain
import Preferences

struct UserDefaultsDependencyKey: DependencyKey {
static var liveValue: UserDefaultsType = UserDefaults.shared
Expand All @@ -80,6 +89,7 @@ struct UserDefaultsDependencyKey: DependencyKey {
it.removePersistentDomain(forName: "HostAppPreview")
return it
}()

static var testValue: UserDefaultsType = {
let it = UserDefaults(suiteName: "HostAppTest")!
it.removePersistentDomain(forName: "HostAppTest")
Expand All @@ -106,3 +116,4 @@ extension DependencyValues {
set { self[APIKeyKeychainDependencyKey.self] = newValue }
}
}

1 change: 1 addition & 0 deletions Core/Sources/Service/GUI/ChatTabFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum ChatTabFactory {
),
title: BrowserChatTab.name
),
folderIfNeeded(TerminalChatTab.chatBuilders(), title: TerminalChatTab.name),
].compactMap { $0 }

return collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ extension ChatTabPool {
externalDependency: ChatTabFactory.externalDependenciesForBrowserChatTab()
) else { break }
return await createTab(id: data.id, from: builder)
case TerminalChatTab.name:
guard let builder = try? await TerminalChatTab.restore(
from: data.data,
externalDependency: ()
) else { break }
return await createTab(id: data.id, from: builder)
default:
break
}
Expand All @@ -397,7 +403,7 @@ extension ChatTabPool {
) else {
return nil
}
return await createTab(from: builder)
return await createTab(id: data.id, from: builder)
}
#endif
}
Expand Down
Loading

0 comments on commit cd41739

Please sign in to comment.