PageSourceSearch

https://autowhisper.xyz/assets/controllers/custom_prompts_controller-9615e996.js

js autowhisper.xyz collected 2026-10-02 01:11:11 UTC 2,006 bytes, 68 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3// Manages the user's custom prompt chips below the chat input: reveal an inline
4// input on "+", POST to add, DELETE to remove. The server re-renders the chip
5// row partial and we swap it into the container — so the cap/visibility logic
6// lives in one place (the partial), not duplicated in JS.
7export default class extends Controller {
8  static targets = ["container", "input", "inputRow"]
9  static values = { createUrl: String }
10
11  showInput() {
12    if (!this.hasInputRowTarget) return
13    this.inputRowTarget.classList.remove("hidden")
14    if (this.hasInputTarget) this.inputTarget.focus()
15  }
16
17  hideInput() {
18    if (this.hasInputRowTarget) this.inputRowTarget.classList.add("hidden")
19    if (this.hasInputTarget) this.inputTarget.value = ""
20  }
21
22  inputKeydown(event) {
23    if (event.key === "Enter") {
24      event.preventDefault()
25      this.save()
26    } else if (event.key === "Escape") {
27      this.hideInput()
28    }
29  }
30
31  save() {
32    const text = (this.hasInputTarget ? this.inputTarget.value : "").trim()
33    if (!text) {
34      this.hideInput()
35      return
36    }
37    this.submit(this.createUrlValue, "POST", { prompt: text })
38  }
39
40  remove(event) {
41    const index = event.params.index
42    if (index === undefined || index === null) return
43    this.submit(`${this.createUrlValue}/${index}`, "DELETE")
44  }
45
46  async submit(url, method, body) {
47    try {
48      const response = await fetch(url, {
49        method,
50        headers: {
51          "Content-Type": "application/json",
52          "X-CSRF-Token": this.csrfToken()
53        },
54        credentials: "same-origin",
55        body: body ? JSON.stringify(body) : undefined
56      })
57      if (!response.ok) return
58      const html = await response.text()
59      this.containerTarget.innerHTML = html
60    } catch (error) {
61      console.error("[custom-prompts] request failed:", error)
62    }
63  }
64
65  csrfToken() {
66    return document.querySelector('meta[name="csrf-token"]')?.content || ""
67  }
68}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.