package aiprompts import ( _ "embed" "encoding/json" "fmt" "strings" "sync" ) // This frozen v6 snapshot is used ONLY to identify exact old default templates // during migrations. Never serve these obsolete instructions to new categories. // //go:embed defaults/prompt-rules-v6.json var previousOfflinePromptRulesJSON []byte func PreviousOfflineDefaultPromptV6(lang string) (string, error) { var rules map[string]offlineRules if err := json.Unmarshal(previousOfflinePromptRulesJSON, &rules); err != nil { return "", err } rule, ok := rules[lang] if !ok || rule.Title == "" || rule.Description == "" || rule.Meta == "" { return "", fmt.Errorf("missing historical v6 language %q", lang) } return "--- Title ---\n" + rule.Title + "\n--- End Title ---\n\n--- Description ---\n" + rule.Description + "\n--- End Description ---\n\n--- Meta ---\n" + rule.Meta + "\n--- End Meta ---", nil } // The v3 bundle is kept ONLY as exact-match migration evidence. The v3 // descriptions were plain text with five 100-word sections and must NEVER be // served as defaults or shown as the new editor examples. // //go:embed defaults/prompt-rules-v3.json var previousOfflinePromptRulesV3JSON []byte func PreviousOfflineDefaultPromptV3(lang string) (string, error) { var rules map[string]offlineRules if err := json.Unmarshal(previousOfflinePromptRulesV3JSON, &rules); err != nil { return "", err } rule, ok := rules[lang] if !ok || rule.Title == "" || rule.Description == "" || rule.Meta == "" { return "", fmt.Errorf("missing historical v3 language %q", lang) } return "--- Title ---\n" + rule.Title + "\n--- End Title ---\n\n--- Description ---\n" + rule.Description + "\n--- End Description ---\n\n--- Meta ---\n" + rule.Meta + "\n--- End Meta ---", nil } // Shipped, human-readable platform instructions for every supported content // language. This is offline reference data, not a request to an LLM. // //go:embed defaults/prompt-rules-25.json var offlinePromptRulesJSON []byte type offlineRules struct { Title string `json:"title"` Description string `json:"description"` Meta string `json:"meta"` } var offlinePromptOnce sync.Once var offlinePrompts map[string]offlineRules var offlinePromptErr error // OfflineDefaultPrompt returns a fully localized, A1-style platform template. // Original category-specific English title instructions continue to live in // the English wildcard and the structured title_template; this shared default // uses the standard brand/type/model/color formula for non-English languages. // Returns an error, rather than silently falling back to English, if a locale // has no bundled translation. func OfflineDefaultPrompt(lang string) (string, error) { offlinePromptOnce.Do(func() { offlinePromptErr = json.Unmarshal(offlinePromptRulesJSON, &offlinePrompts) }) if offlinePromptErr != nil { return "", fmt.Errorf("load bundled prompts: %w", offlinePromptErr) } rule, ok := offlinePrompts[lang] if !ok || strings.TrimSpace(rule.Title) == "" || strings.TrimSpace(rule.Description) == "" || strings.TrimSpace(rule.Meta) == "" { return "", fmt.Errorf("no bundled category formula for language %q", lang) } // The editor and processing pipeline interpret each role section using // the exact marker syntax below. Body structure is defined in the // localized Description HTML instructions, not a repetitive fixed-length article. return "--- Title ---\n" + rule.Title + "\n--- End Title ---\n\n--- Description ---\n" + rule.Description + "\n--- End Description ---\n\n--- Meta ---\n" + rule.Meta + "\n--- End Meta ---", nil } func OfflinePromptLanguages() []string { offlinePromptOnce.Do(func() { offlinePromptErr = json.Unmarshal(offlinePromptRulesJSON, &offlinePrompts) }) out := make([]string, 0, len(offlinePrompts)) for lang := range offlinePrompts { out = append(out, lang) } return out }