MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / parseRemoteSessionsResponse

Function parseRemoteSessionsResponse

packages/sync/src/discovery.ts:25–51  ·  view source on GitHub ↗
(body: string)

Source from the content-addressed store, hash-verified

23 * Supports: Pull protocol `{ sessions, page? }`, ChatLab API `{ success, data }`, and plain array.
24 */
25export function parseRemoteSessionsResponse(body: string): RemoteSessionDiscoveryResult {
26 const parsed = JSON.parse(body)
27
28 let sessions: RemoteSession[]
29 let pageSource: Record<string, unknown> | undefined
30
31 if (Array.isArray(parsed)) {
32 sessions = parsed
33 } else if (parsed && typeof parsed === 'object') {
34 sessions = parsed.sessions ?? parsed.data?.sessions ?? parsed.data ?? []
35 if (!Array.isArray(sessions)) sessions = []
36 pageSource = parsed.page ?? parsed.data?.page
37 } else {
38 sessions = []
39 }
40
41 return {
42 sessions,
43 page:
44 pageSource && typeof pageSource === 'object'
45 ? {
46 hasMore: Boolean(pageSource.hasMore),
47 nextCursor: typeof pageSource.nextCursor === 'string' ? pageSource.nextCursor : undefined,
48 }
49 : undefined,
50 }
51}

Callers 2

fetchRemoteSessionsFunction · 0.90
registerAutomationRoutesFunction · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected