Value returns the prompt text with every chip label expanded to its original content, what goes to the LLM on submit.
()
| 469 | // Value returns the prompt text with every chip label expanded to its original |
| 470 | // content, what goes to the LLM on submit. |
| 471 | func (p promptInput) Value() string { |
| 472 | if len(p.spans) == 0 { |
| 473 | return p.ta.Value() |
| 474 | } |
| 475 | value := p.ta.Value() |
| 476 | runes := []rune(value) |
| 477 | var b strings.Builder |
| 478 | b.Grow(len(value)) |
| 479 | cursor := 0 |
| 480 | for _, span := range p.spans { |
| 481 | content, ok := p.store[span.id] |
| 482 | if !ok { |
| 483 | continue |
| 484 | } |
| 485 | if span.start > cursor { |
| 486 | b.WriteString(string(runes[cursor:span.start])) |
| 487 | } |
| 488 | b.WriteString(content.content) |
| 489 | cursor = span.end |
| 490 | } |
| 491 | if cursor < len(runes) { |
| 492 | b.WriteString(string(runes[cursor:])) |
| 493 | } |
| 494 | return b.String() |
| 495 | } |
| 496 | |
| 497 | // DisplayValue returns the text as shown, chip labels stay collapsed. Used for |
| 498 | // echo-to-scroll on submit and the ↑/↓ history snapshot. |