Repository navigation
Expand file tree
/
Copy pathschedule.go
More file actions
267 lines (234 loc) · 8.74 KB
/
Copy pathschedule.go
File metadata and controls
267 lines (234 loc) · 8.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package cercago
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"time"
"github.com/matrices/cerca-go/internal/apijson"
"github.com/matrices/cerca-go/internal/param"
"github.com/matrices/cerca-go/internal/requestconfig"
"github.com/matrices/cerca-go/option"
"github.com/matrices/cerca-go/shared"
)
// ScheduleService contains methods and other services that help with interacting
// with the cerca API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewScheduleService] method instead.
type ScheduleService struct {
Options []option.RequestOption
}
// NewScheduleService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewScheduleService(opts ...option.RequestOption) (r *ScheduleService) {
r = &ScheduleService{}
r.Options = opts
return
}
// Create schedule
func (r *ScheduleService) New(ctx context.Context, agentID string, body ScheduleNewParams, opts ...option.RequestOption) (res *Schedule, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/schedules", agentID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Update schedule
func (r *ScheduleService) Update(ctx context.Context, agentID string, scheduleID string, body ScheduleUpdateParams, opts ...option.RequestOption) (res *Schedule, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if scheduleID == "" {
err = errors.New("missing required scheduleId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/schedules/%s", agentID, scheduleID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
return res, err
}
// List schedules
func (r *ScheduleService) List(ctx context.Context, agentID string, opts ...option.RequestOption) (res *ScheduleListResponse, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/schedules", agentID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Delete schedule
func (r *ScheduleService) Delete(ctx context.Context, agentID string, scheduleID string, opts ...option.RequestOption) (res *ScheduleDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if scheduleID == "" {
err = errors.New("missing required scheduleId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/schedules/%s", agentID, scheduleID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// Trigger schedule
func (r *ScheduleService) Trigger(ctx context.Context, agentID string, scheduleID string, opts ...option.RequestOption) (res *ScheduleTriggerResponse, err error) {
opts = slices.Concat(r.Options, opts)
if agentID == "" {
err = errors.New("missing required agentId parameter")
return nil, err
}
if scheduleID == "" {
err = errors.New("missing required scheduleId parameter")
return nil, err
}
path := fmt.Sprintf("agents/%s/schedules/%s/trigger", agentID, scheduleID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
type Schedule struct {
ID string `json:"id" api:"required"`
CreatedAt string `json:"createdAt" api:"required"`
Enabled bool `json:"enabled" api:"required"`
Message string `json:"message" api:"required"`
Name string `json:"name" api:"required"`
NextAt string `json:"nextAt" api:"required,nullable"`
Timezone string `json:"timezone" api:"required"`
UpdatedAt string `json:"updatedAt" api:"required"`
Cron string `json:"cron"`
Instructions string `json:"instructions"`
Model string `json:"model"`
RunAt time.Time `json:"runAt" format:"date-time"`
// Per-schedule tool subset. Scheduled threads inherit the agent's effective tools
// when omitted and can only narrow them when provided.
Tools []shared.ToolSpec `json:"tools"`
JSON scheduleJSON `json:"-"`
}
// scheduleJSON contains the JSON metadata for the struct [Schedule]
type scheduleJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Enabled apijson.Field
Message apijson.Field
Name apijson.Field
NextAt apijson.Field
Timezone apijson.Field
UpdatedAt apijson.Field
Cron apijson.Field
Instructions apijson.Field
Model apijson.Field
RunAt apijson.Field
Tools apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Schedule) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r scheduleJSON) RawJSON() string {
return r.raw
}
type ScheduleListResponse struct {
Schedules []Schedule `json:"schedules" api:"required"`
JSON scheduleListResponseJSON `json:"-"`
}
// scheduleListResponseJSON contains the JSON metadata for the struct
// [ScheduleListResponse]
type scheduleListResponseJSON struct {
Schedules apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ScheduleListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r scheduleListResponseJSON) RawJSON() string {
return r.raw
}
type ScheduleDeleteResponse struct {
Success ScheduleDeleteResponseSuccess `json:"success" api:"required"`
JSON scheduleDeleteResponseJSON `json:"-"`
}
// scheduleDeleteResponseJSON contains the JSON metadata for the struct
// [ScheduleDeleteResponse]
type scheduleDeleteResponseJSON struct {
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ScheduleDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r scheduleDeleteResponseJSON) RawJSON() string {
return r.raw
}
type ScheduleDeleteResponseSuccess bool
const (
ScheduleDeleteResponseSuccessTrue ScheduleDeleteResponseSuccess = true
)
func (r ScheduleDeleteResponseSuccess) IsKnown() bool {
switch r {
case ScheduleDeleteResponseSuccessTrue:
return true
}
return false
}
type ScheduleTriggerResponse struct {
ThreadID string `json:"threadId" api:"required"`
JSON scheduleTriggerResponseJSON `json:"-"`
}
// scheduleTriggerResponseJSON contains the JSON metadata for the struct
// [ScheduleTriggerResponse]
type scheduleTriggerResponseJSON struct {
ThreadID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ScheduleTriggerResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r scheduleTriggerResponseJSON) RawJSON() string {
return r.raw
}
type ScheduleNewParams struct {
Message param.Field[string] `json:"message" api:"required"`
Name param.Field[string] `json:"name" api:"required"`
Cron param.Field[string] `json:"cron"`
Instructions param.Field[string] `json:"instructions"`
Model param.Field[string] `json:"model"`
RunAt param.Field[time.Time] `json:"runAt" format:"date-time"`
Timezone param.Field[string] `json:"timezone"`
// Per-schedule tool subset. When the schedule starts a thread, these tools can
// only narrow the agent's effective tools.
Tools param.Field[[]shared.ToolSpecParam] `json:"tools"`
}
func (r ScheduleNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ScheduleUpdateParams struct {
Cron param.Field[string] `json:"cron"`
Enabled param.Field[bool] `json:"enabled"`
Instructions param.Field[string] `json:"instructions"`
Message param.Field[string] `json:"message"`
Model param.Field[string] `json:"model"`
Name param.Field[string] `json:"name"`
RunAt param.Field[time.Time] `json:"runAt" format:"date-time"`
Timezone param.Field[string] `json:"timezone"`
// Per-schedule tool subset. When updated, these tools can only narrow the agent's
// effective tools for future scheduled threads.
Tools param.Field[[]shared.ToolSpecParam] `json:"tools"`
}
func (r ScheduleUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}