mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix TypeScript errors for updated OpenAPI types
This commit is contained in:
1 parent
74b10fc57b
commit
dc9a57b361
7 files changed
+52
-55
No files matched your search
@@ -18,7 +18,7 @@ import type { components } from './opencode-types'
|
||||
export type Message = components['schemas']['Message']
|
||||
export type Part = components['schemas']['Part']
|
||||
export type Session = components['schemas']['Session']
|
||||
export type Permission = components['schemas']['Permission']
|
||||
export type PermissionRequest = components['schemas']['PermissionRequest']
|
||||
export type PermissionResponse = 'once' | 'always' | 'reject'
|
||||
|
||||
export type MessageWithParts = {
|
||||
@@ -88,9 +88,9 @@ export interface SSETodoUpdatedEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEPermissionUpdatedEvent {
|
||||
type: 'permission.updated'
|
||||
properties: Permission
|
||||
export interface SSEPermissionAskedEvent {
|
||||
type: 'permission.asked'
|
||||
properties: PermissionRequest
|
||||
}
|
||||
|
||||
export interface SSEPermissionRepliedEvent {
|
||||
@@ -151,7 +151,7 @@ export type SSEEvent =
|
||||
| SSESessionIdleEvent
|
||||
| SSESessionStatusEvent
|
||||
| SSETodoUpdatedEvent
|
||||
| SSEPermissionUpdatedEvent
|
||||
| SSEPermissionAskedEvent
|
||||
| SSEPermissionRepliedEvent
|
||||
| SSEInstallationUpdatedEvent
|
||||
| SSEInstallationUpdateAvailableEvent
|
||||
|
||||
@@ -8,12 +8,12 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import type { Permission, PermissionResponse } from '@/api/types'
|
||||
import type { PermissionRequest, PermissionResponse } from '@/api/types'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
interface PermissionRequestDialogProps {
|
||||
permission: Permission | null
|
||||
permission: PermissionRequest | null
|
||||
pendingCount: number
|
||||
isFromDifferentSession?: boolean
|
||||
sessionTitle?: string
|
||||
@@ -42,10 +42,10 @@ function getPermissionTypeLabel(type: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function getPermissionDetails(permission: Permission): { primary: string; secondary?: string } {
|
||||
function getPermissionDetails(permission: PermissionRequest): { primary: string; secondary?: string } {
|
||||
const metadata = permission.metadata || {}
|
||||
|
||||
switch (permission.type) {
|
||||
switch (permission.permission) {
|
||||
case 'bash': {
|
||||
const command = metadata.command as string | undefined
|
||||
if (command) {
|
||||
@@ -96,11 +96,7 @@ function getPermissionDetails(permission: Permission): { primary: string; second
|
||||
}
|
||||
}
|
||||
|
||||
const patterns = Array.isArray(permission.pattern)
|
||||
? permission.pattern
|
||||
: permission.pattern
|
||||
? [permission.pattern]
|
||||
: []
|
||||
const patterns = permission.patterns || []
|
||||
|
||||
if (patterns.length > 0) {
|
||||
return { primary: patterns.join('\n') }
|
||||
@@ -129,7 +125,7 @@ export function PermissionRequestDialog({
|
||||
setIsLoading(true)
|
||||
setLoadingAction(response)
|
||||
try {
|
||||
await onRespond(permission.id, permission.sessionID, response)
|
||||
await onRespond(permission.permission, permission.sessionID, response)
|
||||
} catch (error) {
|
||||
console.error('Failed to respond to permission:', error)
|
||||
showToast.error('Failed to respond to permission. Please try again.')
|
||||
@@ -139,7 +135,7 @@ export function PermissionRequestDialog({
|
||||
}
|
||||
}
|
||||
|
||||
const typeLabel = getPermissionTypeLabel(permission.type)
|
||||
const typeLabel = getPermissionTypeLabel(permission.permission)
|
||||
const details = getPermissionDetails(permission)
|
||||
const hasMultiple = pendingCount > 1
|
||||
const displaySessionName = sessionTitle || `Session ${permission.sessionID.slice(0, 8)}...`
|
||||
@@ -157,7 +153,7 @@ export function PermissionRequestDialog({
|
||||
)}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="break-all">
|
||||
{permission.title || `Allow ${typeLabel.toLowerCase()}?`}
|
||||
{`Allow ${typeLabel.toLowerCase()}?`}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -187,7 +183,7 @@ export function PermissionRequestDialog({
|
||||
<div className="text-xs text-muted-foreground space-y-1">
|
||||
{repoDirectory && (
|
||||
<div className="truncate">
|
||||
Repo: <span className="font-medium">{repoDirectory.split('/').pop() || repoDirectory}</span>
|
||||
Repo: <span className="font-medium">{repoDirectory.split('/').pop() ?? repoDirectory}</span>
|
||||
</div>
|
||||
)}
|
||||
{isFromDifferentSession ? (
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { createContext, useContext, useEffect, useState, useCallback, useMemo, useRef } from 'react'
|
||||
import { OpenCodeClient } from '@/api/opencode'
|
||||
import { permissionEvents, usePermissionRequests } from '@/hooks/usePermissionRequests'
|
||||
import type { Permission, PermissionResponse } from '@/api/types'
|
||||
import type { PermissionRequest, PermissionResponse } from '@/api/types'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
@@ -19,7 +19,7 @@ type ActiveRepo = {
|
||||
}
|
||||
|
||||
interface PermissionContextValue {
|
||||
currentPermission: Permission | null
|
||||
currentPermission: PermissionRequest | null
|
||||
pendingCount: number
|
||||
isFromDifferentSession: boolean
|
||||
respondToPermission: (permissionID: string, sessionID: string, response: PermissionResponse) => Promise<void>
|
||||
@@ -27,7 +27,7 @@ interface PermissionContextValue {
|
||||
showDialog: boolean
|
||||
setShowDialog: (show: boolean) => void
|
||||
currentSessionId: string | null
|
||||
getPermissionForCallID: (callID: string, sessionID: string) => Permission | null
|
||||
getPermissionForCallID: (callID: string, sessionID: string) => PermissionRequest | null
|
||||
hasPermissionsForSession: (sessionID: string) => boolean
|
||||
currentRepoDirectory: string | null
|
||||
getRepoForSession: (sessionID: string) => ActiveRepo | null
|
||||
@@ -281,10 +281,10 @@ prevPendingCountRef.current = pendingCount
|
||||
const es = new EventSource(url.toString())
|
||||
currentRefs.set(repoKey, es)
|
||||
|
||||
es.addEventListener('permission.updated', (e) => {
|
||||
es.addEventListener('permission.asked', (e) => {
|
||||
try {
|
||||
const event = JSON.parse(e.data)
|
||||
if ('id' in event.properties && 'sessionID' in event.properties) {
|
||||
if ('permission' in event.properties && 'sessionID' in event.properties) {
|
||||
sessionRepoMapRef.current.set(event.properties.sessionID, {
|
||||
url: repo.url,
|
||||
directory: repo.directory,
|
||||
@@ -292,18 +292,19 @@ prevPendingCountRef.current = pendingCount
|
||||
permissionEvents.emit({ type: 'add', permission: event.properties })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to parse permission.updated event:', err)
|
||||
console.error('Failed to parse permission.asked event:', err)
|
||||
}
|
||||
})
|
||||
|
||||
es.addEventListener('permission.replied', (e) => {
|
||||
try {
|
||||
const event = JSON.parse(e.data)
|
||||
if ('permissionID' in event.properties && 'sessionID' in event.properties) {
|
||||
const requestID = event.properties.requestID || event.properties.permissionID
|
||||
if (requestID && 'sessionID' in event.properties) {
|
||||
permissionEvents.emit({
|
||||
type: 'remove',
|
||||
sessionID: event.properties.sessionID,
|
||||
permissionID: event.properties.permissionID,
|
||||
permissionID: requestID,
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -12,7 +12,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'init',
|
||||
@@ -20,7 +20,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'new',
|
||||
@@ -28,7 +28,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'clear',
|
||||
@@ -36,7 +36,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'sessions',
|
||||
@@ -44,7 +44,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'resume',
|
||||
@@ -52,7 +52,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'continue',
|
||||
@@ -60,7 +60,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'models',
|
||||
@@ -68,7 +68,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'themes',
|
||||
@@ -76,7 +76,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'share',
|
||||
@@ -84,7 +84,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'unshare',
|
||||
@@ -92,7 +92,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'export',
|
||||
@@ -100,7 +100,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'compact',
|
||||
@@ -108,7 +108,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'summarize',
|
||||
@@ -116,7 +116,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'undo',
|
||||
@@ -124,7 +124,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'redo',
|
||||
@@ -132,7 +132,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'details',
|
||||
@@ -140,7 +140,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
},
|
||||
{
|
||||
name: 'editor',
|
||||
@@ -148,7 +148,7 @@ const BUILTIN_COMMANDS: CommandType[] = [
|
||||
template: '',
|
||||
agent: '',
|
||||
model: '',
|
||||
subtask: false
|
||||
hints: []
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export function useTitleGenerating(sessionID: string | undefined) {
|
||||
type AssistantMessage = components["schemas"]["AssistantMessage"];
|
||||
|
||||
type SendPromptRequest = NonNullable<
|
||||
paths["/session/{id}/message"]["post"]["requestBody"]
|
||||
paths["/session/{sessionID}/message"]["post"]["requestBody"]
|
||||
>["content"]["application/json"];
|
||||
|
||||
export const useOpenCodeClient = (opcodeUrl: string | null | undefined, directory?: string) => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useState, useEffect, useCallback, useMemo } from 'react'
|
||||
import type { Permission } from '@/api/types'
|
||||
import type { PermissionRequest } from '@/api/types'
|
||||
|
||||
type PermissionEventType = 'add' | 'remove'
|
||||
|
||||
interface PermissionEvent {
|
||||
type: PermissionEventType
|
||||
permission?: Permission
|
||||
permission?: PermissionRequest
|
||||
sessionID?: string
|
||||
permissionID?: string
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export const permissionEvents = {
|
||||
}
|
||||
}
|
||||
|
||||
type PermissionsBySession = Record<string, Permission[]>
|
||||
type PermissionsBySession = Record<string, PermissionRequest[]>
|
||||
|
||||
export function usePermissionRequests(currentSessionID?: string) {
|
||||
const [permissionsBySession, setPermissionsBySession] = useState<PermissionsBySession>({})
|
||||
@@ -116,9 +116,9 @@ export function usePermissionRequests(currentSessionID?: string) {
|
||||
setPermissionsBySession({})
|
||||
}, [])
|
||||
|
||||
const getPermissionForCallID = useCallback((callID: string, sessionID: string): Permission | null => {
|
||||
const getPermissionForCallID = useCallback((callID: string, sessionID: string): PermissionRequest | null => {
|
||||
const sessionPermissions = permissionsBySession[sessionID] ?? []
|
||||
return sessionPermissions.find(p => p.callID === callID) ?? null
|
||||
return sessionPermissions.find(p => p.tool?.callID === callID) ?? null
|
||||
}, [permissionsBySession])
|
||||
|
||||
const hasPermissionsForSession = useCallback((sessionID: string): boolean => {
|
||||
|
||||
@@ -311,18 +311,18 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string)
|
||||
break
|
||||
}
|
||||
|
||||
case 'permission.updated':
|
||||
if ('id' in event.properties) {
|
||||
case 'permission.asked':
|
||||
if ('permission' in event.properties && 'sessionID' in event.properties) {
|
||||
permissionEvents.emit({ type: 'add', permission: event.properties })
|
||||
}
|
||||
break
|
||||
|
||||
case 'permission.replied':
|
||||
if ('permissionID' in event.properties && 'sessionID' in event.properties) {
|
||||
if ('requestID' in event.properties && 'sessionID' in event.properties) {
|
||||
permissionEvents.emit({
|
||||
type: 'remove',
|
||||
sessionID: event.properties.sessionID,
|
||||
permissionID: event.properties.permissionID
|
||||
sessionID: event.properties.sessionID as string,
|
||||
permissionID: event.properties.requestID as string
|
||||
})
|
||||
}
|
||||
break
|
||||
|
||||
Reference in new issue
Block a user