| index 24ed92a..ac092db 100644 |
| --- a/internal/slides/assist_prompt.go |
| +++ b/internal/slides/assist_prompt.go |
| @@ -39,7 +39,7 @@ OPERATIONS. Each is an object with an "op" key. They are applied in order as one |
| - {"op":"set_block","slide":"<slide id>","id":"<block id>","props":{...},"region":"<region>","step":<number above 0> or null,"items":"each|together" or null} (props are merged into the block's) |
| - {"op":"set_text","slide":"<slide id>","id":"<block id>","markdown":"<text>"} |
| - {"op":"add_scene","id":"<new id>","name":"...","code":"<the code of a scene already in DECK>","states":[{"id":"...","name":"...","description":"<what a screen reader says>"}],"words":{"<key>":"<text>"},"data":<any JSON>} (a scene draws named states; slides show it with scene blocks) |
| -- {"op":"set_scene","id":"<scene id>","name":"...","states":[...],"words":{"<key>":"<text>" or null},"data":<any JSON>} (send only the keys you change; words merge, data is replaced whole) |
| +- {"op":"set_scene","id":"<scene id>","name":"...","states":[...],"words":{"<key>":"<text>" or null},"data":<any JSON>} (send only the keys you change; words merge, data is replaced whole; a scene in DECK with "data_bytes" and no "data" holds more data than you are shown: never send "data" for it) |
| - {"op":"remove_scene","id":"<scene id>"} |
| |
| IDS. Existing slides and blocks are named by their "id" in DECK; use those exactly. For anything you create, invent a short placeholder id ("s1", "s2", "b1", "b2", ...), different for every new slide and block, and use it to refer to that slide or block later in the same answer. The editor replaces placeholders with real ids. |
| @@ -61,7 +61,8 @@ BLOCK TYPES and their props: |
| - code: {"language":"..."}; the markdown is the code itself, line for line, nothing interpreted |
| - divider, spacer: no text |
| - scene: {"scene":"<scene id>","from":"<state id>","to":"<state id>"}; shows from, then one state per press up to to (from must not come after to) |
| -- clip: {"asset":"<a video asset in DECK>","play":"press|loop|once"} |
| +- clip: {"asset":"<an asset in DECK of kind video>","play":"press|loop|once"} |
| +DECK's "scenes" are the deck's scenes, each with its states, words, code and the size of its data; its "assets" are its pictures and videos, each with a "kind": image, video, poster (a video's picture) or still (a scene state's picture). |
| Do not add image, table, columns or shape blocks: pictures cannot be added from here, and the others need a layout you cannot see. |
| |
| TEXT is a small Markdown: **bold**, *italic*, ` + "`code`" + `, ==highlight==, [text](https://...), and "- " list items. Nothing else: no "#" headings, no tables, no HTML. |
| @@ -94,6 +95,14 @@ EXAMPLE, for "a two-slide deck about tea" in an empty deck: |
| // context, in runes; a slide is not an essay, and the cut is marked. |
| const maxAssistText = 2000 |
| |
| +// maxAssistSceneData bounds the scene data the model is shown, in bytes |
| +// of its canonical JSON (deck.SceneDataSize): 4 KiB. A scene's data at |
| +// most that is in the context whole; past it the context has only its |
| +// size, and the model is told not to send data for that scene. The data |
| +// is a scene's model, often a long list, and the deck's 160 KiB is for |
| +// its slides. |
| +const maxAssistSceneData = 4 << 10 |
| + |
| // maxAssistContext bounds the whole deck view sent, in bytes. Past it |
| // the request is refused as too large rather than sent cut short — a |
| // model shown half a deck rewrites half a deck. |
| @@ -104,7 +113,8 @@ type assistContextDeck struct { |
| Theme string `json:"theme"` |
| Accent string `json:"accent,omitempty"` |
| Slides []assistSlide `json:"slides"` |
| - Assets []assistAssetRef `json:"images,omitempty"` |
| + Assets []assistAssetRef `json:"assets,omitempty"` |
| + Scenes []assistScene `json:"scenes,omitempty"` |
| } |
| |
| type assistSlide struct { |
| @@ -128,9 +138,27 @@ type assistBlockView struct { |
| Text string `json:"markdown,omitempty"` |
| } |
| |
| +// assistAssetRef is an asset as the model sees it. Kind tells a clip's |
| +// video ("video", what a clip block's asset names) from its poster |
| +// ("poster"), a scene's still ("still") and any other picture ("image"). |
| type assistAssetRef struct { |
| - ID string `json:"id"` |
| - Alt string `json:"alt,omitempty"` |
| + ID string `json:"id"` |
| + Kind string `json:"kind"` |
| + Alt string `json:"alt,omitempty"` |
| +} |
| + |
| +// assistScene is a scene as the model sees it, bounded: its states and |
| +// words in full (each word cut at maxAssistText), its code ref (which an |
| +// add_scene may reuse), the size of its data and the data itself only |
| +// when it is at most maxAssistSceneData. |
| +type assistScene struct { |
| + ID string `json:"id"` |
| + Name string `json:"name"` |
| + Code string `json:"code"` |
| + States []deck.SceneState `json:"states"` |
| + Words map[string]string `json:"words,omitempty"` |
| + DataBytes int `json:"data_bytes"` |
| + Data *json.RawMessage `json:"data,omitempty"` |
| } |
| |
| // assistContext is the deck as the model sees it. For one slide's |
| @@ -165,9 +193,31 @@ func assistContext(view *deck.Deck, scope assistScope) ([]byte, error) { |
| out.Slides = append(out.Slides, v) |
| } |
| for id, a := range view.Assets { |
| - out.Assets = append(out.Assets, assistAssetRef{ID: id, Alt: a.Alt}) |
| + out.Assets = append(out.Assets, assistAssetRef{ID: id, Kind: assistAssetKind(view, a), Alt: a.Alt}) |
| } |
| sort.Slice(out.Assets, func(i, j int) bool { return out.Assets[i].ID < out.Assets[j].ID }) |
| + for id, sc := range view.Scenes { |
| + v := assistScene{ID: id, Name: sc.Name, Code: sc.Code, States: sc.States, DataBytes: deck.SceneDataSize(sc)} |
| + if v.States == nil { |
| + v.States = []deck.SceneState{} |
| + } |
| + if len(sc.Words) > 0 { |
| + v.Words = make(map[string]string, len(sc.Words)) |
| + for k, w := range sc.Words { |
| + v.Words[k] = clipRunes(w, maxAssistText) |
| + } |
| + } |
| + if v.DataBytes <= maxAssistSceneData { |
| + raw, err := json.Marshal(sc.Data) |
| + if err != nil { |
| + return nil, err |
| + } |
| + msg := json.RawMessage(raw) |
| + v.Data = &msg |
| + } |
| + out.Scenes = append(out.Scenes, v) |
| + } |
| + sort.Slice(out.Scenes, func(i, j int) bool { return out.Scenes[i].ID < out.Scenes[j].ID }) |
| body, err := json.Marshal(out) |
| if err != nil { |
| return nil, err |
| @@ -178,6 +228,27 @@ func assistContext(view *deck.Deck, scope assistScope) ([]byte, error) { |
| return body, nil |
| } |
| |
| +// assistAssetKind is what an asset is to the model: a clip's video, a |
| +// video's poster, a scene's still, or a picture. |
| +func assistAssetKind(view *deck.Deck, a deck.Asset) string { |
| + if a.Video() { |
| + return "video" |
| + } |
| + for _, v := range view.Assets { |
| + if v.Video() && v.Poster == a.Ref { |
| + return "poster" |
| + } |
| + } |
| + for _, sc := range view.Scenes { |
| + for _, st := range sc.Stills { |
| + if st.Ref == a.Ref { |
| + return "still" |
| + } |
| + } |
| + } |
| + return "image" |
| +} |
| + |
| // assistUserMessage is the user turn: the scope, the person's request |
| // and the deck, each fenced by its label. |
| func assistUserMessage(scope assistScope, prompt string, deckJSON []byte) string { |