Skip to content

Protocol Reference

The SDK package owns the protocol contract in packages/sdk/src/protocol/.

Version

ts
export const PROTOCOL_VERSION = 1;

Frame Kinds

Request:

ts
{
  id: string;
  method: string;
  params: unknown;
}

Response:

ts
{
  id: string;
  ok: true;
  result: unknown;
}
{
  id: string;
  ok: false;
  error: ProtocolError;
}

Event:

ts
{
  type: string;
  data: unknown;
}

Events have no id and no direct response.

Built-in Methods

MethodPurpose
getServerInfoServer identity, Photoshop version when available, loaded plugins.
jsx:runRun an inline JSX script.
jsx:executeExecute a named JSX resource with params.
event:subscribeSubscribe the logical client to an event type.
event:unsubscribeRemove that event subscription.
action:autoCutoutRun auto cutout action.
action:removeBackgroundRun remove background action.
layer:getInfoInspect layer information.
layer:getInfoByIdInspect layer by id.
layer:getInfoByIndexInspect layer by index.
layer:getInfoBySelectionIndexInspect layer by Photoshop selection index.
layer:getCurrentPreviewGet the current selected layer preview payload.
layer:importImageValidate and import an image source into Photoshop as a layer.
document:currentGet current document information.
document:exportExport document.
document:saveSave document.
image:exportLayerExport a layer image result.
image:exportLayerWithSelectedPathExport a layer image with the current selection path overlay.
image:getPreviewGet a layer preview image result.
image:exportDocumentExport a document image result.
selection:getAreaGet the current rectangular selection area, or null.
selection:getPathGet the current selection path as SVG metadata, or null.
selection:changeRegister the generator-side selection change watcher.

Plugin-specific methods are open string names and are invoked through connection.invoke(...) on plugin endpoint connections.

HTTP APIs

EndpointPurpose
GET /healthService liveness probe.
GET /pluginsLoaded plugin discovery.
GET /plugins/{id}/healthLoaded plugin runtime status or failed load diagnosis.
POST /action/auto-cutoutRun action:autoCutout; returns boolean.
POST /action/remove-backgroundRun action:removeBackground; returns { success }.
GET /document/currentRun document:current; returns PsDocument.
POST /document/exportRun document:export; body is the WS params.
POST /document/saveRun document:save; body is { savePath? }.
GET /layer/infoRun layer:getInfo; params come from query string.
GET /layer/by-id/{layerID}Run layer:getInfoById; getChildren is a query arg.
GET /layer/by-index/{layerIndex}Run layer:getInfoByIndex; getChildren is a query arg.
GET /layer/current-previewRun layer:getCurrentPreview.
POST /layer/import-imageRun layer:importImage; body is LayerImportImageParams.
POST /image/export-layerRun image:exportLayer; body is the WS params.
POST /image/export-layer-with-selected-pathRun image:exportLayerWithSelectedPath; body is the WS params.
GET /image/preview/{layerSpec}Run image:getPreview; documentId is a query arg.
POST /image/export-documentRun image:exportDocument; body is the WS params.
GET /selection/areaRun selection:getArea; returns PsRect | null.
GET /selection/pathRun selection:getPath; expand is a query arg.

Module HTTP APIs reuse the corresponding WS result shape. selection:change remains a WS/event capability because HTTP cannot carry the ongoing selection change stream.

Server Info

ts
interface ServerInfo {
  name: string;
  version: string;
  psVersion?: string;
  plugins?: PluginInfo[];
}

interface PluginInfo {
  id: string;
}

type PluginStatus = "loaded" | "failed";

type PluginHealthCheck = "ok" | "failed" | "skipped";

interface PluginHealth {
  id: string;
  status: PluginStatus;
  clients: number;
  loadedAt?: number;
  lastError?: ProtocolError;
  checks?: Record<string, PluginHealthCheck>;
}

Failed plugin health may report load or registration checks. A loaded plugin can remain available with a failed runtime check after a contained lifecycle hook error. lastError uses PLUGIN_LOAD_FAILED, PLUGIN_REGISTRATION_FAILED, or PLUGIN_LIFECYCLE_FAILED as appropriate.

Main Events

ts
"#ready": {
  port: number;
  plugins: PluginInfo[];
}

"#closing": {
  reason: "host-close" | "process-exit";
}

"selection:changed": PsRect | null;

"layer:previewChange": LayerPreviewPayload;

"layer:selectionChange": PsLayer[] | null;

Error Shape

ts
interface ProtocolError {
  code: string;
  message: string;
  details?: Record<string, unknown>;
  retryable?: boolean;
  source?: ErrorSource;
  requestId?: string;
  method?: string;
  pluginId?: string;
}

Helpers

The SDK exports helpers for frame handling:

ts
parseFrame(data);
serializeFrame(value);
isRequest(value);
isResponse(value);
isEvent(value);