types.go

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