| 1 | package slides |
| 2 | |
| 3 | import ( |
| 4 | access "amadan.net/oficina/agent-access.git" |
| 5 | "context" |
| 6 | "encoding/json" |
| 7 | strictjson "github.com/go-json-experiment/json" |
| 8 | ) |
| 9 | |
| 10 | // These are discoverable argument schemas, not a second operation interpreter. |
| 11 | // core/src/ops.rs owns validation and execution. Contract tests exercise every |
| 12 | // advertised variant against that engine to keep the public vocabulary honest. |
| 13 | func slideAgentEditVariants() []any { |
| 14 | str := func() any { return map[string]any{"type": "string"} } |
| 15 | nullable := func(v any) any { return map[string]any{"anyOf": []any{v, map[string]any{"type": "null"}}} } |
| 16 | object := func(p map[string]any, required ...string) any { |
| 17 | if required == nil { |
| 18 | required = []string{} |
| 19 | } |
| 20 | return slideAgentObject(p, required...) |
| 21 | } |
| 22 | enumeration := func(values ...string) any { return map[string]any{"enum": values} } |
| 23 | num := map[string]any{"type": "number"} |
| 24 | box := object(map[string]any{"x": num, "y": num, "w": num, "h": num}, "x", "y", "w", "h") |
| 25 | fonts := object(map[string]any{"heading": str(), "body": str()}, "heading", "body") |
| 26 | background := object(map[string]any{"kind": enumeration("theme", "color", "image"), "value": str()}, "kind") |
| 27 | phone := object(map[string]any{"hidden": map[string]any{"type": "boolean"}, "order": map[string]any{"type": "integer"}, "size": enumeration("s", "m", "l"), "box": box}) |
| 28 | props := map[string]any{"type": "object", "description": "Canonical properties for the block type, as exposed in slides_get_deck. Passed unchanged to the semantic engine."} |
| 29 | layout := enumeration("flow", "canvas") |
| 30 | template := enumeration("title", "title-body", "two-column", "section", "image-full", "quote", "blank") |
| 31 | region := enumeration("heading", "body", "aside", "media") |
| 32 | step := map[string]any{"type": "number", "exclusiveMinimum": 0} |
| 33 | // Scenes (scenes and clips spec §2). The core checks the rest: state |
| 34 | // ids used once, data within 960 KiB and the batch within one live |
| 35 | // update (1 MiB), stills naming states. No author: the server sets |
| 36 | // it from whoever acted. |
| 37 | hex64 := map[string]any{"type": "string", "pattern": "^[0-9a-f]{64}$"} |
| 38 | sceneID := map[string]any{"type": "string", "pattern": "^[a-z2-7]{12}$"} |
| 39 | anyJSON := map[string]any{"description": "Any JSON value: the scene's model, replaced whole."} |
| 40 | states := map[string]any{"type": "array", "minItems": 1, "items": object(map[string]any{"id": map[string]any{"type": "string", "minLength": 1}, "name": str(), "description": str()}, "id")} |
| 41 | words := map[string]any{"type": "object", "additionalProperties": str()} |
| 42 | wordPatch := map[string]any{"type": "object", "additionalProperties": nullable(str())} |
| 43 | stills := map[string]any{"type": "object", "additionalProperties": nullable(object(map[string]any{"ref": hex64, "made": hex64}, "ref", "made"))} |
| 44 | variant := func(name string, p map[string]any, required ...string) any { |
| 45 | p["op"] = map[string]any{"const": name} |
| 46 | return object(p, append([]string{"op"}, required...)...) |
| 47 | } |
| 48 | return []any{ |
| 49 | variant("set_meta", map[string]any{"title": str(), "theme": str(), "accent": nullable(str()), "fonts": nullable(fonts), "arrive": nullable(enumeration("appear", "fade", "rise"))}), |
| 50 | variant("add_slide", map[string]any{"id": str(), "after": nullable(str()), "layout": layout, "template": template}, "layout"), |
| 51 | variant("remove_slide", map[string]any{"id": str()}, "id"), |
| 52 | variant("move_slide", map[string]any{"id": str(), "after": nullable(str())}, "id"), |
| 53 | variant("duplicate_slide", map[string]any{"id": str(), "new_id": str(), "new_block_ids": map[string]any{"type": "array", "items": str()}}, "id"), |
| 54 | variant("set_slide", map[string]any{"id": str(), "layout": layout, "template": template, "background": background, "phone": enumeration("inherit", "reflow"), "transition": enumeration("none", "fade"), "talk": nullable(enumeration("full", "parked"))}, "id"), |
| 55 | variant("set_notes", map[string]any{"id": str(), "markdown": str()}, "id", "markdown"), |
| 56 | variant("add_block", map[string]any{"slide": str(), "id": str(), "type": enumeration("heading", "text", "list", "quote", "image", "columns", "code", "shape", "table", "divider", "spacer", "scene", "clip", "qr"), "props": props, "region": region, "box": box, "z": num, "after": nullable(str()), "markdown": str()}, "slide", "type"), |
| 57 | variant("remove_block", map[string]any{"slide": str(), "id": str()}, "slide", "id"), |
| 58 | variant("move_block", map[string]any{"slide": str(), "id": str(), "after": nullable(str())}, "slide", "id"), |
| 59 | variant("set_block", map[string]any{"slide": str(), "id": str(), "props": props, "region": nullable(region), "box": nullable(box), "z": num, "step": nullable(step), "items": nullable(enumeration("together", "each"))}, "slide", "id"), |
| 60 | variant("set_text", map[string]any{"slide": str(), "id": str(), "markdown": str()}, "slide", "id", "markdown"), |
| 61 | variant("set_phone", map[string]any{"slide": str(), "id": str(), "phone": phone}, "slide", "id", "phone"), |
| 62 | variant("add_scene", map[string]any{"id": sceneID, "name": str(), "code": hex64, "states": states, "words": words, "data": anyJSON}, "name", "code", "states"), |
| 63 | variant("set_scene", map[string]any{"id": str(), "name": str(), "code": hex64, "states": states, "words": wordPatch, "data": anyJSON, "stills": stills}, "id"), |
| 64 | variant("remove_scene", map[string]any{"id": str()}, "id"), |
| 65 | } |
| 66 | } |
| 67 | func slideAgentEditableOp(name string) bool { |
| 68 | switch name { |
| 69 | case "set_meta", "add_slide", "remove_slide", "move_slide", "duplicate_slide", "set_slide", "set_notes", "add_block", "remove_block", "move_block", "set_block", "set_text", "set_phone", |
| 70 | "add_scene", "set_scene", "remove_scene": |
| 71 | return true |
| 72 | } |
| 73 | return false |
| 74 | } |
| 75 | func (a *slideAgent) updateOperation(input func(map[string]any, ...string) json.RawMessage, sqid, revision map[string]any) access.Operation { |
| 76 | return access.Operation{Name: "slides_update_deck", Description: "Atomically apply one to one hundred canonical semantic operations at expected_revision. Keep the same client UUID and payload on retry. The returned revision and generated IDs name the original commit; read again for current content.", Scope: "slides:write", Idempotent: true, |
| 77 | Input: input(map[string]any{"sqid": sqid, "expected_revision": revision, "client_id": slideAgentString(36), "ops": map[string]any{"type": "array", "minItems": 1, "maxItems": 100, "items": map[string]any{"oneOf": slideAgentEditVariants()}}}, "sqid", "expected_revision", "client_id", "ops"), |
| 78 | Output: slideAgentObject(map[string]any{"sqid": sqid, "revision": revision, "url": slideAgentString(4096), "ids": map[string]any{"type": "object", "additionalProperties": map[string]any{"type": "string"}}}, "sqid", "revision", "url", "ids"), |
| 79 | Invoke: func(ctx context.Context, p access.Principal, raw json.RawMessage) (any, error) { |
| 80 | var in slideAgentUpdate |
| 81 | if err := strictjson.Unmarshal(raw, &in); err != nil { |
| 82 | return nil, access.Fail("invalid", "Invalid semantic deck edit arguments.") |
| 83 | } |
| 84 | return a.update(ctx, p, slideAgentMember(ctx), in) |
| 85 | }} |
| 86 | } |
| 87 | |