The types around Camera: the workflows built on it, the connection under it, and the host that shares cameras between callers. This is one of the 5 pages of the types reference, which names every type. A field ending in ? may be absent: Slate leaves out what a camera does not report, and never guesses it.
import type { CameraClient, CameraProvider } from '@darkgrade/slate/runtime'Workflows
The types of the workflows built on Camera: takes on several cameras, shot analysis and setup and checks before a shoot.
BenchmarkCheck
One check of runBenchmark and how it went.
interface BenchmarkCheck {
name: string
passed: boolean
durationMilliseconds: number
error?: 'operation-failed' | 'deadline' | 'cancelled'
}Show BenchmarkCheck fieldsHide BenchmarkCheck fields
Which check.
Whether it succeeded.
How long it took.
Why it did not pass: the operation failed, the deadline passed, or the run was cancelled.
BenchmarkOptions
What runBenchmark takes. Every field is optional.
interface BenchmarkOptions {
photo?: boolean
liveView?: boolean
purpose?: 'benchmark' | 'first-contact'
signal?: AbortSignal
timeoutMilliseconds?: number
maximumProperties?: number
onProgress?: (check: BenchmarkCheck) => void
flushEvidence?: () => Promise<unknown>
}Show BenchmarkOptions fieldsHide BenchmarkOptions fields
Take one photo and transfer it.
Transfer one live-view frame.
'first-contact' is the automatic read-only inventory: no capture, live view or storage mode change.
Cancels the run.
The deadline for the whole run, from 1 to 300,000.
The most property descriptors to read, from 1 to 512.
Called with each check as it finishes.
See BenchmarkCheck.
Hosts can drain their bounded telemetry queue between inventory phases.
QualificationCamera
The camera qualifyCameraSetting drives: one read of its controls and one write of a setting.
interface QualificationCamera {
read: () => Promise<{
controls?: Partial<
Record<QualificationSetting, QualificationControl>
>
}>
set: (
setting: QualificationSetting,
value: Value,
) => Promise<unknown>
}Show QualificationCamera fieldsHide QualificationCamera fields
Reads the current controls.
See QualificationSetting.
Writes one setting.
See QualificationSetting.
QualificationSetting
The settings qualifyCameraSetting can exercise.
type QualificationSetting = typeof qualificationSettings[number]Every value (4)
Every value (4)
shutterSpeed aperture iso whiteBalance
VideoTakeState
A take on several cameras as VideoTake publishes it: its stage and each camera's state. See Record a take on several cameras.
interface VideoTakeState {
id: string
name: string
stage: 'preparing'
| 'armed'
| 'recording'
| 'stopping'
| 'review'
| 'collecting'
| 'complete'
| 'attention'
createdAt: string
maximumMinutes: number
error?: string
stopRequested?: boolean
startedAt?: string
stoppedAt?: string
startSkewMilliseconds?: number
cameras: TakeCameraState[]
}Show VideoTakeState fieldsHide VideoTakeState fields
The id given to the constructor.
The take's name, at most 100 characters; Untitled take when none was given.
Where the take is. attention and review wait for a person.
When the take was made, as an ISO 8601 time.
The safety stop, from 1 to 120 minutes.
What went wrong with the take as a whole.
True once a stop was asked for.
When recording started, as an ISO 8601 time.
When recording stopped, as an ISO 8601 time.
The time between the first camera's start and the last one's.
Each camera's part of the take.
See TakeCameraState.
TakeCamera
What VideoTake needs from each camera: the five steps of a take, which you implement over a Camera.
interface TakeCamera {
prepare: () => Promise<void>
start: () => Promise<{
recordingConfirmed:boolean
evidence:string
}>
stop: () => Promise<{
stopped:boolean
media:TakeMedia[]
warning?:string
}>
collect: (
media:TakeMedia[],
progress:(bytes:number,total:number)=>void,
) => Promise<TakeMedia[]>
close: () => Promise<void>
}Show TakeCamera fieldsHide TakeCamera fields
Gets the camera ready to record.
Starts recording, and says whether the camera confirmed it and on what evidence.
Stops recording and lists the new clips.
See TakeMedia.
Copies the clips off the camera, reporting progress, and returns them.
See TakeMedia.
Releases the camera.
TakeCameraState
One camera's part in a take: its state, when it started and stopped, and its clips. stopRequestedAt precedes the first adapter stop attempt; stoppedAt includes card finalization/media discovery.
interface TakeCameraState {
camera: string
state: 'preparing'
| 'ready'
| 'recording'
| 'stopping'
| 'stopped'
| 'collected'
| 'error'
| 'uncertain'
recordingConfirmed?: boolean
startedAt?: string
stopRequestedAt?: string
stoppedAt?: string
evidence?: string
error?: string
warning?: string
media: TakeMedia[]
transferredBytes?: number
totalBytes?: number
transferRecovery?: string
}Show TakeCameraState fieldsHide TakeCameraState fields
The camera's key in the map given to VideoTake.
Where this camera is in the take. uncertain: its start was sent and not confirmed.
Whether the camera confirmed that it was recording.
When its start returned, as an ISO 8601 time.
When its first stop attempt began, as an ISO 8601 time.
When it had stopped and its clips were found, as an ISO 8601 time.
What the start was confirmed by, in words.
What went wrong on this camera.
Something to check that did not fail the take.
Its clips.
See TakeMedia.
Bytes copied so far while collecting.
Bytes to copy in all.
Set while an interrupted transfer is being retried.
TakeMedia
One clip of a take.
interface TakeMedia {
id: string
filename: string
bytes: number
downloadUrl?: string
verified: boolean
}Show TakeMedia fieldsHide TakeMedia fields
The clip's id on its camera.
Its file name.
Its size in bytes.
Where the collected copy is, once it is collected.
Whether the collected copy was verified.
ShotAnalysis
What analyseShot measured in a picture, and how it reads the exposure, focus and colour. See Analyse and set up a shot.
interface ShotAnalysis {
metrics: ShotMetrics
effectiveIso?: number
exposure: 'balanced' | 'bright' | 'dark'
focus: 'detail-visible' | 'soft'
colour: 'neutral' | 'cast' | 'unknown'
method: string
durationMilliseconds: number
scene?: {
subject: string
focus: boolean
colour: boolean
confidence: number
}
}Show ShotAnalysis fieldsHide ShotAnalysis fields
The measurements the three readings below are made from.
See ShotMetrics.
The ISO in the picture's EXIF, when it has one.
How the exposure reads: clipped or very bright, dark, or in between.
Whether edge detail is visible. Edge contrast describes the picture; it cannot prove the subject is in focus.
Whether near-grey pixels are neutral or carry a cast; unknown when the picture has too few of them.
How the picture was analysed, in words.
How long the analysis took.
A local vision model's review of the subject, present only when one was already running.
ShotMetrics
The numbers measureShot takes from the middle of a picture, leaving a 15% border out.
interface ShotMetrics {
median: number
p95: number
clipped: number
dark: number
detail: number
neutralPixels: number
redBlueRatio: number
}Show ShotMetrics fieldsHide ShotMetrics fields
Median brightness (luma), 0 to 1.
95th-percentile brightness, 0 to 1.
The share of pixels clipped to white, 0 to 1.
The share of pixels darker than 0.08, 0 to 1.
Edge detail: the mean squared Laplacian of brightness.
The share of pixels that are near grey, 0 to 1.
Red over blue across the near-grey pixels; about 1 is neutral.
ShotSetupReport
What optimiseShot changed, and whether the result was verified.
interface ShotSetupReport {
status: 'verified' | 'attention' | 'unavailable'
summary: string
durationMilliseconds: number
changes: {
setting: string
before: string
after: string
verified: boolean
reverted?: boolean
attempted?: string
}[]
analysis?: ShotAnalysis
before?: ShotAnalysis
error?: string
budgetExceeded?: boolean
imageVerified?: boolean
focusVerified?: boolean
exposureVerified?: boolean
}Show ShotSetupReport fieldsHide ShotSetupReport fields
verified: the exposure measured in range and every change read back. attention: something still needs a person. optimiseShot returns only these two.
The result in a sentence.
How long the setup took.
Each setting written: its value before and after, and whether it read back.
The picture after the changes.
See ShotAnalysis.
The picture before any change.
See ShotAnalysis.
What stopped the setup, when something did.
True when the time budget ran out.
Whether analysis is of a picture taken after the last change.
Whether focus on the subject was confirmed, by the camera or by the scene review.
Whether the exposure measured in range with fixed ISO and shutter speed, each change read back.
ShotProperty
A setting as optimiseShot reads it: the fields of a CameraControlState it needs.
interface ShotProperty {
value?: string
allowedValues?: string[]
writable?: boolean
enabled?: boolean
}Show ShotProperty fieldsHide ShotProperty fields
The current value.
The values the camera offers now.
Whether the camera accepts a write now.
Whether the setting applies in the camera's current mode.
CameraPower
A camera's battery and power reading, as readCameraPower returns it. Camera telemetry only. A configured outlet or USB cable is not power-source evidence.
interface CameraPower {
observedAt: string
lastRefreshError?: string
source: string
percent?: number
level?: 'empty' | 'low' | 'medium' | 'high' | 'full'
powerSource: 'battery'
| 'dc'
| 'usb'
| 'poe'
| 'unknown'
remainingMinutes?: number
charging?: boolean
batteryPresent?: boolean
raw: Record<string, string | number>
}Show CameraPower fieldsHide CameraPower fields
When the camera was read, as an ISO 8601 time.
Why the latest read failed, when it did.
Which reading it came from, such as ptp-battery-level, canon-eos-ptp or sony-sdk.
0–100, when the camera reports a percentage.
The camera's coarse level, when it reports one.
What powers the camera; unknown unless the camera says.
The camera's own estimate of the minutes left.
True only when explicitly reported; external power does not imply charging.
Whether a battery is in the camera, when it says.
The raw property values the reading was made from.
CameraPowerAssessment
What assessCameraPower concludes for a planned recording. See Checks before a shoot.
interface CameraPowerAssessment {
status: 'pass' | 'warn' | 'fail'
summary: string
runtimeVerified: boolean
reserveMinutes: number
}Show CameraPowerAssessment fieldsHide CameraPowerAssessment fields
pass, warn or fail for the planned recording.
The verdict in a sentence.
True only when the camera's own estimate covers the planned minutes and the reserve.
The reserve that was asked for.
Protocol and transport
The connection under a Camera: timeouts and logging and raw protocol access.
ObjectInfo
A file's PTP ObjectInfo dataset, as the camera sent it. takePhoto returns it with includeInfo.
interface ObjectInfo {
storageID: number
objectFormat: number
objectFormatDecoded: string
protectionStatus: number
objectCompressedSize: number
thumbFormat: number
thumbFormatDecoded: string
thumbCompressedSize: number
thumbPixWidth: number
thumbPixHeight: number
imagePixWidth: number
imagePixHeight: number
imageBitDepth: number
parentObject: number
associationType: number
associationDesc: number
sequenceNumber: number
filename: string
captureDate: string
modificationDate: string
keywords: string
}Show ObjectInfo fieldsHide ObjectInfo fields
The StorageID of the card the object is on.
The object's format code.
The name of that format, or Unknown_0x… when Slate has none.
0 for no protection, 1 for read-only.
The size in bytes; 0xffffffff when the object is 4 GiB or larger.
The thumbnail's format code.
The name of that format.
The thumbnail's size in bytes.
The thumbnail's width in pixels.
The thumbnail's height in pixels.
The picture's width in pixels.
The picture's height in pixels.
The picture's bit depth.
The ObjectHandle of the folder it is in; 0 at the top of the card.
For a folder, the kind of association; 0 for a file.
More about the association, when the type defines it.
Its place in a sequence, when it is part of one.
The file name on the card.
When it was captured, as a PTP date-time string in the camera's local time.
When it was last changed, in the same form.
Keywords, when the camera sets any.
DeviceDescriptor
Which device to open: a USB filter, or a host on the network. See Choose a camera.
interface DeviceDescriptor {
usb?: {
filters: Array<{
vendorId?: number
productId?: number
classCode?: number
subclassCode?: number
protocolCode?: number
serialNumber?: string
}>
exclusionFilters?: Array<{
vendorId?: number
productId?: number
classCode?: number
subclassCode?: number
protocolCode?: number
serialNumber?: string
}>
}
ip?: {
host: string
port?: number
protocol?: 'ptp/ip' | 'upnp'
localAddress?: string
}
}Show DeviceDescriptor fieldsHide DeviceDescriptor fields
Which USB device to open: one matching any of filters and none of exclusionFilters.
A camera on the network, for a PTP/IP transport.
TransportInterface
What a transport implements to carry PTP for a Camera. USB is built in; IPTransport is PTP/IP.
interface TransportInterface {
connect: (device?: DeviceDescriptor) => Promise<void>
disconnect: () => Promise<void>
send: (
data: Uint8Array,
sessionId: number,
transactionId: number,
) => Promise<void>
receive: (
maxLength: number,
sessionId: number,
transactionId: number,
) => Promise<Uint8Array>
isConnected: () => boolean
classRequestReset: () => Promise<void>
resetPort?: () => Promise<void>
getType: () => TransportType
connectionKind?: () => 'usb' | 'wifi' | 'ip'
isLittleEndian: () => boolean
on?: (handler: (event: PTPEvent) => void) => void
off?: (handler: (event: PTPEvent) => void) => void
}Show TransportInterface fieldsHide TransportInterface fields
Opens the device.
See DeviceDescriptor.
Closes it.
Sends one container.
Reads one container of up to maxLength bytes.
Whether the device is open.
The still-image class's Device Reset Request.
Resets the device's USB port and releases it, as if it were unplugged and replugged. Clears a pipe a crashed host left mid-transfer, which a Device Reset Request does not. The transport must be connected again afterwards.
Which kind of transport this is.
The connection as Camera.getInfo() reports it, for a transport that is not what getType() implies (Sony's authenticated SDK channel runs over Wi-Fi IP but is not PTP/IP). Without it: USB or PTP/IP.
Get endianness for this transport PTP datasets and both USB and PTP/IP packet fields use little-endian encoding.
Calls handler with each PTP event the device sends.
Stops handler.
OperationParams
The parameters of a raw operation, by name, as protocolSession(camera).send takes them. See Raw protocol access.
type OperationParams<
Op extends { operationParameters: readonly unknown[] },
> =
Op['operationParameters'] extends readonly []
? Record<string, never>
: BuildParamObject<Op['operationParameters']>OperationResponse
What a raw operation resolves to: the response code and parameters, with data when the operation returns any.
type OperationResponse<Op> =
Op extends { dataCodec: infer C }
? { code: number; parameters?: number[]; data: CodecType<C> }
: Op extends { dataDirection: 'out' }
? { code: number; parameters?: number[]; data: Uint8Array }
: { code: number; parameters?: number[] }EventParams
The parameters of a raw event, by name.
type EventParams<E extends { parameters: readonly unknown[] }> =
E['parameters'] extends readonly []
? Record<string, never>
: BuildEventParamObject<E['parameters']>TransactionPolicy
How long and how often Slate waits for a camera before giving up on a transaction.
interface TransactionPolicy {
timeoutMilliseconds: number
minimumThroughputBytesPerSecond: number
deviceBusyRetries: number
deviceBusyBackoffMilliseconds: number
deviceBusyBudgetMilliseconds: number
automaticUSBReset: boolean
recoverTransport?: (failure: PTPErrorContext) => Promise<void>
}Show TransactionPolicy fieldsHide TransactionPolicy fields
Base time a single send or receive phase may take.
Large data phases get extra time at this rate on top of the base timeout.
Standard (0x1xxx) operations answered DeviceBusy are retried at most this many times.
First retry delay; each further retry doubles it.
Retries stop once this much time has passed since the first attempt; the last delay is shortened to fit.
After a timeout or framing violation on a USB transport, automatically send the still-image class Device Reset Request, wait for the abandoned I/O to settle and reopen the session before the next command. On by default. If the automatic reset fails, later commands fail with PTPRecoveryRequiredError until a disconnect/connect. Transports without a class reset (PTP/IP) always latch instead.
Caller-owned recovery that replaces the automatic USB reset, for example to honor recording/lease guards. It must settle outstanding transport I/O before resolving and must not call this camera's queued methods. Failed or pending recovery blocks further commands; use an explicit disconnect/connect to establish a new transport instead.
PTPProtocolViolation
How a reply broke PTP container framing, on PTPProtocolError.violation.
type PTPProtocolViolation =
| 'short-container'
| 'truncated-container'
| 'unexpected-container-type'
| 'transaction-mismatch'
| 'operation-mismatch'LoggerConfig
What the logger option of new Camera() takes. See Timeouts and logging.
type LoggerConfig = {
expanded?: boolean
captureConsole?: boolean
renderInTerminal?: boolean
maxTransactions?: number
}Show LoggerConfig fieldsHide LoggerConfig fields
Shows each entry's detail in the terminal view; false shows one line per entry.
Routes console.log, console.info, console.warn and console.error into the logger's view. Node only.
Draws a live view of every transaction in the terminal. Node only.
Transactions kept in memory; older ones are dropped, with any data they carried.
Runtime
What a host that shares cameras is written against. These are imported from @darkgrade/slate/runtime, not the main entry. Host cameras for other processes shows them at work.
CameraClient
What MCP and other remote frontends call: the public operations, by their library name.
interface CameraClient {
discover: () => Promise<DiscoveredCamera[]>
operation: (
camera: string,
name: string,
input?: OperationInput,
) => Promise<OperationReply>
benchmark?: (camera: string) => Promise<unknown>
}Show CameraClient fieldsHide CameraClient fields
Camera.discover(): the attached cameras, without opening one.
See DiscoveredCamera.
Runs one public Camera operation on the host's camera with this identity.
See OperationInput, OperationReply.
The deep benchmark workflow, runBenchmark, where the host offers it.
CameraProvider
Platform hosts supply the connected Camera and physical services, never a second MCP-owned session. The runtime runs every operation through Camera itself, so hosts keep no vendor tables.
interface CameraProvider {
discover: () => Promise<DiscoveredCamera[]>
camera: (camera: string) => Camera | Promise<Camera>
assertAllowed: (
camera: string,
operation: string,
) => void | Promise<void>
saveFile?: (
camera: string,
file: OperationFile,
) => Promise<string>
benchmark?: (camera: string) => Promise<unknown>
}Show CameraProvider fieldsHide CameraProvider fields
See DiscoveredCamera.
Throws (for example HardwareBusyError) when this operation may not run now.
Keeps a returned file where the client can read it; the path is returned in the reply.
See OperationFile.
OperationReply
An operation's result as it crosses a process: JSON, with any bytes the host saved by path.
interface OperationReply {
result: unknown
files: {
role: OperationFile['role']
name: string
mimeType: string
bytes: number
path?: string
}[]
images?: { mimeType: string; base64: string }[]
}Show OperationReply fieldsHide OperationReply fields
The files the operation returned, without their bytes; path where the host saved one.
See OperationFile.
Image files inline (live-view frames and previews), for clients that show pictures.
OperationFile
A file an operation returned: a live-view frame, a preview, a photo's or a download's bytes.
interface OperationFile {
role: 'photo'
| 'frame'
| 'overlay'
| 'preview'
| 'download'
name: string
mimeType: string
data: Uint8Array
}Show OperationFile fieldsHide OperationFile fields
A name to save it under.
OperationInput
One call's inputs by parameter name, as an MCP client or the command line gave them.
type OperationInput = Readonly<Record<string, unknown>>SurfaceOperation
One public Camera operation with its MCP tool and CLI command names, as surfaceOperations() lists it.
interface SurfaceOperation extends CameraOperationDescription {
mcpTool: string
cliCommand: string
immediate: boolean
readOnly: boolean
name: string
static?: boolean
summary: string
parameters: readonly OperationParameter[]
}Show SurfaceOperation fieldsHide SurfaceOperation fields
camera_take_photo.
darkgrade camera take-photo (darkgrade cameras for discover).
Stopping never waits behind other camera work, so these run as soon as they are asked for.
Reads without changing the camera.
The first sentence of the method's doc comment.
OwnershipStore
The store a HardwareCoordinator keeps its leases in, shared by every process that might open the same camera. You implement it.
interface OwnershipStore {
claimHardwareResource: (
resource: string,
owner: string,
purpose: string,
lifetimeMilliseconds: number,
) => boolean
heartbeatHardwareOwner: (
owner: string,
lifetimeMilliseconds: number,
) => unknown
releaseHardwareOwner: (owner: string) => unknown
hardwareOwners: () => unknown[]
}Show OwnershipStore fieldsHide OwnershipStore fields
Other types
The types you pass to Camera: its constructor options, and the options and choices of its methods.
The types Camera hands back: what each method resolves to, what an event carries, and what recover() reports.
The types that say what the connected camera is and can do now: what getCapabilities() returns, what setControl takes, and which model was identified.
One type per setting: the values its getter returns and its setter takes, with the types the typed getters and setters are declared with.
Related
The class: constructor, every method, what each returns and throws.
Every setting id with its values, getter, setter and vendor properties.
Every exported type, field by field.
Every error class: when it is thrown and what to do.
Every import path of the package and what it exports.