Commit - use types from SDK
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { OpencodeClient } from "@opencode-ai/sdk/client"
|
||||
import type { Project as SDKProject } from "@opencode-ai/sdk"
|
||||
|
||||
export interface LogEntry {
|
||||
timestamp: number
|
||||
@@ -6,24 +7,23 @@ export interface LogEntry {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface ProjectInfo {
|
||||
id: string
|
||||
worktree: string
|
||||
vcs?: "git"
|
||||
time: {
|
||||
created: number
|
||||
initialized?: number
|
||||
}
|
||||
}
|
||||
// Use SDK Project type instead of our own
|
||||
export type ProjectInfo = SDKProject
|
||||
|
||||
export interface McpServerStatus {
|
||||
name: string
|
||||
status: "running" | "stopped" | "error"
|
||||
}
|
||||
|
||||
// Raw MCP status from server (SDK returns unknown for /mcp endpoint)
|
||||
export type RawMcpStatus = Record<string, {
|
||||
status?: string
|
||||
error?: string
|
||||
}>
|
||||
|
||||
export interface InstanceMetadata {
|
||||
project?: ProjectInfo
|
||||
mcpStatus?: unknown
|
||||
mcpStatus?: RawMcpStatus
|
||||
version?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,23 @@
|
||||
// SDK types
|
||||
import type {
|
||||
EventMessageUpdated as MessageUpdateEvent,
|
||||
EventMessageRemoved as MessageRemovedEvent,
|
||||
EventMessagePartUpdated as MessagePartUpdatedEvent,
|
||||
EventMessagePartRemoved as MessagePartRemovedEvent,
|
||||
Part as SDKPart,
|
||||
Message as SDKMessage
|
||||
} from "@opencode-ai/sdk"
|
||||
|
||||
// Re-export for other modules
|
||||
export type {
|
||||
MessageUpdateEvent,
|
||||
MessageRemovedEvent,
|
||||
MessagePartUpdatedEvent,
|
||||
MessagePartRemovedEvent,
|
||||
SDKPart,
|
||||
SDKMessage
|
||||
}
|
||||
|
||||
export interface RenderCache {
|
||||
text: string
|
||||
html: string
|
||||
@@ -5,11 +25,20 @@ export interface RenderCache {
|
||||
mode?: string
|
||||
}
|
||||
|
||||
// Client-specific part extensions (using intersection type since SDKPart is a union)
|
||||
export type ClientPart = SDKPart & {
|
||||
sessionID?: string
|
||||
messageID?: string
|
||||
synthetic?: boolean
|
||||
version?: number
|
||||
renderCache?: RenderCache
|
||||
}
|
||||
|
||||
export interface MessageDisplayParts {
|
||||
text: any[]
|
||||
tool: any[]
|
||||
reasoning: any[]
|
||||
combined: any[]
|
||||
text: ClientPart[]
|
||||
tool: ClientPart[]
|
||||
reasoning: ClientPart[]
|
||||
combined: ClientPart[]
|
||||
showThinking: boolean
|
||||
version: number
|
||||
}
|
||||
@@ -18,7 +47,7 @@ export interface Message {
|
||||
id: string
|
||||
sessionId: string
|
||||
type: "user" | "assistant"
|
||||
parts: any[]
|
||||
parts: ClientPart[]
|
||||
timestamp: number
|
||||
status: "sending" | "sent" | "streaming" | "complete" | "error"
|
||||
version: number
|
||||
@@ -34,42 +63,41 @@ export interface TextPart {
|
||||
renderCache?: RenderCache
|
||||
}
|
||||
|
||||
function hasTextSegment(segment: unknown): boolean {
|
||||
export type MessageInfo = SDKMessage
|
||||
|
||||
function hasTextSegment(segment: string | { text?: string }): boolean {
|
||||
if (typeof segment === "string") {
|
||||
return segment.trim().length > 0
|
||||
}
|
||||
|
||||
if (segment && typeof segment === "object") {
|
||||
const maybeText = (segment as { text?: unknown }).text
|
||||
if (typeof maybeText === "string") {
|
||||
return maybeText.trim().length > 0
|
||||
}
|
||||
if (segment && typeof segment === "object" && segment.text) {
|
||||
return typeof segment.text === "string" && segment.text.trim().length > 0
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function partHasRenderableText(part: any): boolean {
|
||||
export function partHasRenderableText(part: ClientPart): boolean {
|
||||
if (!part || typeof part !== "object") {
|
||||
return false
|
||||
}
|
||||
|
||||
if (hasTextSegment(part.text)) {
|
||||
const typedPart = part as SDKPart
|
||||
|
||||
if (typedPart.type === "text" && hasTextSegment(typedPart.text)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const contentArray = Array.isArray(part?.content) ? part.content : []
|
||||
for (const item of contentArray) {
|
||||
if (hasTextSegment(item)) {
|
||||
return true
|
||||
}
|
||||
if (typedPart.type === "file" && (typedPart as any).filename) {
|
||||
return true
|
||||
}
|
||||
|
||||
const thinkingContent = Array.isArray(part?.thinking?.content) ? part.thinking.content : []
|
||||
for (const chunk of thinkingContent) {
|
||||
if (hasTextSegment(chunk)) {
|
||||
return true
|
||||
}
|
||||
if (typedPart.type === "tool") {
|
||||
return true // Tool parts are always renderable
|
||||
}
|
||||
|
||||
if (typedPart.type === "reasoning" && hasTextSegment(typedPart.text)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@@ -1,29 +1,64 @@
|
||||
import type { Message } from "./message"
|
||||
import type { Message, MessageInfo } from "./message"
|
||||
import type {
|
||||
Session as SDKSession,
|
||||
Agent as SDKAgent,
|
||||
Provider as SDKProvider,
|
||||
Model as SDKModel
|
||||
} from "@opencode-ai/sdk"
|
||||
|
||||
export interface Session {
|
||||
id: string
|
||||
instanceId: string
|
||||
title: string
|
||||
parentId: string | null
|
||||
agent: string
|
||||
model: {
|
||||
// Export SDK types for external use
|
||||
export type {
|
||||
Session as SDKSession,
|
||||
Agent as SDKAgent,
|
||||
Provider as SDKProvider,
|
||||
Model as SDKModel
|
||||
} from "@opencode-ai/sdk"
|
||||
|
||||
// Our client-specific Session interface extending SDK Session
|
||||
export interface Session extends Omit<import("@opencode-ai/sdk").Session, 'projectID' | 'directory' | 'parentID'> {
|
||||
instanceId: string // Client-specific field
|
||||
parentId: string | null // Client-specific field (override parentID)
|
||||
agent: string // Client-specific field
|
||||
model: { // Client-specific field
|
||||
providerId: string
|
||||
modelId: string
|
||||
}
|
||||
time: {
|
||||
created: number
|
||||
updated: number
|
||||
}
|
||||
revert?: {
|
||||
messageID: string
|
||||
partID?: string
|
||||
snapshot?: string
|
||||
diff?: string
|
||||
}
|
||||
messages: Message[]
|
||||
messagesInfo: Map<string, any>
|
||||
messages: Message[] // Client-specific field
|
||||
messagesInfo: Map<string, MessageInfo> // Client-specific field
|
||||
version: string // Include version from SDK Session
|
||||
}
|
||||
|
||||
// Adapter function to convert SDK Session to client Session
|
||||
export function createClientSession(
|
||||
sdkSession: import("@opencode-ai/sdk").Session,
|
||||
instanceId: string,
|
||||
agent: string = "",
|
||||
model: { providerId: string; modelId: string } = { providerId: "", modelId: "" }
|
||||
): Session {
|
||||
return {
|
||||
...sdkSession,
|
||||
instanceId,
|
||||
parentId: sdkSession.parentID || null,
|
||||
agent,
|
||||
model,
|
||||
messages: [],
|
||||
messagesInfo: new Map(),
|
||||
}
|
||||
}
|
||||
|
||||
// Type guard to check if object is SDK Session
|
||||
export function isSdkSession(obj: unknown): obj is import("@opencode-ai/sdk").Session {
|
||||
return (
|
||||
typeof obj === "object" &&
|
||||
obj !== null &&
|
||||
"id" in obj &&
|
||||
"title" in obj &&
|
||||
"version" in obj &&
|
||||
"time" in obj
|
||||
)
|
||||
}
|
||||
|
||||
// Our client-specific Agent interface (simplified version of SDK Agent)
|
||||
export interface Agent {
|
||||
name: string
|
||||
description: string
|
||||
@@ -34,6 +69,7 @@ export interface Agent {
|
||||
}
|
||||
}
|
||||
|
||||
// Our client-specific Provider interface (simplified version of SDK Provider)
|
||||
export interface Provider {
|
||||
id: string
|
||||
name: string
|
||||
@@ -41,6 +77,7 @@ export interface Provider {
|
||||
defaultModelId?: string
|
||||
}
|
||||
|
||||
// Our client-specific Model interface (simplified version of SDK Model)
|
||||
export interface Model {
|
||||
id: string
|
||||
name: string
|
||||
|
||||
Reference in New Issue
Block a user