mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 12: Phase 12: One shared flattened stream event type; delete the
This commit is contained in:
1 parent
0b2303a870
commit
717536c5a6
15 files changed
+122
-125
No files matched your search
@@ -51,7 +51,8 @@ class MockEventSource {
|
||||
close() {}
|
||||
|
||||
emit(type: string, data: unknown) {
|
||||
const event = { data: JSON.stringify(data) } as MessageEvent
|
||||
const message = type === 'message' ? { payload: data } : data
|
||||
const event = { data: JSON.stringify(message) } as MessageEvent
|
||||
this.listeners.get(type)?.forEach((listener) => listener(event))
|
||||
if (type === 'message' && this.onmessage) {
|
||||
this.onmessage(event)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { useEffect, useRef, useState, useCallback, useMemo } from 'react'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { buildServerDirectoryKey, LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import type { SessionInfo, V2Event } from '@opencode-manager/shared/opencode'
|
||||
import {
|
||||
buildServerDirectoryKey,
|
||||
LOCAL_OPENCODE_SERVER_ID,
|
||||
type OpenCodeStreamEvent,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import type { SessionInfo } from '@opencode-manager/shared/opencode'
|
||||
import { invalidateSessionListCaches, invalidateShellCaches, shellsQueryKey } from '@/lib/queryInvalidation'
|
||||
import {
|
||||
applyShellExit,
|
||||
@@ -18,9 +22,7 @@ import type { EventStreamSubscription } from '@/lib/opencode-event-stream'
|
||||
import { serverScopedKey } from '@/lib/serverScope'
|
||||
import { useOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
|
||||
type V2StreamEvent = V2Event & { directory?: string; serverId?: string }
|
||||
|
||||
const getEventDirectory = (event: V2StreamEvent): string | undefined => {
|
||||
const getEventDirectory = (event: OpenCodeStreamEvent): string | undefined => {
|
||||
return typeof event.directory === 'string' ? event.directory : undefined
|
||||
}
|
||||
|
||||
@@ -73,7 +75,7 @@ export const useSSE = (directory?: string | string[], currentSessionId?: string)
|
||||
[directorySet, primaryDirectory],
|
||||
)
|
||||
|
||||
const handleSSEEvent = useCallback((event: V2StreamEvent) => {
|
||||
const handleSSEEvent = useCallback((event: OpenCodeStreamEvent) => {
|
||||
if ((event.serverId ?? LOCAL_OPENCODE_SERVER_ID) !== serverId) return
|
||||
const eventDirectory = getEventDirectory(event)
|
||||
const cacheDirectory = resolveCacheDirectory(eventDirectory)
|
||||
@@ -193,12 +195,6 @@ export const useSSE = (directory?: string | string[], currentSessionId?: string)
|
||||
return
|
||||
}
|
||||
|
||||
const handleMessage = (data: unknown) => {
|
||||
if (data && typeof data === 'object' && 'type' in data) {
|
||||
handleSSEEvent(data as V2StreamEvent)
|
||||
}
|
||||
}
|
||||
|
||||
const handleStatusChange = (connected: boolean) => {
|
||||
if (!mountedRef.current) return
|
||||
setIsConnected(connected)
|
||||
@@ -224,7 +220,7 @@ export const useSSE = (directory?: string | string[], currentSessionId?: string)
|
||||
|
||||
const subscription = openCodeEventStream.subscribeGlobalMonitor({
|
||||
directories: directoriesList.map((entry) => buildServerDirectoryKey(serverId, entry)),
|
||||
onEvent: handleMessage,
|
||||
onEvent: handleSSEEvent,
|
||||
onStatusChange: handleStatusChange,
|
||||
onResync: handleResync,
|
||||
})
|
||||
|
||||
@@ -71,7 +71,13 @@ interface TestTransport {
|
||||
}
|
||||
|
||||
function testTransport(): TestTransport {
|
||||
return mocks.transport as TestTransport
|
||||
const transport = mocks.transport as TestTransport
|
||||
return {
|
||||
connected: () => transport.connected(),
|
||||
fail: () => transport.fail(),
|
||||
message: (event) => transport.message({ payload: event }),
|
||||
resync: (payload) => transport.resync(payload),
|
||||
}
|
||||
}
|
||||
|
||||
function deferred<Value>() {
|
||||
|
||||
@@ -2,7 +2,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { FetchError } from '@opencode-manager/shared'
|
||||
import { sessionIDFromEvent, type V2Event } from '@opencode-manager/shared/opencode'
|
||||
import { buildServerDirectoryKey, LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import {
|
||||
buildServerDirectoryKey,
|
||||
LOCAL_OPENCODE_SERVER_ID,
|
||||
type OpenCodeStreamEvent,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { listSessionMessages, readSessionSnapshot } from '@/api/opencode'
|
||||
import { openCodeEventStream } from '@/lib/opencode-event-stream'
|
||||
import { sessionTranscriptQueryKey } from '@/lib/queryInvalidation'
|
||||
@@ -150,9 +154,9 @@ export function useSessionTranscript(sessionID: string, directory: string) {
|
||||
|
||||
const subscription = openCodeEventStream.subscribeGlobalMonitor({
|
||||
directories: [buildServerDirectoryKey(serverId, directory)],
|
||||
onEvent: (data) => {
|
||||
const event = data as V2Event & { serverId?: string }
|
||||
onEvent: (event: OpenCodeStreamEvent) => {
|
||||
if ((event.serverId ?? LOCAL_OPENCODE_SERVER_ID) !== serverId) return
|
||||
if (event.type === 'ssh.host-key-request') return
|
||||
if (sessionIDFromEvent(event) !== sessionID) return
|
||||
newestReadRef.current?.buffered.push(event)
|
||||
queuedEventsRef.current.push(event)
|
||||
|
||||
Reference in new issue
Block a user