feat: surface codex app server thread visibility
This commit is contained in:
@@ -1349,6 +1349,67 @@ function normalizeDiscoveryExternalAgentMigration(result) {
|
||||
};
|
||||
}
|
||||
|
||||
function extractDiscoveryThreadStatus(thread) {
|
||||
const status = thread?.status && typeof thread.status === "object" ? thread.status : thread?.status;
|
||||
return safeProgressText(
|
||||
typeof status === "string"
|
||||
? status
|
||||
: status?.type ?? status?.state ?? thread?.state ?? (thread?.archived ? "archived" : "unknown"),
|
||||
40,
|
||||
);
|
||||
}
|
||||
|
||||
function extractLoadedThreadIds(result) {
|
||||
const candidates = [
|
||||
...asArray(result?.threadIds),
|
||||
...asArray(result?.loadedThreadIds),
|
||||
...asArray(result?.data).map((item) => item?.id ?? item?.threadId ?? item),
|
||||
...asArray(result?.threads).map((item) => item?.id ?? item?.threadId ?? item),
|
||||
];
|
||||
return new Set(candidates.map((item) => trimToDefined(item)).filter(Boolean));
|
||||
}
|
||||
|
||||
function normalizeDiscoveryThreadSummary(threadListResult, loadedListResult, limit) {
|
||||
const loadedThreadIds = extractLoadedThreadIds(loadedListResult);
|
||||
const rawThreads = asArray(threadListResult?.data).length > 0
|
||||
? asArray(threadListResult?.data)
|
||||
: asArray(threadListResult?.threads);
|
||||
const threads = rawThreads
|
||||
.map((thread) => {
|
||||
const id = trimToDefined(thread?.id ?? thread?.threadId);
|
||||
if (!id) return null;
|
||||
const archived = Boolean(thread?.archived);
|
||||
return {
|
||||
id,
|
||||
name: safeRuntimeDiagnosticText(thread?.name ?? thread?.title, 120) || id,
|
||||
sourceKind: safeProgressText(thread?.sourceKind ?? thread?.source?.kind, 48) || "unknown",
|
||||
status: extractDiscoveryThreadStatus(thread),
|
||||
archived,
|
||||
loaded: loadedThreadIds.has(id) || Boolean(thread?.loaded),
|
||||
updatedAt: trimToDefined(thread?.updatedAt ?? thread?.lastUpdatedAt ?? thread?.createdAt) || "",
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
const sourceKinds = Array.from(new Set(threads.map((thread) => thread.sourceKind).filter(Boolean))).sort();
|
||||
const latestUpdatedAt = threads
|
||||
.map((thread) => thread.updatedAt)
|
||||
.filter(Boolean)
|
||||
.sort()
|
||||
.at(-1) || "";
|
||||
return {
|
||||
threadCount: threads.length,
|
||||
loadedThreadCount: threads.filter((thread) => thread.loaded).length,
|
||||
activeThreadCount: threads.filter((thread) => /active|running|streaming/i.test(thread.status)).length,
|
||||
archivedThreadCount: threads.filter((thread) => thread.archived).length,
|
||||
latestUpdatedAt,
|
||||
sourceKinds,
|
||||
visibleThreads: threads
|
||||
.filter((thread) => !thread.archived)
|
||||
.sort((left, right) => String(right.updatedAt).localeCompare(String(left.updatedAt)))
|
||||
.slice(0, limit),
|
||||
};
|
||||
}
|
||||
|
||||
async function withCodexAppServerRpcSession(runnerConfig, callback) {
|
||||
const cwd = runnerConfig.cwd || process.cwd();
|
||||
let closed = false;
|
||||
@@ -1470,6 +1531,8 @@ export async function discoverCodexAppServerCapabilities(runnerConfig) {
|
||||
configResult,
|
||||
configRequirementsResult,
|
||||
externalAgentConfigResult,
|
||||
threadListResult,
|
||||
loadedThreadsResult,
|
||||
] = await Promise.all([
|
||||
safeRequest(request, "model/list", { includeHidden: false, limit }),
|
||||
safeRequest(request, "modelProvider/capabilities/read", {}),
|
||||
@@ -1485,6 +1548,8 @@ export async function discoverCodexAppServerCapabilities(runnerConfig) {
|
||||
safeRequest(request, "config/read", { includeLayers: false }),
|
||||
safeRequest(request, "configRequirements/read"),
|
||||
safeRequest(request, "externalAgentConfig/detect", { includeHome: true, cwds: [cwd] }),
|
||||
safeRequest(request, "thread/list", { cwd, limit }),
|
||||
safeRequest(request, "thread/loaded/list", { limit }),
|
||||
]);
|
||||
|
||||
const models = asArray(modelResult?.data)
|
||||
@@ -1518,6 +1583,7 @@ export async function discoverCodexAppServerCapabilities(runnerConfig) {
|
||||
appConfigSummary: normalizeDiscoveryAppConfigSummary(configResult),
|
||||
configRequirements: normalizeDiscoveryConfigRequirements(configRequirementsResult),
|
||||
externalAgentMigration: normalizeDiscoveryExternalAgentMigration(externalAgentConfigResult),
|
||||
threadSummary: normalizeDiscoveryThreadSummary(threadListResult, loadedThreadsResult, limit),
|
||||
errors: [
|
||||
modelResult?.__bossError ? `model/list:${safeRuntimeDiagnosticText(modelResult.__bossError)}` : undefined,
|
||||
providerCapabilities?.__bossError
|
||||
@@ -1549,6 +1615,12 @@ export async function discoverCodexAppServerCapabilities(runnerConfig) {
|
||||
externalAgentConfigResult?.__bossError
|
||||
? `externalAgentConfig/detect:${safeRuntimeDiagnosticText(externalAgentConfigResult.__bossError)}`
|
||||
: undefined,
|
||||
threadListResult?.__bossError
|
||||
? `thread/list:${safeRuntimeDiagnosticText(threadListResult.__bossError)}`
|
||||
: undefined,
|
||||
loadedThreadsResult?.__bossError
|
||||
? `thread/loaded/list:${safeRuntimeDiagnosticText(loadedThreadsResult.__bossError)}`
|
||||
: undefined,
|
||||
].filter(Boolean),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user