d275ffe643
- schedule_followup returns the follow-up id and lists pending follow-ups;
count-then-queue is serialised so the 3-pending bound holds under
concurrent calls.
- cancel_followup {id} removes one of the chat's undelivered follow-ups.
- schedule_followup {run_id, on: finished|attention} queues a durable
follow-up (7-day deadline) that is released with the run's state when the
run ends or waits on a human; run must exist and not already meet the
condition; watches are re-armed from the restored queue after a restart.
- show_html results warn about scripts, remote resources (blocked by the
sandbox) and missing dark-mode support.
- The ambiguous-call error advice fits each tool instead of always
suggesting a different title.
- references/chat.md and the SKILL.md chat paragraph document the above, and
questions are no longer described as Claude-only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.4 KiB
Go
57 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// show_html renders in a sandbox with no scripts and no network, and follows
|
|
// the dark theme only when the document declares dark support (the same test
|
|
// as the app's artifactHtmlSupportsDark). shownHTMLWarnings tells the model
|
|
// when its document relies on what the sandbox blocks, or will stay light, so
|
|
// it can fix the view rather than believe it was shown as written.
|
|
|
|
var (
|
|
shownHTMLScript = regexp.MustCompile(`(?i)<script\b`)
|
|
shownHTMLHandler = regexp.MustCompile(`(?i)<[a-z][^>]*\son[a-z]+\s*=`)
|
|
shownHTMLDarkAware = regexp.MustCompile(`(?i)prefers-color-scheme|color-scheme|light-dark\(`)
|
|
// A remote reference: an attribute or CSS url()/@import naming an
|
|
// http(s) or protocol-relative address.
|
|
shownHTMLRemote = regexp.MustCompile(`(?i)(?:\b(?:src|href|srcset|poster|data)\s*=\s*["']?|url\(\s*["']?|@import\s+["'])((?:https?:)?//[^"')\s>]+)`)
|
|
)
|
|
|
|
// shownHTMLWarnings lists what in html will not work as written, or nil.
|
|
func shownHTMLWarnings(html string) []string {
|
|
var warnings []string
|
|
if shownHTMLScript.MatchString(html) || shownHTMLHandler.MatchString(html) {
|
|
warnings = append(warnings, "it contains JavaScript (<script> or on* handlers), which does not run here; use CSS, <details> and inline SVG instead.")
|
|
}
|
|
var remote []string
|
|
seen := map[string]bool{}
|
|
lower := strings.ToLower(html)
|
|
for _, match := range shownHTMLRemote.FindAllStringSubmatchIndex(html, -1) {
|
|
address := html[match[2]:match[3]]
|
|
// A link to another page is fine: only resources the page loads are
|
|
// blocked. An <a href> is the common case.
|
|
if tag := strings.LastIndex(lower[:match[0]], "<"); tag >= 0 && (strings.HasPrefix(lower[tag:], "<a ") || strings.HasPrefix(lower[tag:], "<a\n")) {
|
|
continue
|
|
}
|
|
if !seen[address] {
|
|
seen[address] = true
|
|
remote = append(remote, address)
|
|
}
|
|
}
|
|
if len(remote) > 0 {
|
|
example := remote[0]
|
|
if len(example) > 120 {
|
|
example = example[:120] + "…"
|
|
}
|
|
warnings = append(warnings, fmt.Sprintf("it loads %d remote resource(s) (such as %s), which the sandbox blocks: inline styles, fonts and images (data: URLs or inline SVG).", len(remote), example))
|
|
}
|
|
if !shownHTMLDarkAware.MatchString(html) {
|
|
warnings = append(warnings, "it does not declare dark support, so it is always shown light, on white, even in a dark theme; add @media (prefers-color-scheme: dark) styles, a color-scheme declaration or light-dark() colors.")
|
|
}
|
|
return warnings
|
|
}
|