1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5// Package shared provides common types and utilities for MCP resources and tools.
6package shared
7
8// Keyed is an interface for types that have ID, Name, and Key fields.
9type Keyed interface {
10 GetID() string
11 GetName() string
12 GetKey() string
13}
14
15// AreaProvider represents an area with its goals for MCP resources.
16type AreaProvider struct {
17 ID string
18 Name string
19 Key string
20 Goals []GoalProvider
21}
22
23// GoalProvider represents a goal within an area.
24type GoalProvider struct {
25 ID string
26 Name string
27 Key string
28}
29
30// HabitProvider represents a habit for MCP resources.
31type HabitProvider struct {
32 ID string
33 Name string
34 Key string
35}
36
37// NotebookProvider represents a notebook for MCP resources.
38type NotebookProvider struct {
39 ID string
40 Name string
41 Key string
42}
43
44// ToHabitProviders converts a slice of Keyed items to HabitProviders.
45func ToHabitProviders[T Keyed](items []T) []HabitProvider {
46 providers := make([]HabitProvider, 0, len(items))
47 for _, item := range items {
48 providers = append(providers, HabitProvider{
49 ID: item.GetID(),
50 Name: item.GetName(),
51 Key: item.GetKey(),
52 })
53 }
54
55 return providers
56}
57
58// ToNotebookProviders converts a slice of Keyed items to NotebookProviders.
59func ToNotebookProviders[T Keyed](items []T) []NotebookProvider {
60 providers := make([]NotebookProvider, 0, len(items))
61 for _, item := range items {
62 providers = append(providers, NotebookProvider{
63 ID: item.GetID(),
64 Name: item.GetName(),
65 Key: item.GetKey(),
66 })
67 }
68
69 return providers
70}
71
72// ToGoalProviders converts a slice of Keyed items to GoalProviders.
73func ToGoalProviders[T Keyed](items []T) []GoalProvider {
74 providers := make([]GoalProvider, 0, len(items))
75 for _, item := range items {
76 providers = append(providers, GoalProvider{
77 ID: item.GetID(),
78 Name: item.GetName(),
79 Key: item.GetKey(),
80 })
81 }
82
83 return providers
84}