Commit - use types from SDK

This commit is contained in:
Shantur Rathore
2025-11-11 21:06:37 +00:00
parent 063a11db76
commit 89dbe43d87
17 changed files with 691 additions and 244 deletions

View File

@@ -1,4 +1,16 @@
import { createSignal } from "solid-js"
import {
MessageUpdateEvent,
MessageRemovedEvent,
MessagePartUpdatedEvent,
MessagePartRemovedEvent
} from "../types/message"
import type {
EventSessionUpdated,
EventSessionCompacted,
EventSessionError,
EventSessionIdle
} from "@opencode-ai/sdk"
interface SSEConnection {
instanceId: string
@@ -7,19 +19,6 @@ interface SSEConnection {
status: "connecting" | "connected" | "disconnected" | "error"
}
interface MessageUpdateEvent {
type: "message_updated"
sessionId: string
messageId: string
parts: any[]
status: string
}
interface SessionUpdateEvent {
type: "session_updated"
session: any
}
interface TuiToastEvent {
type: "tui.toast.show"
properties: {
@@ -30,12 +29,17 @@ interface TuiToastEvent {
}
}
interface SessionIdleEvent {
type: "session.idle"
properties: {
sessionID: string
}
}
type SSEEvent =
| MessageUpdateEvent
| MessageRemovedEvent
| MessagePartUpdatedEvent
| MessagePartRemovedEvent
| EventSessionUpdated
| EventSessionCompacted
| EventSessionError
| EventSessionIdle
| TuiToastEvent
| { type: string; properties?: Record<string, unknown> } // Fallback for unknown event types
const [connectionStatus, setConnectionStatus] = createSignal<
Map<string, "connecting" | "connected" | "disconnected" | "error">
@@ -98,34 +102,36 @@ class SSEManager {
}
}
private handleEvent(instanceId: string, event: any): void {
private handleEvent(instanceId: string, event: SSEEvent): void {
console.log("[SSE] Received event:", event.type, event)
switch (event.type) {
case "message.updated":
this.onMessageUpdate?.(instanceId, event as MessageUpdateEvent)
break
case "message.part.updated":
this.onMessageUpdate?.(instanceId, event)
this.onMessagePartUpdated?.(instanceId, event as MessagePartUpdatedEvent)
break
case "message.removed":
this.onMessageRemoved?.(instanceId, event)
this.onMessageRemoved?.(instanceId, event as MessageRemovedEvent)
break
case "message.part.removed":
this.onMessagePartRemoved?.(instanceId, event)
this.onMessagePartRemoved?.(instanceId, event as MessagePartRemovedEvent)
break
case "session.updated":
this.onSessionUpdate?.(instanceId, event)
this.onSessionUpdate?.(instanceId, event as EventSessionUpdated)
break
case "session.compacted":
this.onSessionCompacted?.(instanceId, event)
this.onSessionCompacted?.(instanceId, event as EventSessionCompacted)
break
case "session.error":
this.onSessionError?.(instanceId, event)
this.onSessionError?.(instanceId, event as EventSessionError)
break
case "tui.toast.show":
this.onTuiToast?.(instanceId, event as TuiToastEvent)
break
case "session.idle":
this.onSessionIdle?.(instanceId, event as SessionIdleEvent)
this.onSessionIdle?.(instanceId, event as EventSessionIdle)
break
default:
console.warn("[SSE] Unknown event type:", event.type)
@@ -162,13 +168,14 @@ class SSEManager {
}
onMessageUpdate?: (instanceId: string, event: MessageUpdateEvent) => void
onMessageRemoved?: (instanceId: string, event: any) => void
onMessagePartRemoved?: (instanceId: string, event: any) => void
onSessionUpdate?: (instanceId: string, event: SessionUpdateEvent) => void
onSessionCompacted?: (instanceId: string, event: any) => void
onSessionError?: (instanceId: string, event: any) => void
onMessageRemoved?: (instanceId: string, event: MessageRemovedEvent) => void
onMessagePartUpdated?: (instanceId: string, event: MessagePartUpdatedEvent) => void
onMessagePartRemoved?: (instanceId: string, event: MessagePartRemovedEvent) => void
onSessionUpdate?: (instanceId: string, event: EventSessionUpdated) => void
onSessionCompacted?: (instanceId: string, event: EventSessionCompacted) => void
onSessionError?: (instanceId: string, event: EventSessionError) => void
onTuiToast?: (instanceId: string, event: TuiToastEvent) => void
onSessionIdle?: (instanceId: string, event: SessionIdleEvent) => void
onSessionIdle?: (instanceId: string, event: EventSessionIdle) => void
getStatus(instanceId: string): "connecting" | "connected" | "disconnected" | "error" | null {
return connectionStatus().get(instanceId) ?? null

View File

@@ -4,6 +4,7 @@ export interface ConfigData {
preferences: Preferences
recentFolders: RecentFolder[]
opencodeBinaries: OpenCodeBinary[]
theme?: "light" | "dark" | "system"
}
export interface InstanceData {

View File

@@ -1,5 +1,5 @@
import { createContext, createSignal, useContext, onMount, createEffect, type JSX } from "solid-js"
import { storage } from "./storage"
import { storage, type ConfigData } from "./storage"
interface ThemeContextValue {
isDark: () => boolean
@@ -28,7 +28,7 @@ export function ThemeProvider(props: { children: JSX.Element }) {
async function loadTheme() {
try {
const config = await storage.loadConfig()
const savedTheme = (config as any)?.theme
const savedTheme = config.theme
let themeDark: boolean
if (savedTheme === "system") {
@@ -60,7 +60,7 @@ export function ThemeProvider(props: { children: JSX.Element }) {
try {
const config = await storage.loadConfig()
const nextPreference = dark ? "dark" : "light"
;(config as any).theme = nextPreference
config.theme = nextPreference
themePreference = nextPreference
await storage.saveConfig(config)
} catch (error) {