mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
feat(codex): share sessions across terminal and web
Use one native app-server for terminal, Web and phone clients while retaining the existing CLI and Runner lifecycle. Synchronize native queues, permissions, question history and steering state; preserve explicit permission precedence and per-turn usage models. Resume inactive clear commands through Runner and reject independent child cold resumes. Add shared-runtime regression tests, generated protocol fixtures and lifecycle documentation.
This commit is contained in:
@@ -59,7 +59,7 @@ function normalizeServiceTiers(value: unknown): string[] | undefined {
|
||||
return tokens.size > 0 ? [...tokens] : undefined;
|
||||
}
|
||||
|
||||
function normalizeModel(entry: unknown): CodexModelSummary | null {
|
||||
export function normalizeCodexModel(entry: unknown): CodexModelSummary | null {
|
||||
if (!entry || typeof entry !== 'object') {
|
||||
return null;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ async function fetchCodexModelsFromAppServer(includeHidden: boolean): Promise<Co
|
||||
|
||||
const response = await client.listModels({ includeHidden });
|
||||
return Array.isArray(response.data)
|
||||
? response.data.map(normalizeModel).filter((model): model is CodexModelSummary => model !== null)
|
||||
? response.data.map(normalizeCodexModel).filter((model): model is CodexModelSummary => model !== null)
|
||||
: [];
|
||||
} catch (error) {
|
||||
throw new Error(getErrorMessage(error, 'Failed to list Codex models'));
|
||||
|
||||
@@ -26,6 +26,7 @@ const uploadDirs = new Map<string, string>()
|
||||
const uploadFileIdentities = new Map<string, Map<string, string>>()
|
||||
const uploadDirPromises = new Map<string, Promise<string>>()
|
||||
const uploadDirCleanupRequested = new Set<string>()
|
||||
const retainedUploadDirs = new Set<string>()
|
||||
let cleanupRegistered = false
|
||||
const MAX_FILENAME_COMPONENT_BYTES = 255
|
||||
|
||||
@@ -123,6 +124,7 @@ async function getOrCreateUploadDir(sessionId?: string): Promise<string> {
|
||||
|
||||
export async function cleanupUploadDir(sessionId?: string): Promise<void> {
|
||||
const sessionKey = getSessionKey(sessionId)
|
||||
retainedUploadDirs.delete(sessionKey)
|
||||
uploadDirCleanupRequested.add(sessionKey)
|
||||
|
||||
try {
|
||||
@@ -154,12 +156,19 @@ export async function cleanupUploadDir(sessionId?: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Pending native input still references these temporary files after suspension.
|
||||
* Explicit cleanup still removes them; otherwise normal OS temp cleanup applies. */
|
||||
export function preserveUploadDirOnExit(sessionId: string): void {
|
||||
retainedUploadDirs.add(getSessionKey(sessionId))
|
||||
}
|
||||
|
||||
function cleanupUploadDirsSync(): void {
|
||||
const dirs = Array.from(uploadDirs.values())
|
||||
const dirs = Array.from(uploadDirs.entries()).filter(([key]) => !retainedUploadDirs.has(key)).map(([, dir]) => dir)
|
||||
uploadDirs.clear()
|
||||
uploadFileIdentities.clear()
|
||||
uploadDirPromises.clear()
|
||||
uploadDirCleanupRequested.clear()
|
||||
retainedUploadDirs.clear()
|
||||
|
||||
for (const dir of dirs) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user