| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| 2 | import { customElement, property } from "lit/decorators.js"; |
| 3 | import { ToolCall } from "../types"; |
| 4 | |
| 5 | type DodoOutput = { |
| 6 | config: string; |
| 7 | }; |
| 8 | |
| 9 | @customElement("sketch-tool-card-dodo-get-project-config") |
| 10 | export class SketchToolCardDodoGetProjectConfig extends LitElement { |
| 11 | @property() |
| 12 | toolCall: ToolCall; |
| 13 | |
| 14 | @property() |
| 15 | open: boolean; |
| 16 | |
| 17 | static styles = css` |
| 18 | .summary-text { |
| 19 | font-family: monospace; |
| 20 | color: #444; |
| 21 | word-break: break-all; |
| 22 | } |
| 23 | |
| 24 | .selector-input { |
| 25 | font-family: monospace; |
| 26 | background: rgba(0, 0, 0, 0.05); |
| 27 | padding: 4px 8px; |
| 28 | border-radius: 4px; |
| 29 | display: inline-block; |
| 30 | word-break: break-all; |
| 31 | } |
| 32 | `; |
| 33 | |
| 34 | render() { |
| 35 | // Parse the input to get selector |
| 36 | console.log(this.toolCall); |
| 37 | let apiBaseAddress = ""; |
| 38 | let projectId = ""; |
| 39 | try { |
| 40 | if (this.toolCall?.input) { |
| 41 | const inp = JSON.parse(this.toolCall.input); |
| 42 | apiBaseAddress = inp.apiBaseAddress || ""; |
| 43 | projectId = inp.projectId || ""; |
| 44 | } |
| 45 | } catch (e) { |
| 46 | console.error("Error parsing dodo input:", e); |
| 47 | } |
| 48 | |
| 49 | let output: DodoOutput | null = null; |
| 50 | try { |
| 51 | if (this.toolCall?.result_message?.tool_result) { |
| 52 | output = JSON.parse(this.toolCall.result_message.tool_result); |
| 53 | } |
| 54 | } catch (e) { |
| 55 | console.error("Error parsing dodo output:", e); |
| 56 | } |
| 57 | |
| 58 | if (output == null) { |
| 59 | throw new Error("No output from dodo tool call"); |
| 60 | } |
| 61 | |
| 62 | return html` |
| 63 | <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 64 | <span slot="summary" class="summary-text"> 🖱️ ${projectId} </span> |
| 65 | <div slot="input"> |
| 66 | <div> |
| 67 | API Base Address: <span class="selector-input">${apiBaseAddress}</span> |
| 68 | </div> |
| 69 | <div> |
| 70 | Project ID: <span class="selector-input">${projectId}</span> |
| 71 | </div> |
| 72 | </div> |
| 73 | <div slot="result"> |
| 74 | <pre>${output.config}</pre> |
| 75 | </div> |
| 76 | </sketch-tool-card> |
| 77 | `; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | declare global { |
| 82 | interface HTMLElementTagNameMap { |
| 83 | "sketch-tool-card-dodo-get-project-config": SketchToolCardDodoGetProjectConfig; |
| 84 | } |
| 85 | } |