prompt_navigator 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1519a5a4fc2a28bda0f3795d7ce91f15afeeab646db88d53888cce56ef031869
4
- data.tar.gz: 6dd58cf6962f7db2fcdb51937147926588d69c8d2c9d71e32d7e923632038789
3
+ metadata.gz: f448c834c18a600ebf636fad362e51f7dd80c354484e1971388a884cdd9ffb80
4
+ data.tar.gz: d9a983063d1afe013001e7017b64ecc49f60467ea6e24a4179c20f37698d7eb4
5
5
  SHA512:
6
- metadata.gz: cf79eba4420fc941941e99cc7701b3b0970227f62e171b23b43750ea5342b90b4600efdac5290a309f8d1773dfe71673719cfd7d11da9718b4e96e99a558afe0
7
- data.tar.gz: 1146200b8a8eecd25555f3b83f858039d323b775832566cd4c8a2d80584417c224cb61fb7400e5637359f7b6071aa5257fa873c5dd0d3c7e352ee3afe1e76b25
6
+ metadata.gz: 7e3e53891c90ffa1fe59767eeb2de6f10b215eef872c4ca815384329b61e315aca9de871ed6f91761c22ef3c252d00415d6741b9158cf46b1ff51284b0c5db46
7
+ data.tar.gz: 35998b74c979da62e030e6bec1609bc35aea630fb205ffed49718f39a3b594879bb0d5c30340b0c9f5b6e38d8fc211b18c7f273d3d788f84a5e64843b09be3ba
@@ -2,8 +2,8 @@
2
2
  position: relative;
3
3
  display: flex;
4
4
  flex-direction: column;
5
- gap: 8px;
6
5
  padding-left: 32px; /* space for arrows */
6
+ margin-top: 20px;
7
7
  }
8
8
 
9
9
  .history-card {
@@ -14,6 +14,7 @@
14
14
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
15
15
  position: relative;
16
16
  z-index: 1;
17
+ margin-bottom: 16px;
17
18
  transition:
18
19
  box-shadow 0.15s ease,
19
20
  transform 0.15s ease;
@@ -27,17 +28,70 @@
27
28
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
28
29
  transform: translateY(-2px);
29
30
  }
31
+
32
+ &:last-child {
33
+ margin-bottom: 0;
34
+ }
35
+
36
+ &:has(+ .history-straight-arrow) {
37
+ margin-bottom: 0;
38
+ }
39
+ }
40
+
41
+ .history-card-row {
42
+ display: flex;
43
+ align-items: center;
44
+ gap: 6px;
45
+ }
46
+
47
+ .history-card-row .history-card-link {
48
+ flex: 1;
49
+ min-width: 0;
30
50
  }
31
51
 
32
52
  .history-card-link {
33
- display: grid;
34
- grid-template-columns: auto 1fr auto;
35
- grid-gap: 8px;
53
+ display: block;
36
54
  text-decoration: none;
37
55
  color: #333;
56
+ min-width: 0;
57
+ }
58
+
59
+ .history-card-delete-form {
60
+ margin: 0;
61
+ display: flex;
38
62
  align-items: center;
39
63
  }
40
64
 
65
+ .history-card-delete {
66
+ display: flex;
67
+ align-items: center;
68
+ justify-content: center;
69
+ width: 22px;
70
+ height: 22px;
71
+ padding: 0;
72
+ border: none;
73
+ background: transparent;
74
+ border-radius: 4px;
75
+ color: #888;
76
+ cursor: pointer;
77
+ flex-shrink: 0;
78
+ opacity: 0;
79
+ transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
80
+
81
+ i {
82
+ font-size: 12px;
83
+ }
84
+
85
+ &:hover {
86
+ color: #dc2626;
87
+ background-color: rgba(220, 38, 38, 0.1);
88
+ }
89
+ }
90
+
91
+ .history-card:hover .history-card-delete {
92
+ opacity: 1;
93
+ }
94
+
41
95
  .history-card-number {
42
96
  font-size: 12px;
43
97
  font-weight: 600;
@@ -57,7 +111,6 @@
57
111
  font-size: 10px;
58
112
  font-weight: 700;
59
113
  letter-spacing: 0.02em;
60
- margin-left: auto;
61
114
  flex-shrink: 0;
62
115
  padding: 2px 6px;
63
116
  border-radius: 4px;
@@ -85,9 +138,10 @@
85
138
  display: flex;
86
139
  justify-content: center;
87
140
  align-items: center;
88
- height: 8px;
141
+ height: 16px;
89
142
  margin: 0;
90
- font-size: 10px;
143
+ font-size: 16px;
144
+ font-weight: bold;
91
145
  color: #555;
92
146
  line-height: 1;
93
147
  }
@@ -8,7 +8,13 @@ export default class extends Controller {
8
8
  #drawArrowsBound
9
9
  #markerId = "history-arrow-head"
10
10
  #startX = 32
11
- #curveOffset = 40
11
+ // Curve offset scales with the vertical gap so arcs of different lengths
12
+ // nest instead of overlap. Bounded so short arcs don't collapse onto the
13
+ // stack and long arcs don't escape the sidebar pane (the stack only has
14
+ // `padding-left: 32px` of space before the chat area).
15
+ #minCurveOffset = 12
16
+ #maxCurveOffset = 28
17
+ #curveScale = 0.22
12
18
 
13
19
  connect() {
14
20
  this.#drawArrows()
@@ -102,13 +108,17 @@ export default class extends Controller {
102
108
  // Skip if cards are adjacent - straight arrow is rendered by helper
103
109
  if (verticalGap < 80) return
104
110
 
105
- const path = this.#createCurvedArrowPath(startY, endY)
111
+ const path = this.#createCurvedArrowPath(startY, endY, verticalGap)
106
112
  svg.appendChild(path)
107
113
  }
108
114
 
109
- #createCurvedArrowPath(startY, endY) {
115
+ #createCurvedArrowPath(startY, endY, verticalGap) {
110
116
  const startX = this.#startX // left edge margin
111
- const curveX = startX - this.#curveOffset // curve outward to the left
117
+ const curveOffset = Math.max(
118
+ this.#minCurveOffset,
119
+ Math.min(verticalGap * this.#curveScale, this.#maxCurveOffset)
120
+ )
121
+ const curveX = startX - curveOffset // curve outward to the left
112
122
  const pathData = `M ${startX} ${startY} C ${curveX} ${startY}, ${curveX} ${endY}, ${startX} ${endY}`
113
123
 
114
124
  const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
@@ -1,13 +1,16 @@
1
1
  <%
2
2
  active_uuid = locals[:active_uuid]
3
3
  card_path = locals[:card_path]
4
+ delete_path = locals[:delete_path]
5
+ # A PE is a leaf when no other PE in the chat references it as `previous`.
6
+ non_leaf_ids = @history.filter_map { |pe| pe.previous_id }
4
7
  %>
5
8
 
6
9
  <h2>History</h2>
7
10
  <% if @history.present? %>
8
11
  <div class="history-stack" data-controller="history">
9
12
  <% @history.each_with_index do |ann, idx| %>
10
- <%= render 'prompt_navigator/history_card', locals: { ann: ann, next_ann: @history[idx + 1], is_active: ann.execution_id == active_uuid, card_path: card_path } %>
13
+ <%= render 'prompt_navigator/history_card', locals: { ann: ann, next_ann: @history[idx + 1], is_active: ann.execution_id == active_uuid, card_path: card_path, delete_path: delete_path, is_leaf: !non_leaf_ids.include?(ann.id) } %>
11
14
  <% end %>
12
15
  <svg class="history-arrows" data-history-target="svg"></svg>
13
16
  </div>
@@ -4,18 +4,44 @@
4
4
  is_active = locals[:is_active]
5
5
  parent_uuid = ann.previous&.execution_id
6
6
  card_path = locals[:card_path]
7
+ delete_path = locals[:delete_path]
8
+ is_leaf = locals[:is_leaf]
9
+
10
+ # Hide leading attached-image data URIs (`![](data:image/png;base64,…)`).
11
+ # The base64 blob isn't useful in a 30-char preview — replace each with a
12
+ # short marker so the rest of the prompt text is visible.
13
+ display_prompt = ann.prompt.to_s.gsub(/!\[[^\]]*\]\(data:[^)]+\)/m, "[image]").strip
7
14
  %>
8
15
 
9
16
  <div class="history-card<%= ' is-active' if is_active %>" data-history-target="cards" data-uuid="<%= ann.execution_id %>" data-parent-uuid="<%= parent_uuid %>">
10
- <%= link_to card_path.call(ann.execution_id), class: "history-card-link" do %>
11
- <div class="history-card-prompt"><%= truncate(ann.prompt.to_s, length: 30) %></div>
17
+ <div class="history-card-row">
18
+ <%= link_to card_path.call(ann.execution_id), class: "history-card-link" do %>
19
+ <div class="history-card-prompt"><%= truncate(display_prompt, length: 30) %></div>
20
+ <% end %>
21
+ <% if is_leaf && delete_path %>
22
+ <%= button_to delete_path.call(ann.execution_id),
23
+ method: :delete,
24
+ class: "history-card-delete",
25
+ title: "Delete this prompt",
26
+ form: { class: "history-card-delete-form" },
27
+ data: { turbo_confirm: "Delete this prompt? This cannot be undone." } do %>
28
+ <i class="bi bi-trash"></i>
29
+ <% end %>
30
+ <% end %>
12
31
  <% if ann.llm_platform.present? %>
13
- <span class="history-card-platform-label" data-platform="<%= ann.llm_platform %>"><%= { "openai" => "GPT", "anthropic" => "A", "google" => "G", "ollama" => "O" }[ann.llm_platform] || ann.llm_platform %></span>
32
+ <% platform_label = PromptNavigator.label_for(platform: ann.llm_platform, model: ann.model) %>
33
+ <% tooltip = ann.model.present? ? "#{ann.model} (#{ann.llm_platform})" : ann.llm_platform.to_s %>
34
+ <span class="history-card-platform-label" data-platform="<%= ann.llm_platform %>" title="<%= tooltip %>"><%= platform_label %></span>
14
35
  <% end %>
15
- <% end %>
36
+ </div>
16
37
  </div>
17
38
 
18
- <%# Check !next_ann.nil? to prevent the "↑" arrow from appearing below the bottom history entry, as parent_uuid would be nil in that case. %>
19
- <% if !next_ann.nil? && parent_uuid == next_ann.execution_id %>
20
- <div class="history-straight-arrow">↑</div>
21
- <% end %>
39
+ <%# Direction-agnostic adjacency arrow: detect whether the next card is this card's
40
+ parent (newest-first ordering "↑") or its child (oldest-first ordering → "↓"). %>
41
+ <% if next_ann %>
42
+ <% if parent_uuid == next_ann.execution_id %>
43
+ <div class="history-straight-arrow">↑</div>
44
+ <% elsif next_ann.previous_id == ann.id %>
45
+ <div class="history-straight-arrow">↓</div>
46
+ <% end %>
47
+ <% end %>
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PromptNavigator
4
+ # Host-overridable display config for the history sidebar.
5
+ #
6
+ # Usage from a host app initializer:
7
+ #
8
+ # PromptNavigator.configure do |c|
9
+ # c.platform_labels["openai"] = "OAI" # override platform default
10
+ # c.model_labels["claude-opus-4-7"] = "Opus" # per-model override
11
+ # end
12
+ class Configuration
13
+ DEFAULT_PLATFORM_LABELS = {
14
+ "openai" => "GPT",
15
+ "anthropic" => "Claude",
16
+ "google" => "Gemini",
17
+ "ollama" => "Ollama"
18
+ }.freeze
19
+
20
+ attr_accessor :platform_labels, :model_labels
21
+
22
+ def initialize
23
+ @platform_labels = DEFAULT_PLATFORM_LABELS.dup
24
+ @model_labels = {}
25
+ end
26
+ end
27
+
28
+ def self.config
29
+ @config ||= Configuration.new
30
+ end
31
+
32
+ def self.configure
33
+ yield config
34
+ end
35
+
36
+ # Resolution order: per-model override → per-platform → raw platform string.
37
+ # Returns "" only when both inputs are blank.
38
+ def self.label_for(platform:, model: nil)
39
+ model_key = model.to_s
40
+ return config.model_labels[model_key] if model_key != "" && config.model_labels.key?(model_key)
41
+ platform_key = platform.to_s
42
+ config.platform_labels[platform_key] || platform_key
43
+ end
44
+ end
@@ -1,7 +1,11 @@
1
1
  module PromptNavigator
2
2
  module Helpers
3
- def history_list(card_path, active_uuid: nil)
4
- render "prompt_navigator/history", locals: { card_path: card_path, active_uuid: active_uuid }
3
+ def history_list(card_path, active_uuid: nil, delete_path: nil)
4
+ render "prompt_navigator/history", locals: {
5
+ card_path: card_path,
6
+ active_uuid: active_uuid,
7
+ delete_path: delete_path
8
+ }
5
9
  end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module PromptNavigator
2
- VERSION = "2.0.0"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "prompt_navigator/version"
4
+ require "prompt_navigator/configuration"
4
5
  require "prompt_navigator/engine"
5
6
  require "prompt_navigator/helpers"
6
7
  require_relative "../app/controllers/concerns/prompt_navigator/history_manageable"
7
8
 
8
9
  module PromptNavigator
9
- # Your code goes here...
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prompt_navigator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler
@@ -60,6 +60,7 @@ files:
60
60
  - lib/generators/prompt_navigator/modeling/modeling_generator.rb
61
61
  - lib/generators/prompt_navigator/modeling/templates/db/migrate/20260129073026_create_prompt_navigator_prompt_executions.rb
62
62
  - lib/prompt_navigator.rb
63
+ - lib/prompt_navigator/configuration.rb
63
64
  - lib/prompt_navigator/engine.rb
64
65
  - lib/prompt_navigator/helpers.rb
65
66
  - lib/prompt_navigator/version.rb