| 1 | package agentaccess |
| 2 | |
| 3 | import "encoding/json" |
| 4 | |
| 5 | // ResourceReference is a locator, never an authorization or invitation token. |
| 6 | type ResourceReference struct { |
| 7 | Team string `json:"team"` |
| 8 | App string `json:"app"` |
| 9 | ID string `json:"id"` |
| 10 | URL string `json:"url"` |
| 11 | } |
| 12 | |
| 13 | type scheduleBlock struct { |
| 14 | Type string `json:"type"` |
| 15 | Text string `json:"text"` |
| 16 | Level int `json:"level,omitempty"` |
| 17 | } |
| 18 | type scheduleAgenda struct { |
| 19 | Title string `json:"title"` |
| 20 | Blocks []scheduleBlock `json:"blocks"` |
| 21 | } |
| 22 | type scheduleInput struct { |
| 23 | Team string `json:"team"` |
| 24 | ClientID string `json:"client_id"` |
| 25 | Title string `json:"title"` |
| 26 | CalendarID int64 `json:"calendar_id"` |
| 27 | Start string `json:"start"` |
| 28 | End string `json:"end"` |
| 29 | TZ string `json:"tz"` |
| 30 | Notes string `json:"notes"` |
| 31 | Agenda *scheduleAgenda `json:"agenda,omitempty"` |
| 32 | } |
| 33 | type scheduleStep struct { |
| 34 | Name string `json:"name"` |
| 35 | State string `json:"state"` |
| 36 | Resource *ResourceReference `json:"resource,omitempty"` |
| 37 | } |
| 38 | type scheduleFailure struct { |
| 39 | Step string `json:"step"` |
| 40 | Code string `json:"code"` |
| 41 | } |
| 42 | type scheduleResult struct { |
| 43 | Team string `json:"team"` |
| 44 | ClientID string `json:"client_id"` |
| 45 | Status string `json:"status"` |
| 46 | Steps []scheduleStep `json:"steps"` |
| 47 | InvitationsSent bool `json:"invitations_sent"` |
| 48 | Failure *scheduleFailure `json:"failure,omitempty"` |
| 49 | } |
| 50 | |
| 51 | func schemaObject(properties map[string]any, required ...string) map[string]any { |
| 52 | return map[string]any{"type": "object", "properties": properties, "required": required, "additionalProperties": false} |
| 53 | } |
| 54 | func schemaString(max int) map[string]any { return map[string]any{"type": "string", "maxLength": max} } |
| 55 | func schemaJSON(v any) json.RawMessage { b, _ := json.Marshal(v); return b } |
| 56 | |
| 57 | func (s *scheduler) operation() Operation { |
| 58 | block := schemaObject(map[string]any{"type": map[string]any{"enum": []string{"paragraph", "heading"}}, "text": schemaString(131072), "level": map[string]any{"type": "integer", "minimum": 0, "maximum": 6}}, "type", "text") |
| 59 | agenda := schemaObject(map[string]any{"title": schemaString(512), "blocks": map[string]any{"type": "array", "maxItems": 200, "items": block}}, "title", "blocks") |
| 60 | ref := schemaObject(map[string]any{"team": schemaString(128), "app": schemaString(32), "id": schemaString(128), "url": schemaString(2048)}, "team", "app", "id", "url") |
| 61 | step := schemaObject(map[string]any{"name": map[string]any{"enum": []string{"agenda", "meeting", "event"}}, "state": map[string]any{"enum": []string{"pending", "confirmed", "unconfirmed"}}, "resource": ref}, "name", "state") |
| 62 | failure := schemaObject(map[string]any{"step": schemaString(32), "code": schemaString(32)}, "step", "code") |
| 63 | return Operation{Name: "calls_schedule", Description: "Create an optional agenda, a meeting and a Calendar event. Requires read/write scopes for each selected app. Resume after interruption with the same client_id and exact original request: durable app receipts prevent duplicates. Partial does not mean the failed step did not commit. Sends no invitations; links grant no access.", Scope: "calls:write", Idempotent: true, |
| 64 | Input: schemaJSON(schemaObject(map[string]any{"team": schemaString(64), "client_id": schemaString(36), "title": schemaString(200), "calendar_id": map[string]any{"type": "integer", "minimum": 1, "maximum": int64(9223372036854775807)}, "start": schemaString(35), "end": schemaString(35), "tz": schemaString(128), "notes": schemaString(3000), "agenda": agenda}, "team", "client_id", "title", "calendar_id", "start", "end", "tz", "notes")), |
| 65 | Output: schemaJSON(schemaObject(map[string]any{"team": schemaString(64), "client_id": schemaString(36), "status": map[string]any{"enum": []string{"complete", "partial"}}, "steps": map[string]any{"type": "array", "minItems": 2, "maxItems": 3, "items": step}, "invitations_sent": map[string]any{"const": false}, "failure": failure}, "team", "client_id", "status", "steps", "invitations_sent")), Available: s.available, Invoke: s.invoke} |
| 66 | } |
| 67 | |