oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package personapi
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/library"
5 "amadan.net/oficina/equipo/internal/taskplan"
6 "encoding/json"
7 "time"
8)
9
10type BeginDeviceInput struct {
11 PublicKey string `json:"public_key"`
12 Label string `json:"label"`
13}
14type ApproveDeviceInput struct {
15 TypedCode string `json:"typed_code"`
16}
17type LabelInput struct {
18 Label string `json:"label"`
19}
20type TeamLinkInput struct {
21 Origin string `json:"origin"`
22 Name string `json:"name"`
23}
24type TeamLink struct {
25 ID string `json:"id"`
26 TeamLinkInput
27 LastSignedInAt *time.Time `json:"last_signed_in_at"`
28 NeedsYou *int64 `json:"needs_you"`
29 Revision int64 `json:"revision"`
30}
31type Account struct {
32 ID string `json:"id"`
33 Label string `json:"label"`
34 Revision int64 `json:"revision"`
35}
36type DecisionOwner struct {
37 Decision string `json:"decision"`
38 Address string `json:"address"`
39}
40type ProjectFields struct {
41 AccountID int64 `json:"account_id"`
42 Name string `json:"name"`
43 Repository string `json:"repository"`
44 AppName string `json:"app_name"`
45 DefaultBranch string `json:"default_branch"`
46 Kind string `json:"kind"`
47 Owners []DecisionOwner `json:"owners"`
48}
49type Project struct {
50 ID string `json:"id"`
51 ProjectFields
52 Revision int64 `json:"revision"`
53}
54type ProjectSettingsInput struct {
55 Action string `json:"action"`
56 ApprovalMode string `json:"approval_mode,omitempty"`
57 PlaybookID string `json:"playbook_id,omitempty"`
58 Kind taskplan.Kind `json:"kind,omitempty"`
59 Rules string `json:"rules,omitempty"`
60}
61type ProjectSettings struct {
62 ApprovalMode string `json:"approval_mode"`
63 ApprovalRevision int64 `json:"approval_revision"`
64 MyApprovalMode string `json:"my_approval_mode"`
65 MyApprovalRevision int64 `json:"my_approval_revision"`
66 Defaults []PlaybookDefault `json:"defaults"`
67 Connections ConnectionChoiceInput `json:"connections"`
68 ConnectionsRevision int64 `json:"connections_revision"`
69 Rules string `json:"rules"`
70 RulesRevision int64 `json:"rules_revision"`
71}
72type PlaybookDefault struct {
73 Kind taskplan.Kind `json:"kind"`
74 PlaybookID string `json:"playbook_id"`
75 Revision int64 `json:"revision"`
76}
77type ModelRef struct {
78 Provider string `json:"provider"`
79 Family string `json:"family"`
80 Model string `json:"model"`
81}
82type SpecialistInput struct {
83 Name string `json:"name"`
84 Icon string `json:"icon"`
85 Instructions string `json:"instructions"`
86 AllowedModels []ModelRef `json:"allowed_models"`
87 Tools []string `json:"tools"`
88 ProjectIDs []int64 `json:"project_ids"`
89 MaxConcurrent int `json:"max_concurrent"`
90}
91type Specialist struct {
92 ID string `json:"id"`
93 SpecialistInput
94 Creator string `json:"creator"`
95 Required bool `json:"required"`
96 Archived bool `json:"archived"`
97 Revision int64 `json:"revision"`
98 Template TemplateRef `json:"template"`
99 WorkCount *int64 `json:"work_count"`
100}
101type PlaybookInput struct {
102 Template TemplateRef `json:"template"`
103 Name string `json:"name"`
104 Kind taskplan.Kind `json:"kind"`
105 Steps []PlanStep `json:"steps"`
106 ProjectIDs []int64 `json:"project_ids"`
107}
108type Playbook struct {
109 ID string `json:"id"`
110 PlaybookInput
111 Creator string `json:"creator"`
112 Archived bool `json:"archived"`
113 Revision int64 `json:"revision"`
114}
115type TemplateRef struct {
116 ID string `json:"id"`
117 Version int64 `json:"version"`
118}
119type Template struct {
120 ID string `json:"id"`
121 Version int64 `json:"version"`
122 Kind string `json:"kind"`
123 GroupKey string `json:"group_key"`
124 NameKey string `json:"name_key"`
125 DescriptionKey string `json:"description_key"`
126 InstructionsKey string `json:"instructions_key"`
127 Icon string `json:"icon"`
128}
129type TemplateInstallInput struct {
130 Version int64 `json:"version"`
131}
132type TemplateDiff struct {
133 From TemplateRef `json:"from"`
134 To TemplateRef `json:"to"`
135 CurrentRevision int64 `json:"current_revision"`
136 Old map[string]json.RawMessage `json:"old"`
137 Current map[string]json.RawMessage `json:"current"`
138 Suggested map[string]json.RawMessage `json:"suggested"`
139}
140type TemplateUpdateInput struct {
141 Diff TemplateDiff `json:"diff"`
142 Fields []string `json:"fields"`
143}
144type Connection struct {
145 ID string `json:"id"`
146 RunnerID string `json:"runner_id"`
147 Label string `json:"label"`
148 Revision int64 `json:"revision"`
149 RevokedAt *time.Time `json:"revoked_at"`
150 Models []ConnectionModel `json:"models"`
151}
152type ConnectionModel struct {
153 Provider string `json:"provider"`
154 Family string `json:"family"`
155 Model string `json:"model"`
156 Kind string `json:"kind"`
157 Available bool `json:"available"`
158 AllowanceRemaining *int64 `json:"allowance_remaining"`
159}
160type ConnectionChoiceInput struct {
161 ConnectionIDs []string `json:"connection_ids"`
162 PinnedID string `json:"pinned_id"`
163 Mode string `json:"mode"`
164}
165type SelectionInput struct {
166 ConnectionID string `json:"connection_id"`
167 Model string `json:"model"`
168}
169type Runner struct {
170 ID string `json:"id"`
171 Label string `json:"label"`
172 Revision int64 `json:"revision"`
173 CreatedAt *time.Time `json:"created_at,omitempty"`
174 LastSeen *time.Time `json:"last_seen,omitempty"`
175 RevokedAt *time.Time `json:"revoked_at"`
176}
177type RunnerApproveInput struct {
178 TypedCode string `json:"typed_code"`
179}
180type OnboardingInput struct {
181 Step string `json:"step"`
182 Provider string `json:"provider,omitempty"`
183 ProjectID int64 `json:"project_id,omitempty"`
184}
185type Onboarding struct {
186 CurrentStep string `json:"current_step"`
187 ProviderChoice string `json:"provider_choice"`
188 RunnerID string `json:"runner_id"`
189 AccountSetupID string `json:"account_setup_id"`
190 Completed map[string]bool `json:"completed"`
191 Revision int64 `json:"revision"`
192}
193type AccountSetupInput struct {
194 RunnerID string `json:"runner_id"`
195 Provider string `json:"provider"`
196 Label string `json:"label"`
197}
198type AccountSetup struct {
199 ID string `json:"id"`
200 State string `json:"state"`
201 Mode string `json:"mode"`
202 Command string `json:"command"`
203}
204type InviteInput struct {
205 Address string `json:"address"`
206 Role string `json:"role"`
207}
208type AcceptInviteInput struct {
209 Secret string `json:"secret"`
210}
211type Invitation struct {
212 ID string `json:"id"`
213 Address string `json:"address"`
214 Role string `json:"role"`
215 State string `json:"state"`
216 ExpiresAt time.Time `json:"expires_at"`
217 Revision int64 `json:"revision"`
218 Link string `json:"link,omitempty"`
219}
220
221func (v SpecialistInput) Value(id string) library.SpecialistInput {
222 out := library.SpecialistInput{Key: id, Name: v.Name, Icon: v.Icon, Instructions: v.Instructions, Tools: v.Tools, ProjectIDs: v.ProjectIDs, MaxConcurrent: v.MaxConcurrent}
223 for _, m := range v.AllowedModels {
224 out.AllowedModels = append(out.AllowedModels, library.ModelRef{Provider: m.Provider, Family: m.Family, Model: m.Model})
225 }
226 return out
227}
228func ProjectSpecialist(v library.Specialist) Specialist {
229 if v.Tools == nil {
230 v.Tools = []string{}
231 }
232 if v.ProjectIDs == nil {
233 v.ProjectIDs = []int64{}
234 }
235 out := Specialist{ID: v.Key, Creator: v.Creator, Required: v.Required, Archived: v.Archived, Revision: v.Revision, Template: TemplateRef{v.TemplateID, v.TemplateVersion}, SpecialistInput: SpecialistInput{Name: v.Name, Icon: v.Icon, Instructions: v.StandingInstructions, Tools: v.Tools, ProjectIDs: v.ProjectIDs, MaxConcurrent: v.MaxConcurrent, AllowedModels: []ModelRef{}}}
236 for _, m := range v.AllowedModels {
237 out.AllowedModels = append(out.AllowedModels, ModelRef{m.Provider, m.Family, m.Model})
238 }
239 return out
240}
241func (v PlaybookInput) Value(id string) library.PlaybookInput {
242 return library.PlaybookInput{Template: library.TemplateRef{ID: v.Template.ID, Version: v.Template.Version}, ID: id, Name: v.Name, Kind: v.Kind, Steps: (PlanInput{Steps: v.Steps}).Value("", 0).Steps, ProjectIDs: v.ProjectIDs}
243}
244func ProjectPlaybook(v library.Playbook) Playbook {
245 if v.ProjectIDs == nil {
246 v.ProjectIDs = []int64{}
247 }
248 return Playbook{ID: v.ID, Creator: v.Creator, Archived: v.Archived, Revision: v.Revision, PlaybookInput: PlaybookInput{Template: TemplateRef{v.Template.ID, v.Template.Version}, Name: v.Name, Kind: v.Kind, Steps: ProjectPlan(taskplan.Plan{Steps: v.Steps}).Steps, ProjectIDs: v.ProjectIDs}}
249}
250func (v TemplateDiff) Value() library.TemplateDiff {
251 return library.TemplateDiff{From: library.TemplateRef{ID: v.From.ID, Version: v.From.Version}, To: library.TemplateRef{ID: v.To.ID, Version: v.To.Version}, CurrentRevision: v.CurrentRevision, Old: v.Old, Current: v.Current, Suggested: v.Suggested}
252}
253func ProjectDiff(v library.TemplateDiff) TemplateDiff {
254 return TemplateDiff{TemplateRef{v.From.ID, v.From.Version}, TemplateRef{v.To.ID, v.To.Version}, v.CurrentRevision, v.Old, v.Current, v.Suggested}
255}
256
257type Selected struct {
258 ConnectionID string `json:"connection_id"`
259 Model string `json:"model"`
260 Reason string `json:"reason"`
261 Revision int64 `json:"revision"`
262}
263