Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: add tygo type generation from Go

Bosch138690b28540
diff --git a/dashboard/src/components/molecules/InstanceCard.tsx b/dashboard/src/components/molecules/InstanceCard.tsx
index 5207274a..5096e642 100644
--- a/dashboard/src/components/molecules/InstanceCard.tsx
+++ b/dashboard/src/components/molecules/InstanceCard.tsx
@@ -7,8 +7,8 @@ interface Props {
onStop: () => void
}
-function formatUptime(startedAt: string): string {
- const diff = Date.now() - new Date(startedAt).getTime()
+function formatUptime(startTime: string): string {
+ const diff = Date.now() - new Date(startTime).getTime()
const mins = Math.floor(diff / 60000)
if (mins < 60) return `${mins}m`
const hours = Math.floor(mins / 60)
@@ -39,7 +39,7 @@ export default function InstanceCard({ instance, onOpen, onStop }: Props) {
</div>
<div className="rounded bg-bg-elevated px-2 py-1.5">
<span className="text-text-muted">Uptime:</span>{' '}
- <span className="text-text-secondary">{formatUptime(instance.startedAt)}</span>
+ <span className="text-text-secondary">{formatUptime(instance.startTime)}</span>
</div>
</div>
diff --git a/dashboard/src/generated/types.ts b/dashboard/src/generated/types.ts
new file mode 100644
index 00000000..b627eac3
--- /dev/null
+++ b/dashboard/src/generated/types.ts
@@ -0,0 +1,109 @@
+// Code generated by tygo. DO NOT EDIT.
+
+//////////
+// source: types.go
+/*
+Package types contains shared API types for the dashboard.
+These types are exported to TypeScript via tygo.
+*/
+
+/**
+ * Profile represents a browser profile stored on disk.
+ */
+export interface Profile {
+ id: string;
+ name: string;
+ path?: string;
+ useWhen?: string;
+ created: string;
+ lastUsed: string;
+ diskUsage: number /* int64 */;
+ running: boolean;
+ source?: string;
+}
+/**
+ * Instance represents a running browser instance.
+ */
+export interface Instance {
+ id: string;
+ profileId: string;
+ profileName: string;
+ port: number /* int */;
+ headless: boolean;
+ status: string; // starting/running/stopping/stopped/error
+ startTime: string;
+ tabs: number /* int */;
+ error?: string;
+}
+/**
+ * Agent represents a connected AI agent.
+ */
+export interface Agent {
+ id: string;
+ name?: string;
+ connectedAt: string;
+ lastActivity?: string;
+ requestCount: number /* int */;
+}
+/**
+ * ActivityEvent represents an action in the activity feed.
+ */
+export interface ActivityEvent {
+ id: string;
+ agentId: string;
+ type: string; // navigate/snapshot/action/screenshot/other
+ method: string;
+ path: string;
+ timestamp: string;
+ details?: { [key: string]: any};
+}
+/**
+ * ScreencastSettings configures live tab previews.
+ */
+export interface ScreencastSettings {
+ fps: number /* int */;
+ quality: number /* int */;
+ maxWidth: number /* int */;
+}
+/**
+ * BrowserSettings configures browser behavior.
+ */
+export interface BrowserSettings {
+ blockImages: boolean;
+ blockMedia: boolean;
+ noAnimations: boolean;
+}
+/**
+ * Settings contains all dashboard settings.
+ */
+export interface Settings {
+ screencast: ScreencastSettings;
+ stealth: string; // light/full
+ browser: BrowserSettings;
+}
+/**
+ * ServerInfo contains health/status information.
+ */
+export interface ServerInfo {
+ version: string;
+ uptime: number /* int64 */;
+ profiles: number /* int */;
+ instances: number /* int */;
+ agents: number /* int */;
+}
+/**
+ * CreateProfileRequest is the request body for creating a profile.
+ */
+export interface CreateProfileRequest {
+ name: string;
+ useWhen?: string;
+ source?: string;
+}
+/**
+ * LaunchInstanceRequest is the request body for launching an instance.
+ */
+export interface LaunchInstanceRequest {
+ profileId: string;
+ port?: number /* int */;
+ headless?: boolean;
+}
diff --git a/dashboard/src/pages/ProfilesPage.tsx b/dashboard/src/pages/ProfilesPage.tsx
index e83be5e4..21cfbd7d 100644
--- a/dashboard/src/pages/ProfilesPage.tsx
+++ b/dashboard/src/pages/ProfilesPage.tsx
@@ -58,7 +58,7 @@ export default function ProfilesPage() {
if (!showLaunch) return
try {
await api.launchInstance({
- profile: showLaunch,
+ profileId: showLaunch,
port: parseInt(launchPort) || 9868,
headless: launchHeadless,
})
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 1bcc0c21..0dd4b3c5 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -1,4 +1,12 @@
-import type { Profile, Instance, Agent, Settings, ServerInfo } from '../types'
+import type {
+ Profile,
+ Instance,
+ Agent,
+ Settings,
+ ServerInfo,
+ CreateProfileRequest,
+ LaunchInstanceRequest,
+} from '../generated/types'
const BASE = '' // Uses proxy in dev
@@ -16,11 +24,7 @@ export async function fetchProfiles(): Promise<Profile[]> {
return request<Profile[]>('/api/profiles')
}
-export async function createProfile(data: {
- name: string
- useWhen?: string
- source?: string
-}): Promise<Profile> {
+export async function createProfile(data: CreateProfileRequest): Promise<Profile> {
return request<Profile>('/api/profiles', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -28,8 +32,8 @@ export async function createProfile(data: {
})
}
-export async function deleteProfile(name: string): Promise<void> {
- await request<void>(`/api/profiles/${encodeURIComponent(name)}`, {
+export async function deleteProfile(id: string): Promise<void> {
+ await request<void>(`/api/profiles/${encodeURIComponent(id)}`, {
method: 'DELETE',
})
}
@@ -39,11 +43,7 @@ export async function fetchInstances(): Promise<Instance[]> {
return request<Instance[]>('/api/instances')
}
-export async function launchInstance(data: {
- profile: string
- port: number
- headless?: boolean
-}): Promise<Instance> {
+export async function launchInstance(data: LaunchInstanceRequest): Promise<Instance> {
return request<Instance>('/api/instances', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
diff --git a/dashboard/src/stores/useAppStore.ts b/dashboard/src/stores/useAppStore.ts
index e1c8a74b..899d6b96 100644
--- a/dashboard/src/stores/useAppStore.ts
+++ b/dashboard/src/stores/useAppStore.ts
@@ -1,5 +1,13 @@
import { create } from 'zustand'
-import type { View, Profile, Instance, Agent, ActivityEvent, Settings, ServerInfo } from '../types'
+import type {
+ Profile,
+ Instance,
+ Agent,
+ ActivityEvent,
+ Settings,
+ ServerInfo,
+} from '../generated/types'
+import type { View } from '../types'
interface AppState {
// Navigation
diff --git a/dashboard/src/types/index.ts b/dashboard/src/types/index.ts
index 2e513039..f8a4634c 100644
--- a/dashboard/src/types/index.ts
+++ b/dashboard/src/types/index.ts
@@ -1,65 +1,16 @@
-// Profile stored on disk
-export interface Profile {
- name: string
- path: string
- useWhen?: string
- createdAt?: string
-}
+// Re-export generated types from Go
+export type {
+ Profile,
+ Instance,
+ Agent,
+ ActivityEvent,
+ Settings,
+ ScreencastSettings,
+ BrowserSettings,
+ ServerInfo,
+ CreateProfileRequest,
+ LaunchInstanceRequest,
+} from '../generated/types'
-// Running browser instance
-export interface Instance {
- id: string
- profileName: string
- port: number
- pid: number
- headless: boolean
- startedAt: string
- tabs?: number
-}
-
-// Connected agent
-export interface Agent {
- id: string
- name?: string
- connectedAt: string
- lastActivity?: string
- requestCount: number
-}
-
-// Activity feed event
-export interface ActivityEvent {
- id: string
- agentId: string
- type: 'navigate' | 'snapshot' | 'action' | 'screenshot' | 'other'
- method: string
- path: string
- timestamp: string
- details?: Record<string, unknown>
-}
-
-// Settings
-export interface Settings {
- screencast: {
- fps: number
- quality: number
- maxWidth: number
- }
- stealth: 'light' | 'full'
- browser: {
- blockImages: boolean
- blockMedia: boolean
- noAnimations: boolean
- }
-}
-
-// Server health info
-export interface ServerInfo {
- version: string
- uptime: number
- profiles: number
- instances: number
- agents: number
-}
-
-// View type
+// View type (frontend only)
export type View = 'profiles' | 'instances' | 'agents' | 'settings'
diff --git a/internal/api/types/types.go b/internal/api/types/types.go
new file mode 100644
index 00000000..3f73f8f3
--- /dev/null
+++ b/internal/api/types/types.go
@@ -0,0 +1,95 @@
+// Package types contains shared API types for the dashboard.
+// These types are exported to TypeScript via tygo.
+package types
+
+import "time"
+
+// Profile represents a browser profile stored on disk.
+type Profile struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Path string `json:"path,omitempty"`
+ UseWhen string `json:"useWhen,omitempty"`
+ Created time.Time `json:"created"`
+ LastUsed time.Time `json:"lastUsed"`
+ DiskUsage int64 `json:"diskUsage"`
+ Running bool `json:"running"`
+ Source string `json:"source,omitempty"`
+}
+
+// Instance represents a running browser instance.
+type Instance struct {
+ ID string `json:"id"`
+ ProfileID string `json:"profileId"`
+ ProfileName string `json:"profileName"`
+ Port int `json:"port"`
+ Headless bool `json:"headless"`
+ Status string `json:"status"` // starting/running/stopping/stopped/error
+ StartTime time.Time `json:"startTime"`
+ Tabs int `json:"tabs"`
+ Error string `json:"error,omitempty"`
+}
+
+// Agent represents a connected AI agent.
+type Agent struct {
+ ID string `json:"id"`
+ Name string `json:"name,omitempty"`
+ ConnectedAt time.Time `json:"connectedAt"`
+ LastActivity time.Time `json:"lastActivity,omitempty"`
+ RequestCount int `json:"requestCount"`
+}
+
+// ActivityEvent represents an action in the activity feed.
+type ActivityEvent struct {
+ ID string `json:"id"`
+ AgentID string `json:"agentId"`
+ Type string `json:"type"` // navigate/snapshot/action/screenshot/other
+ Method string `json:"method"`
+ Path string `json:"path"`
+ Timestamp time.Time `json:"timestamp"`
+ Details map[string]interface{} `json:"details,omitempty"`
+}
+
+// ScreencastSettings configures live tab previews.
+type ScreencastSettings struct {
+ FPS int `json:"fps"`
+ Quality int `json:"quality"`
+ MaxWidth int `json:"maxWidth"`
+}
+
+// BrowserSettings configures browser behavior.
+type BrowserSettings struct {
+ BlockImages bool `json:"blockImages"`
+ BlockMedia bool `json:"blockMedia"`
+ NoAnimations bool `json:"noAnimations"`
+}
+
+// Settings contains all dashboard settings.
+type Settings struct {
+ Screencast ScreencastSettings `json:"screencast"`
+ Stealth string `json:"stealth"` // light/full
+ Browser BrowserSettings `json:"browser"`
+}
+
+// ServerInfo contains health/status information.
+type ServerInfo struct {
+ Version string `json:"version"`
+ Uptime int64 `json:"uptime"`
+ Profiles int `json:"profiles"`
+ Instances int `json:"instances"`
+ Agents int `json:"agents"`
+}
+
+// CreateProfileRequest is the request body for creating a profile.
+type CreateProfileRequest struct {
+ Name string `json:"name"`
+ UseWhen string `json:"useWhen,omitempty"`
+ Source string `json:"source,omitempty"`
+}
+
+// LaunchInstanceRequest is the request body for launching an instance.
+type LaunchInstanceRequest struct {
+ ProfileID string `json:"profileId"`
+ Port int `json:"port,omitempty"`
+ Headless bool `json:"headless,omitempty"`
+}
diff --git a/scripts/generate-types.sh b/scripts/generate-types.sh
new file mode 100755
index 00000000..8efa2012
--- /dev/null
+++ b/scripts/generate-types.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+# Generate TypeScript types from Go structs using tygo
+set -e
+
+cd "$(dirname "$0")/.."
+
+# Ensure tygo is installed
+if ! command -v tygo &> /dev/null; then
+ echo "Installing tygo..."
+ go install github.com/gzuidhof/tygo@latest
+fi
+
+# Generate types
+echo "Generating TypeScript types..."
+tygo generate
+
+echo "✓ Types generated: dashboard/src/generated/types.ts"
diff --git a/tygo.yaml b/tygo.yaml
new file mode 100644
index 00000000..aa557b15
--- /dev/null
+++ b/tygo.yaml
@@ -0,0 +1,6 @@
+packages:
+ - path: "github.com/pinchtab/pinchtab/internal/api/types"
+ output_path: "dashboard/src/generated/types.ts"
+ type_mappings:
+ time.Time: "string"
+ "map[string]interface{}": "Record<string, unknown>"