Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
import { createClient } from '@/lib/supabase/server'
|
|
import { NextResponse } from 'next/server'
|
|
import { requireCompanyId } from '@/lib/company/context'
|
|
|
|
// GET /api/documents/:id/extraction-status
|
|
//
|
|
// Light-weight polling endpoint for the AI document-extraction pipeline.
|
|
// Returns the minimal fields needed to drive an "extracting…" UI without
|
|
// touching storage (no signed URL creation per poll).
|
|
//
|
|
// Derived status:
|
|
// running : extracted_at IS NULL (pipeline hasn't stamped yet)
|
|
// succeeded : extracted_at IS NOT NULL AND extracted_data IS NOT NULL
|
|
// unsupported : extraction_model = 'skipped:*' (HEIC, ZIP, …)
|
|
// failed : extracted_at IS NOT NULL AND extracted_data IS NULL AND
|
|
// extraction_model = 'failed:*'
|
|
// disabled : the document-extraction extension isn't enabled (column
|
|
// stays untouched indefinitely). Client times out and shows
|
|
// a quiet fallback. We don't distinguish this from running
|
|
// server-side: the client decides based on elapsed time.
|
|
export async function GET(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
) {
|
|
const supabase = await createClient()
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
|
|
const companyId = await requireCompanyId(supabase, user.id)
|
|
const { id } = await params
|
|
|
|
const { data, error } = await supabase
|
|
.from('document_attachments')
|
|
.select('id, extracted_at, extracted_data, extraction_model')
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
.maybeSingle()
|
|
|
|
if (error) return NextResponse.json({ error: error.message }, { status: 500 })
|
|
if (!data) return NextResponse.json({ error: 'Not found' }, { status: 404 })
|
|
|
|
const extractedAt = data.extracted_at as string | null
|
|
const extractedData = data.extracted_data as Record<string, unknown> | null
|
|
const model = data.extraction_model as string | null
|
|
|
|
let status: 'running' | 'succeeded' | 'failed' | 'unsupported'
|
|
if (!extractedAt) {
|
|
status = 'running'
|
|
} else if (extractedData) {
|
|
status = 'succeeded'
|
|
} else if (model?.startsWith('skipped:')) {
|
|
status = 'unsupported'
|
|
} else {
|
|
status = 'failed'
|
|
}
|
|
|
|
return NextResponse.json({
|
|
data: {
|
|
id: data.id,
|
|
status,
|
|
extracted_at: extractedAt,
|
|
extraction_model: model,
|
|
},
|
|
})
|
|
}
|