Thomas G. Lopes commited on
Commit
6c3123d
·
1 Parent(s): 7d76168

duplication

Browse files
Files changed (1) hide show
  1. src/routes/canvas/chat-node.svelte +78 -31
src/routes/canvas/chat-node.svelte CHANGED
@@ -11,6 +11,7 @@
11
  import IconAdd from "~icons/lucide/plus";
12
  import IconX from "~icons/lucide/x";
13
  import IconStop from "~icons/lucide/square";
 
14
  import type { ChatCompletionInputMessage } from "@huggingface/tasks";
15
  import ModelPicker from "./model-picker.svelte";
16
  import ProviderPicker from "./provider-picker.svelte";
@@ -209,37 +210,83 @@
209
  </div>
210
  {/if}
211
 
212
- <!-- Add node button -->
213
- <button
214
- class="abs-x-center absolute -bottom-4 z-10 flex items-center gap-1.5 rounded-full bg-black
215
- px-4 py-2 text-xs font-medium text-white opacity-0
216
- shadow-sm transition-all group-hover:opacity-100 hover:scale-[1.02]
217
- hover:bg-gray-900 focus:ring-2 focus:ring-gray-900/20 focus:outline-none active:scale-[0.98]"
218
- onclick={() => {
219
- const curr = getNode(id);
220
- const newNode: Node = {
221
- id: crypto.randomUUID(),
222
- position: { x: curr?.position.x ?? 100, y: (curr?.position.y ?? 0) + size.height + 40 },
223
- data: { query: "", response: "", modelId: data.modelId, provider: data.provider },
224
- type: "chat",
225
- width: undefined,
226
- height: undefined,
227
- };
228
- nodes.current.push(newNode);
229
- const edge: Edge = {
230
- id: crypto.randomUUID(),
231
- source: curr!.id,
232
- target: newNode.id,
233
- animated: true,
234
- label: "",
235
- data: {},
236
- };
237
- edges.current.push(edge);
238
- }}
239
- >
240
- <IconAdd class="h-3 w-3" />
241
- Add Node
242
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
  <!-- Close button -->
245
  <button
 
11
  import IconAdd from "~icons/lucide/plus";
12
  import IconX from "~icons/lucide/x";
13
  import IconStop from "~icons/lucide/square";
14
+ import IconCopy from "~icons/lucide/copy";
15
  import type { ChatCompletionInputMessage } from "@huggingface/tasks";
16
  import ModelPicker from "./model-picker.svelte";
17
  import ProviderPicker from "./provider-picker.svelte";
 
210
  </div>
211
  {/if}
212
 
213
+ <!-- Action buttons -->
214
+ <div class="abs-x-center absolute -bottom-4 z-10 flex gap-2 opacity-0 transition-all group-hover:opacity-100">
215
+ <!-- Duplicate button -->
216
+ <button
217
+ class="flex items-center gap-1.5 rounded-full bg-gray-700
218
+ px-4 py-2 text-xs font-medium text-white
219
+ shadow-sm transition-all hover:scale-[1.02]
220
+ hover:bg-gray-600 focus:ring-2 focus:ring-gray-600/20 focus:outline-none active:scale-[0.98]"
221
+ onclick={() => {
222
+ const curr = getNode(id);
223
+ const newNodeId = crypto.randomUUID();
224
+ const newNode: Node = {
225
+ id: newNodeId,
226
+ position: { x: (curr?.position.x ?? 100) + 50, y: (curr?.position.y ?? 0) + 50 },
227
+ data: {
228
+ query: data.query,
229
+ response: data.response,
230
+ modelId: data.modelId,
231
+ provider: data.provider,
232
+ },
233
+ type: "chat",
234
+ width: undefined,
235
+ height: undefined,
236
+ };
237
+ nodes.current.push(newNode);
238
+
239
+ // Copy only incoming edges (parent connections)
240
+ const incomingEdges = edges.current.filter(edge => edge.target === id);
241
+ for (const edge of incomingEdges) {
242
+ const newEdge: Edge = {
243
+ id: crypto.randomUUID(),
244
+ source: edge.source,
245
+ target: newNodeId,
246
+ animated: edge.animated,
247
+ label: edge.label,
248
+ data: edge.data,
249
+ };
250
+ edges.current.push(newEdge);
251
+ }
252
+ }}
253
+ >
254
+ <IconCopy class="h-3 w-3" />
255
+ Duplicate
256
+ </button>
257
+
258
+ <!-- Add node button -->
259
+ <button
260
+ class="flex items-center gap-1.5 rounded-full bg-black
261
+ px-4 py-2 text-xs font-medium text-white
262
+ shadow-sm transition-all hover:scale-[1.02]
263
+ hover:bg-gray-900 focus:ring-2 focus:ring-gray-900/20 focus:outline-none active:scale-[0.98]"
264
+ onclick={() => {
265
+ const curr = getNode(id);
266
+ const newNode: Node = {
267
+ id: crypto.randomUUID(),
268
+ position: { x: curr?.position.x ?? 100, y: (curr?.position.y ?? 0) + size.height + 40 },
269
+ data: { query: "", response: "", modelId: data.modelId, provider: data.provider },
270
+ type: "chat",
271
+ width: undefined,
272
+ height: undefined,
273
+ };
274
+ nodes.current.push(newNode);
275
+ const edge: Edge = {
276
+ id: crypto.randomUUID(),
277
+ source: curr!.id,
278
+ target: newNode.id,
279
+ animated: true,
280
+ label: "",
281
+ data: {},
282
+ };
283
+ edges.current.push(edge);
284
+ }}
285
+ >
286
+ <IconAdd class="h-3 w-3" />
287
+ Add Node
288
+ </button>
289
+ </div>
290
 
291
  <!-- Close button -->
292
  <button