@printobserver/sdk 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ export declare const CONTRACT_VERSION: string;
18
18
  * Every operation this client exposes a method for, which is every operation
19
19
  * the server declares and no other.
20
20
  */
21
- export declare const OPERATION_NAMES: readonly ["prints", "status", "context", "image", "history", "manifest_get", "look", "manifest_set", "spools", "spool", "printer_history", "preflight", "pause", "resume", "cancel", "start_print", "set_feedrate_factor", "set_flowrate_factor", "set_tool_target_c", "set_bed_target_c", "set_fan_percent", "acknowledge_failure", "register_spool", "load_spool", "unload_spool", "adjust_spool", "retire_spool"];
21
+ export declare const OPERATION_NAMES: readonly ["prints", "status", "context", "image", "history", "events", "manifest_get", "look", "manifest_set", "spools", "spool", "printer_history", "preflight", "pause", "resume", "cancel", "start_print", "set_feedrate_factor", "set_flowrate_factor", "set_tool_target_c", "set_bed_target_c", "set_fan_percent", "acknowledge_failure", "register_spool", "load_spool", "unload_spool", "adjust_spool", "retire_spool"];
22
22
  /** What an operator's acknowledgement of a failure event asks for next. */
23
23
  export type AcknowledgementDisposition = "continue" | "watch" | "stop";
24
24
  /** What one mutating request left behind it. */
@@ -177,6 +177,30 @@ export interface ChargePendedPayload {
177
177
  /** What was held. */
178
178
  pending: PendingCharge;
179
179
  }
180
+ /**
181
+ * What a charge took from a spool, and the whole calculation behind it.
182
+ *
183
+ * Present or absent as one: a debit names its spool exactly when it carries
184
+ * the grams, the figures they were worked out with, and the spool's figure
185
+ * either side of them.
186
+ */
187
+ export interface ChargedFilament {
188
+ /**
189
+ * The density the grams were worked out with, in grams per cubic
190
+ * centimetre.
191
+ */
192
+ density_g_cm3: number;
193
+ /** The diameter the grams were worked out with, in millimetres. */
194
+ diameter_mm: number;
195
+ /** What the length weighs, in grams; what is subtracted from the spool. */
196
+ grams: number;
197
+ /** The spool's figure after it, in grams. */
198
+ remaining_after_g: number;
199
+ /** The spool's figure before the charge, in grams. */
200
+ remaining_before_g: number;
201
+ /** The spool charged. */
202
+ spool_id: SpoolId;
203
+ }
180
204
  /** One mark a spool command cleared, and the spool it was cleared from. */
181
205
  export interface ClearedMark {
182
206
  /** The reason that no longer stands. */
@@ -264,6 +288,28 @@ export interface EventRecord {
264
288
  * declares for itself.
265
289
  */
266
290
  export type EventSource = string;
291
+ /**
292
+ * What an events read answers: the events stored after its cursor that pass
293
+ * its filters, oldest first, and where the next read picks up.
294
+ */
295
+ export interface EventsAnswer {
296
+ /**
297
+ * The last event this read examined, whether or not it passed the
298
+ * filters, given as `after` to read on from it; null when the log held
299
+ * nothing to start after. Always sent, as null when it is that.
300
+ */
301
+ cursor: EventId | null;
302
+ /**
303
+ * The events, oldest first in the order they were stored, each exactly as
304
+ * a history read serves it.
305
+ */
306
+ events: Array<EventRecord>;
307
+ /**
308
+ * The watched print's end as stored, whatever the filters said, and null
309
+ * while it is open. Absent from a read that names no print.
310
+ */
311
+ print_ended?: PrintEnded | null;
312
+ }
267
313
  /** What happened when an accepted action reached the printer. */
268
314
  export type ExecutionOutcome = "succeeded" | {
269
315
  failed: {
@@ -272,13 +318,11 @@ export type ExecutionOutcome = "succeeded" | {
272
318
  };
273
319
  /** A filament change was signalled during a print. */
274
320
  export interface FilamentChangeSignalledPayload {
275
- /** The position the spool was charged up to, when one was known. */
276
- position?: FilePosition | null;
277
321
  /**
278
- * Whether that position was read when the signal was handled, rather than
279
- * being the last one recorded; never with no position at all.
322
+ * The position the spool was charged up to, and how fresh it is, when one
323
+ * was known; absent, there is no position and so no claim about one.
280
324
  */
281
- position_read_at_signal: boolean;
325
+ position?: SignalPosition | null;
282
326
  /** The kind of the alert that carried the signal. */
283
327
  source_kind: EventKind;
284
328
  /** The spool that was on it, when one was tracked. */
@@ -296,17 +340,11 @@ export interface FilamentConsumedPayload {
296
340
  /** The durable identity of this debit. */
297
341
  charge_key: ChargeKey;
298
342
  /**
299
- * The density the grams were worked out with, in grams per cubic
300
- * centimetre.
301
- */
302
- density_g_cm3?: number | null;
303
- /** The diameter the grams were worked out with, in millimetres. */
304
- diameter_mm?: number | null;
305
- /**
306
- * What that length weighs, in grams, when a spool gave its diameter and
307
- * density.
343
+ * The spool charged and the whole calculation of what it was charged;
344
+ * absent when nothing was tracked on the tool, and the filament was
345
+ * recorded uncharged.
308
346
  */
309
- grams?: number | null;
347
+ charged?: ChargedFilament | null;
310
348
  /** How much was fed, in millimetres. */
311
349
  length_mm: number;
312
350
  /** How the length was worked out. */
@@ -315,16 +353,7 @@ export interface FilamentConsumedPayload {
315
353
  note?: string | null;
316
354
  /** How far into the file the charge runs, when that was read. */
317
355
  position?: FilePosition | null;
318
- /** The spool's figure after it, in grams. */
319
- remaining_after_g?: number | null;
320
- /** The spool's figure before the charge, in grams. */
321
- remaining_before_g?: number | null;
322
- /**
323
- * The spool charged; absent when nothing was tracked on the tool, and the
324
- * filament was recorded uncharged.
325
- */
326
- spool_id?: SpoolId | null;
327
- /** The tool that fed it. */
356
+ /** The tool that fed it, as its key names it. */
328
357
  tool: number;
329
358
  }
330
359
  /**
@@ -696,8 +725,11 @@ export interface PendingCharge {
696
725
  * one.
697
726
  */
698
727
  analysed_length_mm?: number | null;
699
- /** The key of the print segment the filament was fed in. */
700
- charge_key: ChargeKey;
728
+ /**
729
+ * The print segment the filament was fed in, which names the print and
730
+ * the tool that fed it.
731
+ */
732
+ charge_key: PrintSegmentKey;
701
733
  /** How much was fed, in millimetres. */
702
734
  length_mm: number;
703
735
  /** How that length was worked out. */
@@ -708,10 +740,6 @@ export interface PendingCharge {
708
740
  pended_at: Timestamp;
709
741
  /** How far into the file the segment ran, when that was read. */
710
742
  position?: FilePosition | null;
711
- /** The print it was fed in. */
712
- print_id: PrintId;
713
- /** The tool that fed it. */
714
- tool: number;
715
743
  }
716
744
  /** One pending charge a spool command took. */
717
745
  export interface PendingTaken {
@@ -784,6 +812,8 @@ export interface PortFailurePayload {
784
812
  * a second version of one fact.
785
813
  */
786
814
  export type PortFailureSite = "printer_snapshot" | "printer_job" | "image_write" | "supervision_turn" | "camera_look" | "detector_acknowledgement";
815
+ /** How fresh the position a filament change charged up to is. */
816
+ export type PositionFreshness = "read_at_signal" | "last_recorded";
787
817
  /** What a filament check found for one print. */
788
818
  export interface Preflight {
789
819
  /** When the check was made. */
@@ -810,31 +840,88 @@ export interface PreflightCheckedPayload {
810
840
  /** What the check found. */
811
841
  preflight: Preflight;
812
842
  }
813
- /** What a filament check found for one tool. */
814
- export interface PreflightTool {
815
- /** The margin asked for beyond that, in grams. */
816
- buffer_g?: number | null;
843
+ /**
844
+ * What a print needs from one spool, in grams: both figures a comparison
845
+ * with what the spool holds uses, or neither.
846
+ */
847
+ export interface PreflightNeed {
848
+ /** The margin asked for beyond that. */
849
+ buffer_g: number;
817
850
  /**
818
- * The loaded spool's marks at the check, oldest first, whatever the
819
- * verdict, so a spool both short and unverified says both.
851
+ * What the print needs from the spool, by the file's analysis and the
852
+ * spool's own diameter and density.
820
853
  */
854
+ required_g: number;
855
+ }
856
+ /** What a check that refuses a start found for one tool. */
857
+ export type PreflightObjection = {
858
+ verdict: "insufficient";
821
859
  marks?: Array<UnverifiedMark>;
822
- /** What the spool holds, in grams. */
823
- remaining_g?: number | null;
824
- /** What the print needs from it, in grams, when the file's analysis says. */
825
- required_g?: number | null;
826
- /** The spool loaded on it, when one is. */
827
- spool_id?: SpoolId | null;
828
- /**
829
- * That spool's name, beside its identifier, so a reader need not look it
830
- * up.
831
- */
832
- spool_name?: string | null;
860
+ need: PreflightNeed;
861
+ remaining_g: number;
862
+ spool: PreflightSpool;
863
+ } | {
864
+ verdict: "unverified_spool";
865
+ marks: Array<UnverifiedMark>;
866
+ need?: PreflightNeed | null;
867
+ remaining_g: number;
868
+ spool: PreflightSpool;
869
+ } | {
870
+ verdict: "no_analysis";
871
+ remaining_g: number;
872
+ spool: PreflightSpool;
873
+ };
874
+ /**
875
+ * The spool a check judged, named beside its identifier so a reader need
876
+ * not look it up.
877
+ */
878
+ export interface PreflightSpool {
879
+ /** The spool's identifier. */
880
+ id: SpoolId;
881
+ /** The spool's name. */
882
+ name: string;
883
+ }
884
+ /** What a filament check found for one tool. */
885
+ export interface PreflightTool {
886
+ /** What the check found for it, with the evidence that finding rests on. */
887
+ result: PreflightToolResult;
833
888
  /** The tool, in the printer's own numbering. */
834
889
  tool: number;
835
- /** What the check found for this tool. */
836
- verdict: PreflightVerdict;
837
890
  }
891
+ /**
892
+ * What a filament check found for one tool, tagged by its verdict, each
893
+ * verdict carrying exactly the evidence it rests on.
894
+ */
895
+ export type PreflightToolResult = {
896
+ verdict: "passed";
897
+ need: PreflightNeed;
898
+ remaining_g: number;
899
+ spool: PreflightSpool;
900
+ } | {
901
+ verdict: "unchecked";
902
+ } | {
903
+ verdict: "insufficient";
904
+ marks?: Array<UnverifiedMark>;
905
+ need: PreflightNeed;
906
+ remaining_g: number;
907
+ spool: PreflightSpool;
908
+ } | {
909
+ verdict: "unverified_spool";
910
+ marks: Array<UnverifiedMark>;
911
+ need?: PreflightNeed | null;
912
+ remaining_g: number;
913
+ spool: PreflightSpool;
914
+ } | {
915
+ verdict: "no_analysis";
916
+ remaining_g: number;
917
+ spool: PreflightSpool;
918
+ } | {
919
+ verdict: "overridden";
920
+ objection: PreflightObjection;
921
+ } | {
922
+ verdict: "warned";
923
+ objection: PreflightObjection;
924
+ };
838
925
  /** What a filament check found, for one tool or for a whole print. */
839
926
  export type PreflightVerdict = "passed" | "unchecked" | "insufficient" | "unverified_spool" | "no_analysis" | "overridden" | "warned";
840
927
  /** The whole vocabulary an actor may ask for, and there is no other. */
@@ -914,6 +1001,15 @@ export interface PrintContext {
914
1001
  /** A bounded list of this print's events, newest first. */
915
1002
  recent_events: Array<EventRecord>;
916
1003
  }
1004
+ /** One print's end, as its `print_ended` event stored it. */
1005
+ export interface PrintEnded {
1006
+ /** The `print_ended` event. */
1007
+ event_id: EventId;
1008
+ /** How the print ended. */
1009
+ outcome: PrintOutcome;
1010
+ /** When that event was received. */
1011
+ received_at: Timestamp;
1012
+ }
917
1013
  /** A print ended. */
918
1014
  export interface PrintEndedPayload {
919
1015
  /** How far into its file it last read, when that was read. */
@@ -982,6 +1078,19 @@ export interface PrintRecord {
982
1078
  /** The state the print is in. */
983
1079
  state: PrinterState;
984
1080
  }
1081
+ /**
1082
+ * One segment of a print this system watched, on one tool: the key of a
1083
+ * `ChargeKey::Print` debit, and the only key filament held pending can be
1084
+ * under.
1085
+ */
1086
+ export interface PrintSegmentKey {
1087
+ /** The print. */
1088
+ print_id: PrintId;
1089
+ /** Which segment, numbered as `ChargeKey::Print` numbers it. */
1090
+ segment: number;
1091
+ /** The tool, in the printer's own numbering. */
1092
+ tool: number;
1093
+ }
985
1094
  /** A print started. */
986
1095
  export interface PrintStartedPayload {
987
1096
  /** The file being printed, when it is known. */
@@ -1115,7 +1224,8 @@ export type RejectionReason = {
1115
1224
  };
1116
1225
  } | {
1117
1226
  spool_refused: {
1118
- detail: string;
1227
+ cause: SpoolRefusalCause;
1228
+ message: string;
1119
1229
  };
1120
1230
  };
1121
1231
  /**
@@ -1128,6 +1238,16 @@ export interface Reported {
1128
1238
  /** One shape of the contracts, which say nothing more about it. */
1129
1239
  value: number;
1130
1240
  }
1241
+ /** The position a filament change charged up to, and how fresh it is. */
1242
+ export interface SignalPosition {
1243
+ /**
1244
+ * Whether it was read when the signal was handled, or is the last one
1245
+ * recorded before it.
1246
+ */
1247
+ freshness: PositionFreshness;
1248
+ /** The position. */
1249
+ position: FilePosition;
1250
+ }
1131
1251
  /** A spool's remaining figure was corrected. */
1132
1252
  export interface SpoolAdjustedPayload {
1133
1253
  /** Who corrected it. */
@@ -1223,8 +1343,25 @@ export interface SpoolCommandRejectedPayload {
1223
1343
  /** The whole decision, carrying which refusal it was. */
1224
1344
  decision: PolicyDecision;
1225
1345
  }
1346
+ /** One field of a spool command, as the command names it. */
1347
+ export type SpoolField = "name" | "material" | "diameter_mm" | "density_g_cm3" | "initial_g" | "remaining_g" | "tare_g" | "gross_g";
1226
1348
  /** A lowercase hyphenated version 7 UUID identifying one registered spool. */
1227
1349
  export type SpoolId = string;
1350
+ /**
1351
+ * Where a spool is in its life.
1352
+ *
1353
+ * One state rather than a loaded tool beside a retirement instant, because a
1354
+ * retired spool is on no tool: retiring a loaded spool takes it off.
1355
+ */
1356
+ export type SpoolLifecycle = {
1357
+ state: "shelved";
1358
+ } | {
1359
+ state: "loaded";
1360
+ tool: number;
1361
+ } | {
1362
+ state: "retired";
1363
+ at: Timestamp;
1364
+ };
1228
1365
  /** A spool was loaded onto a tool, or confirmed as never having left it. */
1229
1366
  export interface SpoolLoadedPayload {
1230
1367
  /** Who loaded it. */
@@ -1257,8 +1394,11 @@ export interface SpoolRecord {
1257
1394
  id: SpoolId;
1258
1395
  /** The net filament on the spool when it was full, in grams; above zero. */
1259
1396
  initial_g: number;
1260
- /** The tool the spool is loaded on, when it is loaded. */
1261
- loaded_on_tool?: number | null;
1397
+ /**
1398
+ * Where the spool is in its life: on the shelf, loaded on a tool, or
1399
+ * retired — and never both of the last two.
1400
+ */
1401
+ lifecycle: SpoolLifecycle;
1262
1402
  /** The material, as given and trimmed, such as `PLA`; never empty. */
1263
1403
  material: string;
1264
1404
  /** The operator's own label for the spool; never empty. */
@@ -1272,8 +1412,6 @@ export interface SpoolRecord {
1272
1412
  * charge is never refused or clamped, so this may go below zero.
1273
1413
  */
1274
1414
  remaining_g: number;
1275
- /** When the spool was retired, if it has been. */
1276
- retired_at?: Timestamp | null;
1277
1415
  /** The empty spool's own weight, in grams, when the operator gave it. */
1278
1416
  tare_g?: number | null;
1279
1417
  /** How far the remaining figure can be trusted. */
@@ -1281,6 +1419,45 @@ export interface SpoolRecord {
1281
1419
  /** When anything about the spool last changed. */
1282
1420
  updated_at: Timestamp;
1283
1421
  }
1422
+ /**
1423
+ * Why the spool ledger refused a command, each cause carrying what a client
1424
+ * needs to choose the next valid request.
1425
+ */
1426
+ export type SpoolRefusalCause = {
1427
+ cause: "unknown_spool";
1428
+ spool_id: SpoolId;
1429
+ } | {
1430
+ cause: "retired_spool";
1431
+ spool_id: SpoolId;
1432
+ } | {
1433
+ cause: "nothing_to_confirm";
1434
+ tool: number;
1435
+ } | {
1436
+ cause: "invalid_adjustment_figure";
1437
+ field: SpoolField;
1438
+ value: number;
1439
+ } | {
1440
+ cause: "tare_required";
1441
+ spool_id: SpoolId;
1442
+ } | {
1443
+ cause: "density_required";
1444
+ material: string;
1445
+ spool_id?: SpoolId | null;
1446
+ } | {
1447
+ cause: "missing_field";
1448
+ field: SpoolField;
1449
+ } | {
1450
+ cause: "conflicting_fields";
1451
+ fields: Array<SpoolField>;
1452
+ } | {
1453
+ cause: "unknown_tool";
1454
+ tool: number;
1455
+ } | {
1456
+ cause: "not_loaded";
1457
+ spool_id: SpoolId;
1458
+ } | {
1459
+ cause: "ledger_refused";
1460
+ };
1284
1461
  /** A spool was registered. */
1285
1462
  export interface SpoolRegisteredPayload {
1286
1463
  /** Who registered it. */
@@ -1578,6 +1755,14 @@ export declare class GeneratedClient extends GeneratedSurface {
1578
1755
  * said no.
1579
1756
  */
1580
1757
  history(printId: string, limit?: number): Promise<HistoryAnswer>;
1758
+ /**
1759
+ * Call `events` on the configured supervisor.
1760
+ *
1761
+ * Rejects with `Unreachable` when nothing answered, with `Unreadable` when
1762
+ * the answer could not be read, and with `Refused` when the supervisor
1763
+ * said no.
1764
+ */
1765
+ events(after?: string, printId?: string, kinds?: Array<string>, excludeKinds?: Array<string>, waitS?: number, limit?: number): Promise<EventsAnswer>;
1581
1766
  /**
1582
1767
  * Call `manifest_get` on the configured supervisor.
1583
1768
  *
package/dist/contract.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * generate-clients`, and commit what that writes.
8
8
  */
9
9
  import { GeneratedSurface, reasonGiven } from "./surface.js";
10
- export const CONTRACT_VERSION = "0.5.0";
10
+ export const CONTRACT_VERSION = "0.7.0";
11
11
  /**
12
12
  * Every operation this client exposes a method for, which is every operation
13
13
  * the server declares and no other.
@@ -18,6 +18,7 @@ export const OPERATION_NAMES = [
18
18
  "context",
19
19
  "image",
20
20
  "history",
21
+ "events",
21
22
  "manifest_get",
22
23
  "look",
23
24
  "manifest_set",
@@ -169,6 +170,42 @@ export class GeneratedClient extends GeneratedSurface {
169
170
  // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
170
171
  return await this.call("GET", target, asked, sending);
171
172
  }
173
+ /**
174
+ * Call `events` on the configured supervisor.
175
+ *
176
+ * Rejects with `Unreachable` when nothing answered, with `Unreadable` when
177
+ * the answer could not be read, and with `Refused` when the supervisor
178
+ * said no.
179
+ */
180
+ async events(after, printId, kinds, excludeKinds, waitS, limit) {
181
+ const target = `/v1/events`;
182
+ const asked = [];
183
+ if (after !== undefined) {
184
+ asked.push(["after", String(after)]);
185
+ }
186
+ if (printId !== undefined) {
187
+ asked.push(["print_id", String(printId)]);
188
+ }
189
+ if (kinds !== undefined) {
190
+ for (const value of kinds) {
191
+ asked.push(["kinds", String(value)]);
192
+ }
193
+ }
194
+ if (excludeKinds !== undefined) {
195
+ for (const value of excludeKinds) {
196
+ asked.push(["exclude_kinds", String(value)]);
197
+ }
198
+ }
199
+ if (waitS !== undefined) {
200
+ asked.push(["wait_s", String(waitS)]);
201
+ }
202
+ if (limit !== undefined) {
203
+ asked.push(["limit", String(limit)]);
204
+ }
205
+ const sending = undefined;
206
+ // llmlint: ignore[boundary_inputs_validated] See suppressions.toml.
207
+ return await this.call("GET", target, asked, sending);
208
+ }
172
209
  /**
173
210
  * Call `manifest_get` on the configured supervisor.
174
211
  *
package/package.json CHANGED
@@ -12,12 +12,12 @@
12
12
  "license": "MIT",
13
13
  "main": "dist/index.js",
14
14
  "name": "@printobserver/sdk",
15
- "printobserverContractVersion": "0.5.0",
15
+ "printobserverContractVersion": "0.7.0",
16
16
  "repository": {
17
17
  "type": "git",
18
18
  "url": "https://github.com/nickderobertis/printobserver"
19
19
  },
20
20
  "type": "module",
21
21
  "types": "dist/index.d.ts",
22
- "version": "0.5.0"
22
+ "version": "0.7.0"
23
23
  }