Skip to content

Commit a98cbfd

Browse files
committed
schema v2 for command annotations
1 parent 6a4ba8e commit a98cbfd

File tree

3 files changed

+112
-3
lines changed

3 files changed

+112
-3
lines changed

api/src/opentrons/protocol_runner/json_translator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,13 @@ def translate_command_annotations(
304304
"""Translate command annotations in json protocol schema v8."""
305305
if isinstance(protocol, (ProtocolSchemaV6, ProtocolSchemaV7)):
306306
return []
307-
else:
307+
elif protocol.commandAnnotationSchemaId == "opentronsCommandAnnotationSchemaV1":
308308
command_annotations: List[CommandAnnotation] = [
309309
CommandAnnotationAdapter.validate_python(
310310
command_annotation.model_dump(),
311311
)
312312
for command_annotation in protocol.commandAnnotations
313313
]
314314
return command_annotations
315+
else:
316+
return []
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"$id": "opentronsCommandAnnotationSchemaV2#",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"$defs": {
5+
"baseAnnotation": {
6+
"description": "Things all annotations have",
7+
"type": "object",
8+
"required": ["annotationType", "annotationID"],
9+
"properties": {
10+
"annotationID": {
11+
"description": "A unique identifier for a command annotation.",
12+
"type": "string"
13+
},
14+
"annotationType": {
15+
"description": "The type of annotation (for machine parsing)",
16+
"type": "string"
17+
},
18+
"parentAnnotation": {
19+
"description": "The parent annotation of this annotation, if any.",
20+
"type": "string"
21+
}
22+
}
23+
},
24+
"secondOrderCommand": {
25+
"description": "Annotates a group of atomic commands which were the direct result of a second order command (e.g. transfer, consolidate, mix)",
26+
"allOf": [{ "$ref": "#/$defs/baseAnnotation" }],
27+
"type": "object",
28+
"required": [
29+
"annotationType",
30+
"commandKeys",
31+
"params",
32+
"machineReadableName"
33+
],
34+
"properties": {
35+
"annotationType": {
36+
"type": "string",
37+
"enum": ["secondOrderCommand"]
38+
},
39+
"params": {
40+
"description": "key value pairs of the parameters that were passed to the second order command that this annotates",
41+
"type": "object"
42+
},
43+
"machineReadableName": {
44+
"description": "The name of the second order command in the form that the generating software refers to it. (e.g. 'transfer', 'thermocyclerStep')",
45+
"type": "string"
46+
},
47+
"userSpecifiedName": {
48+
"description": "The optional user-specified name of the second order command",
49+
"type": "string"
50+
},
51+
"userSpecifiedDescription": {
52+
"description": "The optional user-specified description of the second order command",
53+
"type": "string"
54+
}
55+
}
56+
},
57+
"userCommand": {
58+
"description": "A user generated command annotation as opposed to one generated automatically.",
59+
"allOf": [{ "$ref": "#/$defs/baseAnnotation" }],
60+
"type": "object",
61+
"required": [
62+
"annotationType",
63+
"annotationID",
64+
"params",
65+
"userSpecifiedName"
66+
],
67+
"properties": {
68+
"annotationType": {
69+
"type": "string",
70+
"enum": ["userCommand"]
71+
},
72+
"params": {
73+
"description": "key value pairs of the parameters that were passed to the second order command that this annotates",
74+
"type": "object"
75+
},
76+
"userSpecifiedName": {
77+
"description": "The optional user-specified name of the second order command",
78+
"type": "string"
79+
},
80+
"userSpecifiedDescription": {
81+
"description": "The optional user-specified description of the second order command",
82+
"type": "string"
83+
}
84+
}
85+
},
86+
"custom": {
87+
"description": "Annotates a group of atomic commands in some manner that Opentrons software does not anticipate or originate",
88+
"allOf": [{ "$ref": "#/$defs/baseAnnotation" }],
89+
"type": "object",
90+
"required": ["annotationType", "commandKeys"],
91+
"properties": {
92+
"annotationType": {
93+
"type": "string",
94+
"enum": ["custom"]
95+
}
96+
},
97+
"additionalProperties": true
98+
}
99+
},
100+
"oneOf": [
101+
{ "$ref": "#/$defs/secondOrderCommand" },
102+
{ "$ref": "#/$defs/custom" }
103+
]
104+
}

shared-data/python/opentrons_shared_data/protocol/models/protocol_schema_v8.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Any, List, Optional, Dict
2+
from typing import Any, List, Optional, Dict, Union
33
from typing_extensions import Literal
44

55
from pydantic import BaseModel, Field, ConfigDict
@@ -50,7 +50,10 @@ class ProtocolSchemaV8(BaseModel):
5050
labwareDefinitions: Dict[str, LabwareDefinition]
5151
commandSchemaId: CommandSchemaId
5252
commands: List[Command]
53-
commandAnnotationSchemaId: Literal["opentronsCommandAnnotationSchemaV1"]
53+
commandAnnotationSchemaId: Union[
54+
Literal["opentronsCommandAnnotationSchemaV1"],
55+
Literal["opentronsCommandAnnotationSchemaV2"],
56+
]
5457
commandAnnotations: List[CommandAnnotation]
5558
designerApplication: Optional[DesignerApplication] = None
5659
model_config = ConfigDict(populate_by_name=True)

0 commit comments

Comments
 (0)