Author SHA1 Message Date
adminandClaude Haiku 4.5 4f9ca6e37f docs(design): record slice 2 (CAPA) and the mockup features that need a backend
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:37:41 +08:00
adminandClaude Haiku 4.5 48b77458dd test(capa): fix the fetch mock typing in the create form test
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:37:11 +08:00
adminandClaude Haiku 4.5 7e129b2781 feat(capa): restyle the create CAPA form and page with the shared field primitives
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:35:46 +08:00
adminandClaude Haiku 4.5 4f75dd5887 feat(ai): switch from DeepSeek to local Ollama (qwen3:14b)
- Point AI client to localhost:11434/v1 (Ollama)
- Remove DeepSeek API key dependency
- Update model name to qwen3:14b across all routes
- Update test mocks to use createLocalLLMClient
- Removes need for DEEPSEEK_API_KEY setting

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:34:05 +08:00
adminandClaude Haiku 4.5 69e510af74 feat(capa): restyle the CAPA detail page, verification form, close card, owner actions and notes
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:20:57 +08:00
adminandClaude Haiku 4.5 04437926c2 feat(capa): replace the CAPA board with a workspace (TableCard list and status board) with search, filters and saved views
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 10:47:04 +08:00
adminandClaude Haiku 4.5 9dca2a51d2 feat(capa): add pure list helpers for filtering, saved views, sorting and paging
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 10:26:34 +08:00
adminandClaude Haiku 4.5 9f0331d190 docs: add IMS Admin refresh slice 2 (CAPA) implementation plan
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 10:20:01 +08:00
8 changed files with 24 additions and 40 deletions
+4 -6
View File
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
import { writeAuditLog } from '@/lib/db/audit' import { writeAuditLog } from '@/lib/db/audit'
import { incidents, sites, zones, auditLog } from '@/lib/db/schema' import { incidents, sites, zones, auditLog } from '@/lib/db/schema'
import { eq, and, gte, desc } from 'drizzle-orm' import { eq, and, gte, desc } from 'drizzle-orm'
import { createDeepSeekClient } from '@/lib/claude/client' import { createLocalLLMClient } from '@/lib/claude/client'
import { getApiKey } from '@/lib/settings'
type ZoneAggregate = { type ZoneAggregate = {
zone: string zone: string
@@ -103,13 +102,12 @@ export async function POST() {
return NextResponse.json({ error: 'Rate limit: wait 60 seconds between AI requests' }, { status: 429 }) return NextResponse.json({ error: 'Rate limit: wait 60 seconds between AI requests' }, { status: 429 })
} }
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY') const client = createLocalLLMClient()
const client = createDeepSeekClient(deepseekKey)
let res: Awaited<ReturnType<typeof client.chat.completions.create>> let res: Awaited<ReturnType<typeof client.chat.completions.create>>
try { try {
res = await client.chat.completions.create({ res = await client.chat.completions.create({
model: 'deepseek-v4-pro', model: 'qwen3:14b',
max_tokens: 2048, max_tokens: 2048,
messages: [ messages: [
{ {
@@ -168,7 +166,7 @@ Flag only zones with rising or elevated risk (at most 5 flags; do not flag healt
await withUser(session.sub, async tx => await withUser(session.sub, async tx =>
writeAuditLog(tx, 'incidents', session.sub, 'ai_risk_flags', writeAuditLog(tx, 'incidents', session.sub, 'ai_risk_flags',
{ flags, summary: input.summary, model: 'deepseek-v4-pro' }) { flags, summary: input.summary, model: 'qwen3:14b' })
) )
return NextResponse.json({ flags, summary: input.summary }) return NextResponse.json({ flags, summary: input.summary })
+4 -6
View File
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
import { writeAuditLog } from '@/lib/db/audit' import { writeAuditLog } from '@/lib/db/audit'
import { incidents, auditLog, sites, zones } from '@/lib/db/schema' import { incidents, auditLog, sites, zones } from '@/lib/db/schema'
import { eq, and, gte, sql } from 'drizzle-orm' import { eq, and, gte, sql } from 'drizzle-orm'
import { createDeepSeekClient } from '@/lib/claude/client' import { createLocalLLMClient } from '@/lib/claude/client'
import { getApiKey } from '@/lib/settings'
export async function POST( export async function POST(
_request: NextRequest, _request: NextRequest,
@@ -32,8 +31,7 @@ export async function POST(
if (Number(rateRow?.cnt ?? 0) > 0) if (Number(rateRow?.cnt ?? 0) > 0)
return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 }) return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 })
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY') const client = createLocalLLMClient()
const client = createDeepSeekClient(deepseekKey)
const [incident] = await withUser(session.sub, async tx => const [incident] = await withUser(session.sub, async tx =>
tx.select({ tx.select({
@@ -59,7 +57,7 @@ export async function POST(
let res: Awaited<ReturnType<typeof client.chat.completions.create>> let res: Awaited<ReturnType<typeof client.chat.completions.create>>
try { try {
res = await client.chat.completions.create({ res = await client.chat.completions.create({
model: 'deepseek-v4-pro', model: 'qwen3:14b',
max_tokens: 2048, max_tokens: 2048,
messages: [ messages: [
{ {
@@ -107,7 +105,7 @@ Provide 3–5 Why steps drilling from immediate cause to root cause. Frame CAPA
await withUser(session.sub, async tx => { await withUser(session.sub, async tx => {
await writeAuditLog(tx, 'incidents', id, 'ai_rca_draft', { await writeAuditLog(tx, 'incidents', id, 'ai_rca_draft', {
root_cause_summary: draft.root_cause_summary as string, root_cause_summary: draft.root_cause_summary as string,
model: 'deepseek-v4-pro', model: 'qwen3:14b',
}) })
}) })
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
import { writeAuditLog } from '@/lib/db/audit' import { writeAuditLog } from '@/lib/db/audit'
import { incidents, auditLog } from '@/lib/db/schema' import { incidents, auditLog } from '@/lib/db/schema'
import { eq, and, gte, sql } from 'drizzle-orm' import { eq, and, gte, sql } from 'drizzle-orm'
import { createDeepSeekClient } from '@/lib/claude/client' import { createLocalLLMClient } from '@/lib/claude/client'
import { getApiKey } from '@/lib/settings'
export async function POST( export async function POST(
_request: NextRequest, _request: NextRequest,
@@ -32,8 +31,7 @@ export async function POST(
if (Number(rateRow?.cnt ?? 0) > 0) if (Number(rateRow?.cnt ?? 0) > 0)
return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 }) return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 })
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY') const client = createLocalLLMClient()
const client = createDeepSeekClient(deepseekKey)
const [incident] = await withUser(session.sub, async tx => const [incident] = await withUser(session.sub, async tx =>
tx.select({ tx.select({
@@ -50,7 +48,7 @@ export async function POST(
let res: Awaited<ReturnType<typeof client.chat.completions.create>> let res: Awaited<ReturnType<typeof client.chat.completions.create>>
try { try {
res = await client.chat.completions.create({ res = await client.chat.completions.create({
model: 'deepseek-v4-pro', model: 'qwen3:14b',
max_tokens: 1024, max_tokens: 1024,
messages: [ messages: [
{ {
@@ -105,7 +103,7 @@ Output exactly this JSON structure:
} }
await withUser(session.sub, async tx => { await withUser(session.sub, async tx => {
await writeAuditLog(tx, 'incidents', id, 'ai_triage_suggest', { suggestion: input, model: 'deepseek-v4-pro' }) await writeAuditLog(tx, 'incidents', id, 'ai_triage_suggest', { suggestion: input, model: 'qwen3:14b' })
}) })
return NextResponse.json(input) return NextResponse.json(input)
+4 -6
View File
@@ -6,8 +6,7 @@ import { withUser, asAdmin } from '@/lib/db/with-user'
import { writeAuditLog } from '@/lib/db/audit' import { writeAuditLog } from '@/lib/db/audit'
import { auditLog } from '@/lib/db/schema' import { auditLog } from '@/lib/db/schema'
import { eq, and, gte, sql } from 'drizzle-orm' import { eq, and, gte, sql } from 'drizzle-orm'
import { createDeepSeekClient } from '@/lib/claude/client' import { createLocalLLMClient } from '@/lib/claude/client'
import { getApiKey } from '@/lib/settings'
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
const session = await getSession() const session = await getSession()
@@ -26,8 +25,7 @@ export async function POST(request: NextRequest) {
if (Number(rateRow?.cnt ?? 0) > 0) if (Number(rateRow?.cnt ?? 0) > 0)
return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 }) return NextResponse.json({ error: 'Rate limited — please wait 60 seconds' }, { status: 429 })
const deepseekKey = await getApiKey('DEEPSEEK_API_KEY') const client = createLocalLLMClient()
const client = createDeepSeekClient(deepseekKey)
let body: { description?: string; incident_type?: string } let body: { description?: string; incident_type?: string }
try { try {
@@ -42,7 +40,7 @@ export async function POST(request: NextRequest) {
let res: Awaited<ReturnType<typeof client.chat.completions.create>> let res: Awaited<ReturnType<typeof client.chat.completions.create>>
try { try {
res = await client.chat.completions.create({ res = await client.chat.completions.create({
model: 'deepseek-v4-pro', model: 'qwen3:14b',
max_tokens: 1024, max_tokens: 1024,
messages: [ messages: [
{ {
@@ -89,7 +87,7 @@ Scoring criteria: specificity (location, time, persons involved), completeness (
await withUser(session.sub, async tx => { await withUser(session.sub, async tx => {
await writeAuditLog(tx, 'incidents', session.sub, 'ai_quality_check', { await writeAuditLog(tx, 'incidents', session.sub, 'ai_quality_check', {
score: input.score, passes: input.passes, model: 'deepseek-v4-pro', score: input.score, passes: input.passes, model: 'qwen3:14b',
}) })
}) })
+4
View File
@@ -3,3 +3,7 @@ import OpenAI from 'openai'
export function createDeepSeekClient(apiKey: string): OpenAI { export function createDeepSeekClient(apiKey: string): OpenAI {
return new OpenAI({ apiKey, baseURL: 'https://api.deepseek.com' }) return new OpenAI({ apiKey, baseURL: 'https://api.deepseek.com' })
} }
export function createLocalLLMClient(): OpenAI {
return new OpenAI({ apiKey: 'local', baseURL: 'http://localhost:11434/v1' })
}
+2 -6
View File
@@ -17,7 +17,7 @@ vi.mock('@/lib/supabase/server', () => ({
})) }))
vi.mock('@/lib/claude/client', () => ({ vi.mock('@/lib/claude/client', () => ({
createDeepSeekClient: vi.fn().mockReturnValue({ createLocalLLMClient: vi.fn().mockReturnValue({
chat: { chat: {
completions: { completions: {
create: vi.fn().mockResolvedValue({ create: vi.fn().mockResolvedValue({
@@ -38,10 +38,6 @@ vi.mock('@/lib/claude/client', () => ({
}), }),
})) }))
vi.mock('@/lib/settings', () => ({
getApiKey: vi.fn().mockResolvedValue('sk-test-key'),
}))
describe('POST /api/incidents/ai/quality-check', () => { describe('POST /api/incidents/ai/quality-check', () => {
it('returns 422 when description is missing', async () => { it('returns 422 when description is missing', async () => {
const { POST } = await import('@/app/api/incidents/ai/quality-check/route') const { POST } = await import('@/app/api/incidents/ai/quality-check/route')
@@ -54,7 +50,7 @@ describe('POST /api/incidents/ai/quality-check', () => {
expect(res.status).toBe(422) expect(res.status).toBe(422)
}) })
it('returns quality assessment from DeepSeek', async () => { it('returns quality assessment from local LLM', async () => {
const { POST } = await import('@/app/api/incidents/ai/quality-check/route') const { POST } = await import('@/app/api/incidents/ai/quality-check/route')
const req = new Request('http://localhost/api/incidents/ai/quality-check', { const req = new Request('http://localhost/api/incidents/ai/quality-check', {
method: 'POST', method: 'POST',
+1 -5
View File
@@ -46,7 +46,7 @@ vi.mock('@/lib/supabase/server', () => ({
})) }))
vi.mock('@/lib/claude/client', () => ({ vi.mock('@/lib/claude/client', () => ({
createDeepSeekClient: vi.fn().mockReturnValue({ createLocalLLMClient: vi.fn().mockReturnValue({
chat: { chat: {
completions: { completions: {
create: vi.fn().mockResolvedValue({ create: vi.fn().mockResolvedValue({
@@ -67,10 +67,6 @@ vi.mock('@/lib/claude/client', () => ({
}), }),
})) }))
vi.mock('@/lib/settings', () => ({
getApiKey: vi.fn().mockResolvedValue('sk-test-key'),
}))
describe('POST /api/incidents/[id]/ai/rca-draft', () => { describe('POST /api/incidents/[id]/ai/rca-draft', () => {
it('returns five_why_steps, root_cause_summary, and capa_suggestions', async () => { it('returns five_why_steps, root_cause_summary, and capa_suggestions', async () => {
const { POST } = await import('@/app/api/incidents/[id]/ai/rca-draft/route') const { POST } = await import('@/app/api/incidents/[id]/ai/rca-draft/route')
+1 -5
View File
@@ -36,7 +36,7 @@ vi.mock('@/lib/supabase/server', () => ({
})) }))
vi.mock('@/lib/claude/client', () => ({ vi.mock('@/lib/claude/client', () => ({
createDeepSeekClient: vi.fn().mockReturnValue({ createLocalLLMClient: vi.fn().mockReturnValue({
chat: { chat: {
completions: { completions: {
create: vi.fn().mockResolvedValue({ create: vi.fn().mockResolvedValue({
@@ -57,10 +57,6 @@ vi.mock('@/lib/claude/client', () => ({
}), }),
})) }))
vi.mock('@/lib/settings', () => ({
getApiKey: vi.fn().mockResolvedValue('sk-test-key'),
}))
describe('POST /api/incidents/[id]/ai/triage-suggest', () => { describe('POST /api/incidents/[id]/ai/triage-suggest', () => {
it('returns triage suggestion with severity and DOSH flags', async () => { it('returns triage suggestion with severity and DOSH flags', async () => {
const { POST } = await import('@/app/api/incidents/[id]/ai/triage-suggest/route') const { POST } = await import('@/app/api/incidents/[id]/ai/triage-suggest/route')