import type { ProtocolStep, ScheduleEvent, } from '../types' import { getTemplateData } from './templateEnvelopes' import { validateInstrumentRunData } from './templateValidators' import type { InstrumentRunColumnsAdapterResult, InstrumentRunDataFrameAdapterResult, InstrumentRunRowsAdapterResult, InstrumentRunScheduleEventsAdapterResult, InstrumentRunStepsAdapterResult, InstrumentRunTemplate, InstrumentRunTemplateData, } from './types' import { addMinutes, dateFromMetadata, instrumentRunScheduleColor, instrumentRunScheduleStatus, instrumentRunStepStatus, instrumentRunStepType, } from './instrumentRunAdapterHelpers' /** @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function toInstrumentRunRows( template: InstrumentRunTemplate | InstrumentRunTemplateData ): InstrumentRunRowsAdapterResult { const data = getTemplateData(template, 'instrument-run') validateInstrumentRunData(data) const methods = new Map(data.methods.map(method => [method.id, method])) return [...data.items] .sort((a, b) => a.order - b.order) .map(item => { const method = methods.get(item.methodId) return { id: item.id, order: item.order, kind: item.kind, sampleId: item.sampleId, name: item.name ?? item.sampleId ?? item.kind, method: method?.name ?? item.methodId, vial: item.vial, plateId: item.plateId, wellId: item.wellId, injectionVolume: item.injectionVolume, expectedDurationMin: item.expectedDurationMin, status: item.status, instrument: data.instrument ?? method?.instrument, ...(item.metadata ?? {}), } }) } /** @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function toInstrumentRunColumns(): InstrumentRunColumnsAdapterResult { return [ { key: 'order', label: 'Order', sortable: true, align: 'right' }, { key: 'kind', label: 'Kind', sortable: true }, { key: 'sampleId', label: 'Sample ID', sortable: true }, { key: 'name', label: 'Name', sortable: true }, { key: 'method', label: 'Method', sortable: true }, { key: 'vial', label: 'Vial', sortable: true }, { key: 'wellId', label: 'Well', sortable: true }, { key: 'injectionVolume', label: 'Injection', sortable: true, align: 'right' }, { key: 'expectedDurationMin', label: 'Duration', sortable: true, align: 'right' }, { key: 'status', label: 'Status', sortable: true }, { key: 'instrument', label: 'Instrument', sortable: true }, ] } /** @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function toInstrumentRunDataFrame( template: InstrumentRunTemplate | InstrumentRunTemplateData ): InstrumentRunDataFrameAdapterResult { return { data: toInstrumentRunRows(template), columns: toInstrumentRunColumns(), rowKey: 'id', } } /** * Convert an instrument-run template into ExperimentTimeline protocol steps for acquisition queue previews. * * @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function toInstrumentRunSteps( template: InstrumentRunTemplate | InstrumentRunTemplateData ): InstrumentRunStepsAdapterResult { const data = getTemplateData(template, 'instrument-run') validateInstrumentRunData(data) const methods = new Map(data.methods.map(method => [method.id, method])) return [...data.items] .sort((a, b) => a.order - b.order) .map((item): ProtocolStep => { const method = methods.get(item.methodId) const name = item.name ?? item.sampleId ?? item.kind return { id: item.id, type: instrumentRunStepType(item.kind), name, description: [ item.kind, method?.name, item.vial ? `Vial ${item.vial}` : undefined, item.wellId ? `Well ${item.wellId}` : undefined, ] .filter(Boolean) .join(' / '), duration: item.expectedDurationMin, status: instrumentRunStepStatus(item.status), parameters: { kind: item.kind, sampleId: item.sampleId, methodId: item.methodId, method: method?.name, vial: item.vial, plateId: item.plateId, wellId: item.wellId, injectionVolume: item.injectionVolume, instrument: data.instrument ?? method?.instrument, }, order: item.order, } }) } /** * Convert an instrument-run template into readonly ScheduleCalendar events ordered by run queue timing. * * @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function toInstrumentRunScheduleEvents( template: InstrumentRunTemplate | InstrumentRunTemplateData ): InstrumentRunScheduleEventsAdapterResult { const data = getTemplateData(template, 'instrument-run') validateInstrumentRunData(data) const methods = new Map(data.methods.map(method => [method.id, method])) let cursor = dateFromMetadata(data.metadata, ['scheduledStart', 'runStart', 'start', 'startedAt']) ?? new Date('2024-01-01T08:00:00.000Z') return [...data.items] .sort((a, b) => a.order - b.order) .map((item): ScheduleEvent => { const method = methods.get(item.methodId) const start = dateFromMetadata(item.metadata, ['scheduledStart', 'start', 'startedAt']) ?? cursor const end = dateFromMetadata(item.metadata, ['scheduledEnd', 'end', 'completedAt']) ?? addMinutes(start, Math.max(item.expectedDurationMin ?? 10, 1)) cursor = end return { id: item.id, title: item.name ?? item.sampleId ?? item.kind, start: start.toISOString(), end: end.toISOString(), color: instrumentRunScheduleColor(item.kind), status: instrumentRunScheduleStatus(item.status), draggable: false, resizable: false, metadata: { kind: item.kind, sampleId: item.sampleId, methodId: item.methodId, method: method?.name, vial: item.vial, plateId: item.plateId, wellId: item.wellId, injectionVolume: item.injectionVolume, instrument: data.instrument ?? method?.instrument, }, } }) }