Skip to content

Commit 4db4e35

Browse files
committed
Merge branch 'feature/defining-chat-agent' into develop
2 parents 43cfbe4 + 7c849a1 commit 4db4e35

35 files changed

Lines changed: 1680 additions & 1152 deletions

Core/Sources/ChatGPTChatTab/Chat.swift

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,7 @@ struct Chat {
343343
}
344344
}(),
345345
text: message.summary ?? message.content ?? "",
346-
references: message.references.map {
347-
.init(
348-
title: $0.title,
349-
subtitle: $0.subTitle,
350-
uri: $0.uri,
351-
startLine: $0.startLine,
352-
kind: $0.kind
353-
)
354-
}
346+
references: message.references.map(convertReference)
355347
))
356348

357349
for call in message.toolCalls ?? [] {
@@ -513,3 +505,48 @@ private actor TimedDebounceFunction {
513505
}
514506
}
515507

508+
private func convertReference(
509+
_ reference: ChatMessage.Reference
510+
) -> DisplayedChatMessage.Reference {
511+
.init(
512+
title: reference.title,
513+
subtitle: {
514+
switch reference.kind {
515+
case let .symbol(_, uri, _, _):
516+
return uri
517+
case let .webpage(uri):
518+
return uri
519+
case let .textFile(uri):
520+
return uri
521+
case let .other(kind):
522+
return kind
523+
case .text:
524+
return reference.content
525+
}
526+
}(),
527+
uri: {
528+
switch reference.kind {
529+
case let .symbol(_, uri, _, _):
530+
return uri
531+
case let .webpage(uri):
532+
return uri
533+
case let .textFile(uri):
534+
return uri
535+
case .other:
536+
return ""
537+
case .text:
538+
return ""
539+
}
540+
}(),
541+
startLine: {
542+
switch reference.kind {
543+
case let .symbol(_, _, startLine, _):
544+
return startLine
545+
default:
546+
return nil
547+
}
548+
}(),
549+
kind: reference.kind
550+
)
551+
}
552+

Core/Sources/ChatGPTChatTab/ChatPanel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ struct ChatPanel_Preview: PreviewProvider {
504504
subtitle: "Hi Hi Hi Hi",
505505
uri: "https://google.com",
506506
startLine: nil,
507-
kind: .class
507+
kind: .symbol(.class, uri: "https://google.com", startLine: nil, endLine: nil)
508508
),
509509
]
510510
),

Core/Sources/ChatGPTChatTab/Views/BotMessage.swift

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,37 @@ struct ReferenceIcon: View {
139139
RoundedRectangle(cornerRadius: 4)
140140
.fill({
141141
switch kind {
142-
case .class:
143-
Color.purple
144-
case .struct:
145-
Color.purple
146-
case .enum:
147-
Color.purple
148-
case .actor:
149-
Color.purple
150-
case .protocol:
151-
Color.purple
152-
case .extension:
153-
Color.indigo
154-
case .case:
155-
Color.green
156-
case .property:
157-
Color.teal
158-
case .typealias:
159-
Color.orange
160-
case .function:
161-
Color.teal
162-
case .method:
163-
Color.blue
142+
case .symbol(let symbol, _, _, _):
143+
switch symbol {
144+
case .class:
145+
Color.purple
146+
case .struct:
147+
Color.purple
148+
case .enum:
149+
Color.purple
150+
case .actor:
151+
Color.purple
152+
case .protocol:
153+
Color.purple
154+
case .extension:
155+
Color.indigo
156+
case .case:
157+
Color.green
158+
case .property:
159+
Color.teal
160+
case .typealias:
161+
Color.orange
162+
case .function:
163+
Color.teal
164+
case .method:
165+
Color.blue
166+
}
164167
case .text:
165168
Color.gray
166169
case .webpage:
167170
Color.blue
171+
case .textFile:
172+
Color.gray
168173
case .other:
169174
Color.gray
170175
}
@@ -173,34 +178,39 @@ struct ReferenceIcon: View {
173178
.overlay(alignment: .center) {
174179
Group {
175180
switch kind {
176-
case .class:
177-
Text("C")
178-
case .struct:
179-
Text("S")
180-
case .enum:
181-
Text("E")
182-
case .actor:
183-
Text("A")
184-
case .protocol:
185-
Text("Pr")
186-
case .extension:
187-
Text("Ex")
188-
case .case:
189-
Text("K")
190-
case .property:
191-
Text("P")
192-
case .typealias:
193-
Text("T")
194-
case .function:
195-
Text("𝑓")
196-
case .method:
197-
Text("M")
181+
case .symbol(let symbol, _, _, _):
182+
switch symbol {
183+
case .class:
184+
Text("C")
185+
case .struct:
186+
Text("S")
187+
case .enum:
188+
Text("E")
189+
case .actor:
190+
Text("A")
191+
case .protocol:
192+
Text("Pr")
193+
case .extension:
194+
Text("Ex")
195+
case .case:
196+
Text("K")
197+
case .property:
198+
Text("P")
199+
case .typealias:
200+
Text("T")
201+
case .function:
202+
Text("𝑓")
203+
case .method:
204+
Text("M")
205+
}
198206
case .text:
199207
Text("Tx")
200208
case .webpage:
201209
Text("Wb")
202210
case .other:
203211
Text("Ot")
212+
case .textFile:
213+
Text("Tx")
204214
}
205215
}
206216
.font(.system(size: 12).monospaced())
@@ -225,7 +235,7 @@ struct ReferenceIcon: View {
225235
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
226236
uri: "https://google.com",
227237
startLine: nil,
228-
kind: .class
238+
kind: .symbol(.class, uri: "https://google.com", startLine: nil, endLine: nil)
229239
), count: 20),
230240
chat: .init(initialState: .init(), reducer: { Chat(service: .init()) })
231241
)
@@ -240,43 +250,42 @@ struct ReferenceIcon: View {
240250
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
241251
uri: "https://google.com",
242252
startLine: nil,
243-
kind: .class
253+
kind: .symbol(.class, uri: "https://google.com", startLine: nil, endLine: nil)
244254
),
245255
.init(
246256
title: "BotMessage.swift:100-102",
247257
subtitle: "/Core/Sources/ChatGPTChatTab/Views",
248258
uri: "https://google.com",
249259
startLine: nil,
250-
kind: .struct
260+
kind: .symbol(.struct, uri: "https://google.com", startLine: nil, endLine: nil)
251261
),
252262
.init(
253263
title: "ReferenceList",
254264
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
255265
uri: "https://google.com",
256266
startLine: nil,
257-
kind: .function
267+
kind: .symbol(.function, uri: "https://google.com", startLine: nil, endLine: nil)
258268
),
259269
.init(
260270
title: "ReferenceList",
261271
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
262272
uri: "https://google.com",
263273
startLine: nil,
264-
kind: .case
274+
kind: .symbol(.case, uri: "https://google.com", startLine: nil, endLine: nil)
265275
),
266276
.init(
267277
title: "ReferenceList",
268278
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
269279
uri: "https://google.com",
270280
startLine: nil,
271-
kind: .extension
281+
kind: .symbol(.extension, uri: "https://google.com", startLine: nil, endLine: nil)
272282
),
273283
.init(
274284
title: "ReferenceList",
275285
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
276286
uri: "https://google.com",
277287
startLine: nil,
278-
kind: .webpage
288+
kind: .webpage(uri: "https://google.com")
279289
),
280290
], chat: .init(initialState: .init(), reducer: { Chat(service: .init()) }))
281291
}
282-

Core/Sources/ChatPlugin/AITerminalChatPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ public actor AITerminalChatPlugin: ChatPlugin {
66
public static var command: String { "airun" }
77
public nonisolated var name: String { "AI Terminal" }
88

9-
let chatGPTService: any ChatGPTServiceType
9+
let chatGPTService: any LegacyChatGPTServiceType
1010
var terminal: TerminalType = Terminal()
1111
var isCancelled = false
1212
weak var delegate: ChatPluginDelegate?
1313
var isStarted = false
1414
var command: String?
1515

16-
public init(inside chatGPTService: any ChatGPTServiceType, delegate: ChatPluginDelegate) {
16+
public init(inside chatGPTService: any LegacyChatGPTServiceType, delegate: ChatPluginDelegate) {
1717
self.chatGPTService = chatGPTService
1818
self.delegate = delegate
1919
}

Core/Sources/ChatPlugin/AskChatGPT.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public func askChatGPT(
1414
configuration: configuration,
1515
functionProvider: NoChatGPTFunctionProvider()
1616
)
17-
let service = ChatGPTService(
17+
let service = LegacyChatGPTService(
1818
memory: memory,
1919
configuration: configuration
2020
)

Core/Sources/ChatPlugin/CallAIFunction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func callAIFunction(
1818
let argsString = args.joined(separator: ", ")
1919
let configuration = UserPreferenceChatGPTConfiguration()
2020
.overriding(.init(temperature: 0))
21-
let service = ChatGPTService(
21+
let service = LegacyChatGPTService(
2222
memory: AutoManagedChatGPTMemory(
2323
systemPrompt: "You are now the following python function: ```# \(description)\n\(function)```\n\nOnly respond with your `return` value.",
2424
configuration: configuration,

Core/Sources/ChatPlugin/ChatPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public protocol ChatPlugin: AnyObject {
66
static var command: String { get }
77
var name: String { get }
88

9-
init(inside chatGPTService: any ChatGPTServiceType, delegate: ChatPluginDelegate)
9+
init(inside chatGPTService: any LegacyChatGPTServiceType, delegate: ChatPluginDelegate)
1010
func send(content: String, originalMessage: String) async
1111
func cancel() async
1212
func stopResponding() async

Core/Sources/ChatPlugin/TerminalChatPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public actor TerminalChatPlugin: ChatPlugin {
77
public static var command: String { "run" }
88
public nonisolated var name: String { "Terminal" }
99

10-
let chatGPTService: any ChatGPTServiceType
10+
let chatGPTService: any LegacyChatGPTServiceType
1111
var terminal: TerminalType = Terminal()
1212
var isCancelled = false
1313
weak var delegate: ChatPluginDelegate?
1414

15-
public init(inside chatGPTService: any ChatGPTServiceType, delegate: ChatPluginDelegate) {
15+
public init(inside chatGPTService: any LegacyChatGPTServiceType, delegate: ChatPluginDelegate) {
1616
self.chatGPTService = chatGPTService
1717
self.delegate = delegate
1818
}

Core/Sources/ChatPlugins/MathChatPlugin/MathChatPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ public actor MathChatPlugin: ChatPlugin {
77
public static var command: String { "math" }
88
public nonisolated var name: String { "Math" }
99

10-
let chatGPTService: any ChatGPTServiceType
10+
let chatGPTService: any LegacyChatGPTServiceType
1111
var isCancelled = false
1212
weak var delegate: ChatPluginDelegate?
1313

14-
public init(inside chatGPTService: any ChatGPTServiceType, delegate: ChatPluginDelegate) {
14+
public init(inside chatGPTService: any LegacyChatGPTServiceType, delegate: ChatPluginDelegate) {
1515
self.chatGPTService = chatGPTService
1616
self.delegate = delegate
1717
}

Core/Sources/ChatPlugins/SearchChatPlugin/SearchChatPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public actor SearchChatPlugin: ChatPlugin {
66
public static var command: String { "search" }
77
public nonisolated var name: String { "Search" }
88

9-
let chatGPTService: any ChatGPTServiceType
9+
let chatGPTService: any LegacyChatGPTServiceType
1010
var isCancelled = false
1111
weak var delegate: ChatPluginDelegate?
1212

13-
public init(inside chatGPTService: any ChatGPTServiceType, delegate: ChatPluginDelegate) {
13+
public init(inside chatGPTService: any LegacyChatGPTServiceType, delegate: ChatPluginDelegate) {
1414
self.chatGPTService = chatGPTService
1515
self.delegate = delegate
1616
}

0 commit comments

Comments
 (0)