@tscircuit/core 0.0.209 → 0.0.210

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.
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ declare abstract class Renderable implements IRenderable {
40
40
  private _asyncEffects;
41
41
  constructor(props: any);
42
42
  protected _markDirty(phase: RenderPhase): void;
43
- protected _queueAsyncEffect(effect: () => Promise<void>): void;
43
+ protected _queueAsyncEffect(effectName: string, effect: () => Promise<void>): void;
44
44
  protected _emitRenderLifecycleEvent(phase: RenderPhase, eventType: "start" | "end"): void;
45
45
  getString(): string;
46
46
  _hasIncompleteAsyncEffects(): boolean;
@@ -930,14 +930,17 @@ declare class Board extends Group<typeof boardProps> {
930
930
  autorouter: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
931
931
  serverUrl: z.ZodOptional<z.ZodString>;
932
932
  inputFormat: z.ZodOptional<z.ZodEnum<["simplified", "circuit-json"]>>;
933
+ serverMode: z.ZodOptional<z.ZodEnum<["job", "solve-endpoint"]>>;
933
934
  cache: z.ZodOptional<z.ZodType<_tscircuit_props.PcbRouteCache, z.ZodTypeDef, _tscircuit_props.PcbRouteCache>>;
934
935
  }, "strip", z.ZodTypeAny, {
935
936
  serverUrl?: string | undefined;
936
937
  inputFormat?: "simplified" | "circuit-json" | undefined;
938
+ serverMode?: "job" | "solve-endpoint" | undefined;
937
939
  cache?: _tscircuit_props.PcbRouteCache | undefined;
938
940
  }, {
939
941
  serverUrl?: string | undefined;
940
942
  inputFormat?: "simplified" | "circuit-json" | undefined;
943
+ serverMode?: "job" | "solve-endpoint" | undefined;
941
944
  cache?: _tscircuit_props.PcbRouteCache | undefined;
942
945
  }>, z.ZodLiteral<"sequential-trace">, z.ZodLiteral<"subcircuit">, z.ZodLiteral<"auto">, z.ZodLiteral<"auto-local">, z.ZodLiteral<"auto-cloud">]>>;
943
946
  }>, {
@@ -975,6 +978,7 @@ declare class Board extends Group<typeof boardProps> {
975
978
  autorouter?: "sequential-trace" | "subcircuit" | "auto" | "auto-local" | "auto-cloud" | {
976
979
  serverUrl?: string | undefined;
977
980
  inputFormat?: "simplified" | "circuit-json" | undefined;
981
+ serverMode?: "job" | "solve-endpoint" | undefined;
978
982
  cache?: _tscircuit_props.PcbRouteCache | undefined;
979
983
  } | undefined;
980
984
  schAutoLayoutEnabled?: boolean | undefined;
@@ -1007,6 +1011,7 @@ declare class Board extends Group<typeof boardProps> {
1007
1011
  autorouter?: "sequential-trace" | "subcircuit" | "auto" | "auto-local" | "auto-cloud" | {
1008
1012
  serverUrl?: string | undefined;
1009
1013
  inputFormat?: "simplified" | "circuit-json" | undefined;
1014
+ serverMode?: "job" | "solve-endpoint" | undefined;
1010
1015
  cache?: _tscircuit_props.PcbRouteCache | undefined;
1011
1016
  } | undefined;
1012
1017
  schAutoLayoutEnabled?: boolean | undefined;
package/dist/index.js CHANGED
@@ -114,11 +114,12 @@ var Renderable = class {
114
114
  this.renderPhaseStates[orderedRenderPhases[i]].dirty = true;
115
115
  }
116
116
  }
117
- _queueAsyncEffect(effect) {
117
+ _queueAsyncEffect(effectName, effect) {
118
118
  const asyncEffect = {
119
119
  promise: effect(),
120
120
  // TODO don't start effects until end of render cycle
121
121
  phase: this._currentRenderPhase,
122
+ effectName,
122
123
  complete: false
123
124
  };
124
125
  this._asyncEffects.push(asyncEffect);
@@ -127,18 +128,24 @@ var Renderable = class {
127
128
  if ("root" in this && this.root) {
128
129
  ;
129
130
  this.root.emit("asyncEffectComplete", {
130
- component: this,
131
- asyncEffect
131
+ effectName,
132
+ componentDisplayName: this.getString(),
133
+ phase: asyncEffect.phase
132
134
  });
133
135
  }
134
136
  }).catch((error) => {
135
- console.error(`Async effect error in ${asyncEffect.phase}:`, error);
137
+ console.error(
138
+ `Async effect error in ${asyncEffect.phase} "${effectName}":
139
+ ${error.stack}`
140
+ );
136
141
  asyncEffect.complete = true;
137
142
  if ("root" in this && this.root) {
138
143
  ;
139
144
  this.root.emit("asyncEffectComplete", {
140
- component: this,
141
- asyncEffect
145
+ effectName,
146
+ componentDisplayName: this.getString(),
147
+ phase: asyncEffect.phase,
148
+ error: error.toString()
142
149
  });
143
150
  }
144
151
  });
@@ -3214,7 +3221,7 @@ var NormalComponent = class extends PrimitiveComponent {
3214
3221
  });
3215
3222
  return;
3216
3223
  }
3217
- this._queueAsyncEffect(async () => {
3224
+ this._queueAsyncEffect("get-supplier-part-numbers", async () => {
3218
3225
  this._asyncSupplierPartNumbers = await supplierPartNumbersMaybePromise;
3219
3226
  this._markDirty("PartsEngineRender");
3220
3227
  });
@@ -3363,6 +3370,7 @@ var getSimpleRouteJsonFromTracesAndDb = ({
3363
3370
  };
3364
3371
 
3365
3372
  // lib/components/primitive-components/Group/Group.ts
3373
+ import Debug4 from "debug";
3366
3374
  var Group = class extends NormalComponent {
3367
3375
  _asyncAutoroutingResult = null;
3368
3376
  get config() {
@@ -3427,42 +3435,80 @@ var Group = class extends NormalComponent {
3427
3435
  }
3428
3436
  doInitialPcbTraceRender() {
3429
3437
  if (this._shouldUseTraceByTraceRouting()) return;
3430
- let serverUrl = this.props.autorouter?.serverUrl;
3431
- if (this.props.autorouter === "auto-cloud") {
3432
- serverUrl = "https://registry-api.tscircuit.com/autorouting/solve";
3433
- }
3434
- if (serverUrl) {
3435
- this._queueAsyncEffect(async () => {
3438
+ const serverUrl = this.props.autorouter?.serverUrl ?? "https://registry-api.tscircuit.com";
3439
+ const serverMode = this.props.autorouter?.serverMode ?? "job";
3440
+ const debug3 = Debug4("tscircuit:core:autorouting");
3441
+ const fetchWithDebug = (url, options) => {
3442
+ debug3("fetching", url);
3443
+ return fetch(url, options);
3444
+ };
3445
+ this._queueAsyncEffect("make-http-autorouting-request", async () => {
3446
+ if (serverMode === "solve-endpoint") {
3436
3447
  if (this.props.autorouter?.inputFormat === "simplified") {
3437
- const { autorouting_result: autorouting_result2 } = await fetch(serverUrl, {
3438
- method: "POST",
3439
- body: JSON.stringify({
3440
- input_simple_route_json: this._getSimpleRouteJsonFromPcbTraces()
3441
- }),
3442
- headers: {
3443
- "Content-Type": "application/json"
3448
+ const { autorouting_result: autorouting_result2 } = await fetchWithDebug(
3449
+ `${serverUrl}/autorouting/solve`,
3450
+ {
3451
+ method: "POST",
3452
+ body: JSON.stringify({
3453
+ input_simple_route_json: this._getSimpleRouteJsonFromPcbTraces()
3454
+ }),
3455
+ headers: { "Content-Type": "application/json" }
3444
3456
  }
3445
- }).then((r) => r.json());
3457
+ ).then((r) => r.json());
3446
3458
  this._asyncAutoroutingResult = autorouting_result2;
3447
3459
  this._markDirty("PcbTraceRender");
3460
+ return;
3448
3461
  }
3449
- const arRes = await fetch(serverUrl, {
3450
- method: "POST",
3451
- body: JSON.stringify({
3452
- // TODO filter such that we're only using this subcircuit's
3453
- // components
3454
- input_circuit_json: this.root.db.toArray()
3455
- }),
3456
- headers: {
3457
- "Content-Type": "application/json"
3462
+ const { autorouting_result } = await fetchWithDebug(
3463
+ `${serverUrl}/autorouting/solve`,
3464
+ {
3465
+ method: "POST",
3466
+ body: JSON.stringify({
3467
+ input_circuit_json: this.root.db.toArray()
3468
+ }),
3469
+ headers: { "Content-Type": "application/json" }
3458
3470
  }
3459
- });
3460
- const resultText = await arRes.text();
3461
- const { autorouting_result } = JSON.parse(resultText);
3471
+ ).then((r) => r.json());
3462
3472
  this._asyncAutoroutingResult = autorouting_result;
3463
3473
  this._markDirty("PcbTraceRender");
3464
- });
3465
- }
3474
+ return;
3475
+ }
3476
+ const { autorouting_job } = await fetchWithDebug(
3477
+ `${serverUrl}/autorouting/jobs/create`,
3478
+ {
3479
+ method: "POST",
3480
+ body: JSON.stringify({
3481
+ input_circuit_json: this.root.db.toArray(),
3482
+ provider: "freerouting",
3483
+ autostart: true
3484
+ }),
3485
+ headers: { "Content-Type": "application/json" }
3486
+ }
3487
+ ).then((r) => r.json());
3488
+ while (true) {
3489
+ const { autorouting_job: job } = await fetchWithDebug(
3490
+ `${serverUrl}/autorouting/jobs/get?autorouting_job_id=${autorouting_job.autorouting_job_id}`,
3491
+ { method: "POST" }
3492
+ ).then((r) => r.json());
3493
+ if (job.is_finished) {
3494
+ const { autorouting_job_output } = await fetchWithDebug(
3495
+ `${serverUrl}/autorouting/jobs/get_output?autorouting_job_id=${autorouting_job.autorouting_job_id}`,
3496
+ { method: "POST" }
3497
+ ).then((r) => r.json());
3498
+ this._asyncAutoroutingResult = {
3499
+ output_pcb_traces: autorouting_job_output.output_pcb_traces
3500
+ };
3501
+ this._markDirty("PcbTraceRender");
3502
+ break;
3503
+ }
3504
+ if (job.has_error) {
3505
+ throw new Error(
3506
+ `Autorouting job failed: ${JSON.stringify(job.error)}`
3507
+ );
3508
+ }
3509
+ await new Promise((resolve) => setTimeout(resolve, 100));
3510
+ }
3511
+ });
3466
3512
  }
3467
3513
  updatePcbTraceRender() {
3468
3514
  if (!this._asyncAutoroutingResult) return;
@@ -3532,7 +3578,10 @@ var Group = class extends NormalComponent {
3532
3578
  * or if using a "fullview" or "rip and replace" autorouting mode
3533
3579
  */
3534
3580
  _shouldUseTraceByTraceRouting() {
3535
- if (this.props.autorouter) return false;
3581
+ const props = this._parsedProps;
3582
+ if (props.autorouter === "auto-local") return true;
3583
+ if (props.autorouter === "sequential-trace") return true;
3584
+ if (props.autorouter) return false;
3536
3585
  return true;
3537
3586
  }
3538
3587
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.209",
4
+ "version": "0.0.210",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -41,11 +41,11 @@
41
41
  "@tscircuit/footprinter": "^0.0.89",
42
42
  "@tscircuit/infgrid-ijump-astar": "^0.0.24",
43
43
  "@tscircuit/math-utils": "^0.0.5",
44
- "circuit-json": "^0.0.108",
45
- "circuit-json-to-connectivity-map": "^0.0.17",
46
- "@tscircuit/props": "^0.0.106",
44
+ "@tscircuit/props": "^0.0.107",
47
45
  "@tscircuit/schematic-autolayout": "^0.0.6",
48
46
  "@tscircuit/soup-util": "^0.0.41",
47
+ "circuit-json": "^0.0.108",
48
+ "circuit-json-to-connectivity-map": "^0.0.17",
49
49
  "circuit-to-svg": "0.0.84",
50
50
  "format-si-unit": "^0.0.2",
51
51
  "nanoid": "^5.0.7",