"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.RuntimeStatusView = void 0; const vscode = __importStar(require("vscode")); class RuntimeStatusView { static viewType = "codewhale.runtimeStatus"; view; state = { kind: "offline", baseUrl: "http://127.0.0.1:7878", detail: "Runtime has not been checked yet.", }; threads = []; threadsDetail = "Connect to the runtime to load recent threads."; snapshots = []; snapshotsDetail = "Connect to the runtime to load restore points."; resolveWebviewView(view) { this.view = view; view.webview.options = { enableScripts: true }; view.webview.onDidReceiveMessage((message) => { if (message.command === "check") { void vscode.commands.executeCommand("codewhale.checkRuntime"); } else if (message.command === "start") { void vscode.commands.executeCommand("codewhale.startRuntime"); } else if (message.command === "terminal") { void vscode.commands.executeCommand("codewhale.openTerminal"); } else if (message.command === "threads") { void vscode.commands.executeCommand("codewhale.refreshAgentView"); } else if (message.command === "snapshots") { void vscode.commands.executeCommand("codewhale.refreshSnapshots"); } }); this.render(); } update(state) { this.state = state; this.render(); } updateThreads(threads, detail) { this.threads = threads; this.threadsDetail = detail; this.render(); } updateSnapshots(snapshots, detail) { this.snapshots = snapshots; this.snapshotsDetail = detail; this.render(); } render() { if (!this.view) { return; } const badge = labelFor(this.state.kind); const nonce = makeNonce(); const threadsHtml = this.threads.length > 0 ? this.threads.map((thread) => renderThread(thread)).join("") : `

${escapeHtml(this.threadsDetail)}

`; const snapshotsHtml = this.snapshots.length > 0 ? this.snapshots.map((snapshot) => renderSnapshot(snapshot)).join("") : `

${escapeHtml(this.snapshotsDetail)}

`; this.view.webview.html = `
${escapeHtml(badge)}

${escapeHtml(this.state.detail)}

${escapeHtml(this.state.baseUrl)}

Agent View
${threadsHtml}
Restore Points
${snapshotsHtml} `; } } exports.RuntimeStatusView = RuntimeStatusView; function renderSnapshot(snapshot) { return `
${escapeHtml(snapshot.label)}
${escapeHtml(`${snapshot.id} · ${formatUnixTimestamp(snapshot.timestamp)}`)}
`; } function renderThread(thread) { const status = thread.latestTurnStatus ? ` · ${thread.latestTurnStatus}` : ""; const archived = thread.archived ? " · archived" : ""; const git = renderGitMetadata(thread); const workspace = thread.workspace ? ` · ${thread.workspace}` : ""; const updated = thread.updatedAt ? ` · ${formatTimestamp(thread.updatedAt)}` : ""; return `
${escapeHtml(thread.title)}
${escapeHtml(thread.preview || "No recent message.")}
${escapeHtml(`${thread.mode} · ${thread.model}${status}${git}${archived}${updated}${workspace}`)}
`; } function renderGitMetadata(thread) { if (!thread.branch && !thread.head && !thread.dirty) { return ""; } const parts = []; if (thread.branch) { parts.push(`branch ${thread.branch}`); } if (thread.head) { parts.push(`@ ${thread.head}`); } if (thread.dirty) { parts.push("dirty"); } return ` · ${parts.join(" ")}`; } function labelFor(kind) { switch (kind) { case "connected": return "Connected"; case "auth-required": return "Token Required"; case "error": return "Runtime Error"; case "offline": return "Offline"; } } function formatTimestamp(value) { const date = new Date(value); if (Number.isNaN(date.getTime())) { return value; } return date.toLocaleString(); } function formatUnixTimestamp(value) { const date = new Date(value * 1000); if (Number.isNaN(date.getTime())) { return String(value); } return date.toLocaleString(); } function escapeHtml(value) { return value .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); } function makeNonce() { const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let nonce = ""; for (let index = 0; index < 32; index += 1) { nonce += alphabet.charAt(Math.floor(Math.random() * alphabet.length)); } return nonce; } //# sourceMappingURL=status.js.map