MCPcopy
hub / github.com/callstack/agent-device / finalizeDaemonResponse

Function finalizeDaemonResponse

src/daemon/request-finalization.ts:10–50  ·  view source on GitHub ↗
(
  req: DaemonRequest,
  response: DaemonResponse,
  trackArtifact: (opts: { artifactPath: string; tenantId?: string; fileName?: string }) => string,
)

Source from the content-addressed store, hash-verified

8import type { DaemonArtifact, DaemonRequest, DaemonResponse, DaemonResponseData } from './types.ts';
9
10export function finalizeDaemonResponse(
11 req: DaemonRequest,
12 response: DaemonResponse,
13 trackArtifact: (opts: { artifactPath: string; tenantId?: string; fileName?: string }) => string,
14): DaemonResponse {
15 const details = getDiagnosticsMeta();
16 if (!response.ok) {
17 emitDiagnostic({
18 level: 'error',
19 phase: 'request_failed',
20 data: {
21 code: response.error.code,
22 message: response.error.message,
23 },
24 });
25 const logPathOnFailure = flushDiagnosticsToSessionFile({ force: true }) ?? undefined;
26 const normalizedError = normalizeError(
27 new AppError(toAppErrorCode(response.error.code), response.error.message, {
28 ...(response.error.details ?? {}),
29 hint:
30 response.error.hint ??
31 (typeof response.error.details?.hint === 'string'
32 ? response.error.details.hint
33 : undefined),
34 diagnosticId: response.error.diagnosticId,
35 logPath: response.error.logPath,
36 }),
37 {
38 diagnosticId: details.diagnosticId,
39 logPath: logPathOnFailure,
40 },
41 );
42 return { ok: false, error: normalizedError };
43 }
44 emitDiagnostic({ level: 'info', phase: 'request_success' });
45 flushDiagnosticsToSessionFile();
46 return {
47 ok: true,
48 data: registerDownloadableArtifacts(req, response.data, trackArtifact),
49 };
50}
51
52function registerDownloadableArtifacts(
53 req: DaemonRequest,

Callers 2

finalizeFunction · 0.90

Calls 6

getDiagnosticsMetaFunction · 0.90
emitDiagnosticFunction · 0.90
normalizeErrorFunction · 0.90
toAppErrorCodeFunction · 0.90

Tested by

no test coverage detected