Skip to content

Commit b1e35f5

Browse files
committed
Replace interface{} with any everywhere.
Signed-off-by: Katharine Berry <[email protected]>
1 parent 07eb947 commit b1e35f5

File tree

14 files changed

+79
-79
lines changed

14 files changed

+79
-79
lines changed

service/assistant/assistant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (s *Service) handleQuota(rw http.ResponseWriter, r *http.Request) {
6464
return
6565
}
6666
if !userInfo.HasSubscription {
67-
response, err := json.Marshal(map[string]interface{}{
67+
response, err := json.Marshal(map[string]any{
6868
"used": 0,
6969
"remaining": 0,
7070
"hasSubscription": false,

service/assistant/functions/alarms.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ func init() {
209209
})
210210
}
211211

212-
func alarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}, requests chan<- map[string]interface{}, responses <-chan map[string]interface{}) interface{} {
212+
func alarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args any, requests chan<- map[string]any, responses <-chan map[string]any) any {
213213
ctx, span := beeline.StartSpan(ctx, "set_alarm")
214214
defer span.Send()
215215
if !query.SupportsAction(ctx, "set_alarm") {
216216
return Error{Error: "You need to update the app on your watch to set alarms."}
217217
}
218218
input := args.(*AlarmInput)
219219
log.Println("Asking watch to set an alarm...")
220-
requests <- map[string]interface{}{
220+
requests <- map[string]any{
221221
"time": input.Time,
222222
"isTimer": false,
223223
"name": input.Name,
@@ -229,7 +229,7 @@ func alarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{
229229
return resp
230230
}
231231

232-
func timerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}, requests chan<- map[string]interface{}, responses <-chan map[string]interface{}) interface{} {
232+
func timerImpl(ctx context.Context, quotaTracker *quota.Tracker, args any, requests chan<- map[string]any, responses <-chan map[string]any) any {
233233
ctx, span := beeline.StartSpan(ctx, "set_timer")
234234
defer span.Send()
235235
if !query.SupportsAction(ctx, "set_alarm") {
@@ -241,7 +241,7 @@ func timerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{
241241
if duration == 0 {
242242
return Error{Error: "You need to pass the timer duration in seconds to duration_seconds (e.g. duration_seconds=300 for a 5 minute timer)."}
243243
}
244-
requests <- map[string]interface{}{
244+
requests <- map[string]any{
245245
"duration": duration,
246246
"isTimer": true,
247247
"name": input.Name,
@@ -253,7 +253,7 @@ func timerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{
253253
return resp
254254
}
255255

256-
func alarmThought(i interface{}) string {
256+
func alarmThought(i any) string {
257257
args := i.(*AlarmInput)
258258
if args.Time == "" {
259259
return "Contemplating time"
@@ -262,7 +262,7 @@ func alarmThought(i interface{}) string {
262262
}
263263
}
264264

265-
func timerThought(i interface{}) string {
265+
func timerThought(i any) string {
266266
args := i.(*TimerInput)
267267
if args.Duration == 0 {
268268
return "Contemplating time"
@@ -271,15 +271,15 @@ func timerThought(i interface{}) string {
271271
}
272272
}
273273

274-
func deleteAlarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}, requests chan<- map[string]interface{}, responses <-chan map[string]interface{}) interface{} {
274+
func deleteAlarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args any, requests chan<- map[string]any, responses <-chan map[string]any) any {
275275
ctx, span := beeline.StartSpan(ctx, "delete_alarm")
276276
defer span.Send()
277277
if !query.SupportsAction(ctx, "set_alarm") {
278278
return Error{Error: "You need to update the app on your watch to delete alarms."}
279279
}
280280
input := args.(*DeleteAlarmInput)
281281
log.Printf("Asking watch to delete an alarm set for %s...\n", input.Time)
282-
requests <- map[string]interface{}{
282+
requests <- map[string]any{
283283
"time": input.Time,
284284
"isTimer": false,
285285
"action": "set_alarm",
@@ -290,15 +290,15 @@ func deleteAlarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args inte
290290
return resp
291291
}
292292

293-
func deleteTimerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}, requests chan<- map[string]interface{}, responses <-chan map[string]interface{}) interface{} {
293+
func deleteTimerImpl(ctx context.Context, quotaTracker *quota.Tracker, args any, requests chan<- map[string]any, responses <-chan map[string]any) any {
294294
ctx, span := beeline.StartSpan(ctx, "delete_timer")
295295
defer span.Send()
296296
if !query.SupportsAction(ctx, "set_alarm") {
297297
return Error{Error: "You need to update the app on your watch to delete timers."}
298298
}
299299
input := args.(*DeleteTimerInput)
300300
log.Printf("Asking watch to delete a timer set for %s...\n", input.Time)
301-
requests <- map[string]interface{}{
301+
requests <- map[string]any{
302302
"time": input.Time,
303303
"isTimer": true,
304304
"action": "set_alarm",
@@ -309,22 +309,22 @@ func deleteTimerImpl(ctx context.Context, quotaTracker *quota.Tracker, args inte
309309
return resp
310310
}
311311

312-
func deleteAlarmThought(i interface{}) string {
312+
func deleteAlarmThought(i any) string {
313313
return "Deleting an alarm"
314314
}
315315

316-
func deleteTimerThought(i interface{}) string {
316+
func deleteTimerThought(i any) string {
317317
return "Deleting a timer"
318318
}
319319

320-
func getAlarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}, requests chan<- map[string]interface{}, responses <-chan map[string]interface{}) interface{} {
320+
func getAlarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args any, requests chan<- map[string]any, responses <-chan map[string]any) any {
321321
ctx, span := beeline.StartSpan(ctx, "get_alarm")
322322
defer span.Send()
323323
if !query.SupportsAction(ctx, "get_alarm") {
324324
return Error{Error: "You need to update the app on your watch to get alarms."}
325325
}
326326
log.Println("Asking watch to get alarms...")
327-
requests <- map[string]interface{}{
327+
requests <- map[string]any{
328328
"isTimer": false,
329329
"action": "get_alarm",
330330
}
@@ -334,14 +334,14 @@ func getAlarmImpl(ctx context.Context, quotaTracker *quota.Tracker, args interfa
334334
return resp
335335
}
336336

337-
func getTimerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}, requests chan<- map[string]interface{}, responses <-chan map[string]interface{}) interface{} {
337+
func getTimerImpl(ctx context.Context, quotaTracker *quota.Tracker, args any, requests chan<- map[string]any, responses <-chan map[string]any) any {
338338
ctx, span := beeline.StartSpan(ctx, "get_timer")
339339
defer span.Send()
340340
if !query.SupportsAction(ctx, "get_alarm") {
341341
return Error{Error: "You need to update the app on your watch to get timers."}
342342
}
343343
log.Println("Asking watch to get alarms...")
344-
requests <- map[string]interface{}{
344+
requests <- map[string]any{
345345
"isTimer": true,
346346
"action": "get_alarm",
347347
}
@@ -351,10 +351,10 @@ func getTimerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interfa
351351
return resp
352352
}
353353

354-
func getAlarmThought(i interface{}) string {
354+
func getAlarmThought(i any) string {
355355
return "Checking your alarms"
356356
}
357357

358-
func getTimerThought(i interface{}) string {
358+
func getTimerThought(i any) string {
359359
return "Checking your timers"
360360
}

service/assistant/functions/currency.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func init() {
7171
})
7272
}
7373

74-
func convertCurrency(ctx context.Context, qt *quota.Tracker, input interface{}) interface{} {
74+
func convertCurrency(ctx context.Context, qt *quota.Tracker, input any) any {
7575
ctx, span := beeline.StartSpan(ctx, "convert_currency")
7676
defer span.Send()
7777
ccr := input.(*CurrencyConversionRequest)
@@ -106,7 +106,7 @@ func convertCurrency(ctx context.Context, qt *quota.Tracker, input interface{})
106106
}
107107
}
108108

109-
func convertCurrencyThought(i interface{}) string {
109+
func convertCurrencyThought(i any) string {
110110
args := i.(*CurrencyConversionRequest)
111111
return fmt.Sprintf("Checking the %s/%s rate...", args.From, args.To)
112112
}

service/assistant/functions/feedback.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ func init() {
5757
})
5858
}
5959

60-
func sendFeedbackImpl(ctx context.Context, quotaTracker *quota.Tracker, i interface{}, requestChan chan<- map[string]interface{}, responseChan <-chan map[string]interface{}) interface{} {
60+
func sendFeedbackImpl(ctx context.Context, quotaTracker *quota.Tracker, i any, requestChan chan<- map[string]any, responseChan <-chan map[string]any) any {
6161
args := i.(*FeedbackInput)
6262
if !args.IncludeThread && args.Feedback == "" {
6363
return Error{Error: "You need either set include_thread = true or include some feedback from the user."}
6464
}
6565
log.Printf("Asking phone to send feedback...")
66-
request := map[string]interface{}{
66+
request := map[string]any{
6767
"action": "send_feedback",
6868
"feedback": args.Feedback,
6969
}
@@ -77,7 +77,7 @@ func sendFeedbackImpl(ctx context.Context, quotaTracker *quota.Tracker, i interf
7777
return response
7878
}
7979

80-
func sendFeedbackThought(i interface{}) string {
80+
func sendFeedbackThought(i any) string {
8181
args := i.(*FeedbackInput)
8282
if args.IncludeThread && args.Feedback != "" {
8383
return "Sending conversation with feedback..."

service/assistant/functions/fixup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var valueRegexp = regexp.MustCompile(`(?m)^\s*".+?"\s*:\s*(.+?),?\s*$`)
2525
// FixupBrokenJson takes a string that is supposed to be JSON, but erroneously contains expressions where there
2626
// should be numbers, and evaluates those expressions.
2727
func FixupBrokenJson(j string) string {
28-
var throwaway interface{}
28+
var throwaway any
2929
if err := json.Unmarshal([]byte(j), &throwaway); err == nil {
3030
return j
3131
}

service/assistant/functions/functions.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
"nhooyr.io/websocket"
3030
)
3131

32-
type ToolFunction func(context.Context, *quota.Tracker, interface{}) interface{}
33-
type CallbackFunction func(context.Context, *quota.Tracker, interface{}, chan<- map[string]interface{}, <-chan map[string]interface{}) interface{}
34-
type ThoughtFunction func(interface{}) string
32+
type ToolFunction func(context.Context, *quota.Tracker, any) any
33+
type CallbackFunction func(context.Context, *quota.Tracker, any, chan<- map[string]any, <-chan map[string]any) any
34+
type ThoughtFunction func(any) string
3535

3636
const MaxResponseSize = 20000
3737

@@ -50,7 +50,7 @@ type Registration struct {
5050
RedactOutputInChatHistory bool
5151
// An instance of the object used to hold the function's parameters. This is what will be passed to
5252
// either Fn or Cb, and it will also be processed to pass to the model - including the comments.
53-
InputType interface{}
53+
InputType any
5454
// A capability the device must report for this function to be provided.
5555
Capability string
5656
// A capability the device must *not* report for this function to be provided.
@@ -97,7 +97,7 @@ func CallFunction(ctx context.Context, qt *quota.Tracker, fn, args string) (stri
9797
if _, ok := functionMap[fn]; !ok || functionMap[fn].Fn == nil {
9898
return "", fmt.Errorf("function %q not found", fn)
9999
}
100-
var result interface{}
100+
var result any
101101
in := reflect.New(reflect.TypeOf(functionMap[fn].InputType)).Interface()
102102
if err := json.Unmarshal([]byte(FixupBrokenJson(args)), in); err != nil {
103103
result = Error{"Invalid JSON: " + err.Error()}
@@ -123,12 +123,12 @@ func CallAction(ctx context.Context, qt *quota.Tracker, fn, args string, ws *web
123123
return "", fmt.Errorf("function %q not found", fn)
124124
}
125125
a := reflect.New(reflect.TypeOf(functionMap[fn].InputType)).Interface()
126-
var result interface{}
126+
var result any
127127
if err := json.Unmarshal([]byte(FixupBrokenJson(args)), &a); err != nil {
128128
result = Error{"Invalid JSON: " + err.Error()}
129129
} else {
130-
reqChan := make(chan map[string]interface{})
131-
respChan := make(chan map[string]interface{})
130+
reqChan := make(chan map[string]any)
131+
respChan := make(chan map[string]any)
132132
defer close(reqChan)
133133
defer close(respChan)
134134
ctxTimeout, cancel := context.WithTimeout(ctx, 10*time.Second)
@@ -138,7 +138,7 @@ func CallAction(ctx context.Context, qt *quota.Tracker, fn, args string, ws *web
138138
s, err := json.Marshal(req)
139139
if err != nil {
140140
log.Printf("unable to marshal request: %v", err)
141-
respChan <- map[string]interface{}{
141+
respChan <- map[string]any{
142142
"status": "error",
143143
"error": "unable to marshal request: " + err.Error(),
144144
}
@@ -147,7 +147,7 @@ func CallAction(ctx context.Context, qt *quota.Tracker, fn, args string, ws *web
147147
log.Println("Sending request to watch...")
148148
if err := ws.Write(ctxTimeout, websocket.MessageText, append([]byte("a"), s...)); err != nil {
149149
log.Printf("unable to write request: %v", err)
150-
respChan <- map[string]interface{}{
150+
respChan <- map[string]any{
151151
"status": "error",
152152
"error": "unable to write request: " + err.Error(),
153153
}
@@ -158,24 +158,24 @@ func CallAction(ctx context.Context, qt *quota.Tracker, fn, args string, ws *web
158158
log.Printf("response read: %v", string(respBytes))
159159
if err != nil {
160160
log.Printf("unable to read response: %v", err)
161-
respChan <- map[string]interface{}{
161+
respChan <- map[string]any{
162162
"status": "error",
163163
"error": "unable to read response: " + err.Error(),
164164
}
165165
continue
166166
}
167167
if messageType != websocket.MessageText {
168168
log.Printf("unexpected message type: %v", messageType)
169-
respChan <- map[string]interface{}{
169+
respChan <- map[string]any{
170170
"status": "error",
171171
"error": "unable to read response: " + err.Error(),
172172
}
173173
continue
174174
}
175-
var resp map[string]interface{}
175+
var resp map[string]any
176176
if err := json.Unmarshal(respBytes, &resp); err != nil {
177177
log.Printf("unable to unmarshal response: %v", err)
178-
respChan <- map[string]interface{}{
178+
respChan <- map[string]any{
179179
"status": "error",
180180
"error": "unable to unmarshal response: " + err.Error(),
181181
}

service/assistant/functions/locations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ func init() {
4848
})
4949
}
5050

51-
func getLocationThought(args interface{}) string {
51+
func getLocationThought(args any) string {
5252
arg := args.(*GetLocationInput)
5353
return fmt.Sprintf("Locating %q", arg.PlaceName)
5454
}
5555

56-
func getLocationImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{}) interface{} {
56+
func getLocationImpl(ctx context.Context, quotaTracker *quota.Tracker, args any) any {
5757
ctx, span := beeline.StartSpan(ctx, "get_location")
5858
defer span.Send()
5959
arg := args.(*GetLocationInput)

0 commit comments

Comments
 (0)