- RMM Overshell (migration 077): admin page, dispatch UI, executor/worker, target resolver, script registry (AD/DHCP/DNS/event-log/services/software/network/loglift) - LogLift evidence pipeline (migration 078): upload webhook, B2 storage client, receiver/matcher, EventLogCollector PowerShell script - IT Glue audit + write-back (migrations 075, 076): asset-audit runner, ticket xrefs, applications/configurations browse pages + apply/revert/audit endpoints - Link-aware analyzer bundles (migration 073) + provider toggle (migration 074): link-discovery service, OpenRouter LLM provider, related-tickets/itglue-suggestion panels, analyze-bundle endpoint - Endpoint data model + device-link reconciliation (migrations 079, 080): conflicts admin page, reconciler service, resolve endpoints - Dashboard overhaul: integration-health service + alerts, overview/health endpoints - Permissions: add itglue + rmm scopes; middleware: public /api/rmm/loglift route Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
/**
|
|
* GET /api/analyzer/tickets/:ticketNumber/links
|
|
* Cheap explicit-only discovery (regex + RELATED TICKETS section + problem_ticket_id).
|
|
* No LLM cost. Use this on page load to render the Related Tickets panel.
|
|
*
|
|
* POST /api/analyzer/tickets/:ticketNumber/links
|
|
* Body: { includeSuggested?: boolean }
|
|
* Runs the Haiku-suggested arm in addition to the explicit arm.
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { requireAuth } from '@/lib/auth-utils';
|
|
import {
|
|
loadTicketBundle,
|
|
TicketNotFoundError,
|
|
} from '@/lib/services/analyzer/data-access';
|
|
import {
|
|
discoverLinks,
|
|
discoverExplicitLinks,
|
|
} from '@/lib/services/analyzer/link-discovery';
|
|
import { SuggestLinksRequest } from '@/lib/types/analyzer';
|
|
|
|
export async function GET(
|
|
_request: NextRequest,
|
|
{ params }: { params: Promise<{ ticketNumber: string }> }
|
|
) {
|
|
const { error } = await requireAuth();
|
|
if (error) return error;
|
|
|
|
const { ticketNumber } = await params;
|
|
|
|
let bundle;
|
|
try {
|
|
bundle = await loadTicketBundle(ticketNumber);
|
|
} catch (err) {
|
|
if (err instanceof TicketNotFoundError) {
|
|
return NextResponse.json(
|
|
{ error: `Ticket ${ticketNumber} not found in local mirror` },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
console.error('[analyzer/links] data-access error:', err);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to load ticket' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
const result = await discoverExplicitLinks(bundle);
|
|
return NextResponse.json({
|
|
explicit: result.explicit,
|
|
suggested: [],
|
|
isProblemTicket: result.isProblemTicket,
|
|
problemTicketSignals: result.problemTicketSignals,
|
|
});
|
|
}
|
|
|
|
export async function POST(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ ticketNumber: string }> }
|
|
) {
|
|
const { error } = await requireAuth();
|
|
if (error) return error;
|
|
|
|
const { ticketNumber } = await params;
|
|
|
|
const body = await request.json().catch(() => ({}));
|
|
const parsed = SuggestLinksRequest.safeParse(body);
|
|
if (!parsed.success) {
|
|
return NextResponse.json(
|
|
{ error: 'Invalid request body', details: parsed.error.issues },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
let bundle;
|
|
try {
|
|
bundle = await loadTicketBundle(ticketNumber);
|
|
} catch (err) {
|
|
if (err instanceof TicketNotFoundError) {
|
|
return NextResponse.json(
|
|
{ error: `Ticket ${ticketNumber} not found in local mirror` },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
console.error('[analyzer/links] data-access error:', err);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to load ticket' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
const result = await discoverLinks(bundle, {
|
|
includeSuggested: parsed.data.includeSuggested,
|
|
});
|
|
return NextResponse.json(result);
|
|
}
|