Files
goodbuddy/src/shared/local-inference-contracts.ts
T
mesalogo 935a8f56bf feat: add persistent document handling and protect note drafts
Add HTTP PaddleOCR-VL settings and shared document previews for chat and knowledge imports. Preserve attachment originals and parsed assets across drafts, messages and queues; support explicit image OCR, selecting document images into a conversation draft, and restoring queued input for editing.

Protect unsaved note bodies and titles during navigation and asynchronous updates. Match canvas analysis to source revisions, invalidate affected comments, preserve annotations during pagination, and provide a resizable record index with saved width preferences.

Existing OCR settings retain local behavior. Historical attachments without saved originals are not reconstructed. Advanced OCR options depend on the configured service; image sending depends on the effective model and Runtime.

Validation: full typecheck and lint passed; 477 focused tests passed across 12 files; staged whitespace checks passed. The full repository suite was not rerun for this commit.

Release note: Keep note drafts safe while switching workspaces, resize the record index, and revisit saved document attachments with OCR previews and selected images in chat.
2026-09-19 16:51:10 +08:00

57 lines
1.9 KiB
TypeScript

import { z } from 'zod'
export const inferenceServiceIdSchema = z.enum(['asr', 'ocr', 'embedding', 'tts'])
export const inferenceActionSchema = z.object({
serviceId: inferenceServiceIdSchema,
action: z.enum(['start', 'stop', 'restart']),
confirmedTaskIds: z.array(z.string().max(200)).max(256).default([])
}).strict()
export const inferenceCancelSchema = z.object({ taskId: z.string().min(1).max(200) }).strict()
export type InferenceServiceId = z.infer<typeof inferenceServiceIdSchema>
export type InferenceAction = z.infer<typeof inferenceActionSchema>
export type InferenceTask = {
id: string
serviceId: InferenceServiceId
source: string
model?: string
state: 'running' | 'cancelling' | 'completed' | 'cancelled' | 'failed'
startedAt: number
finishedAt?: number
error?: string
cancelUnavailableReason?: string
}
export type InferenceResources =
| { scope: 'unavailable'; reason: string }
| {
scope: 'service-process'
pid: number
sampledAt: number
cpuPercent?: number
cpuUnavailableReason?: string
workingSetBytes?: number
memoryUnavailableReason?: string
}
export type InferenceService = {
id: InferenceServiceId
name: string
engine: string
ownership: 'request-worker' | 'renderer-worker' | 'managed-process' | 'unavailable'
state: 'idle' | 'running' | 'starting' | 'stopping' | 'stopped' | 'error' | 'unavailable' | 'unknown'
model?: string
detail: string
error?: string
actions: InferenceAction['action'][]
resources?: InferenceResources
}
export type LocalInferenceSnapshot = {
services: InferenceService[]
tasks: InferenceTask[]
externalConnections?: { id: string; name: string; model: string }[]
}
export type LocalInferenceApi = {
openSettings: (category?: 'model' | 'document-parsing') => Promise<void>
getSnapshot: () => Promise<LocalInferenceSnapshot>
act: (input: InferenceAction) => Promise<void>
cancel: (taskId: string) => Promise<void>
}