@tscircuit/core 0.0.276 → 0.0.277

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
@@ -45,8 +45,9 @@ declare abstract class Renderable implements IRenderable {
45
45
  _renderId: string;
46
46
  _currentRenderPhase: RenderPhase | null;
47
47
  private _asyncEffects;
48
+ parent: Renderable | null;
48
49
  constructor(props: any);
49
- protected _markDirty(phase: RenderPhase): void;
50
+ _markDirty(phase: RenderPhase): void;
50
51
  protected _queueAsyncEffect(effectName: string, effect: () => Promise<void>): void;
51
52
  protected _emitRenderLifecycleEvent(phase: RenderPhase, startOrEnd: "start" | "end"): void;
52
53
  getString(): string;
@@ -928,6 +929,7 @@ interface SimpleRouteJson {
928
929
  declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps> extends NormalComponent<Props> implements ISubcircuit {
929
930
  pcb_group_id: string | null;
930
931
  subcircuit_id: string | null;
932
+ _hasStartedAsyncAutorouting: boolean;
931
933
  _asyncAutoroutingResult: {
932
934
  output_simple_route_json?: SimpleRouteJson;
933
935
  output_pcb_traces?: PcbTrace[];
@@ -941,6 +943,10 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
941
943
  doInitialCreateTraceHintsFromProps(): void;
942
944
  _getSimpleRouteJsonFromPcbTraces(): SimpleRouteJson;
943
945
  doInitialSourceAddConnectivityMapKey(): void;
946
+ _areChildSubcircuitsRouted(): boolean;
947
+ _shouldRouteAsync(): boolean;
948
+ _runEffectMakeHttpAutoroutingRequest(): Promise<void>;
949
+ _startAsyncAutorouting(): void;
944
950
  doInitialPcbTraceRender(): void;
945
951
  updatePcbTraceRender(): void;
946
952
  _updatePcbTraceRenderFromSimpleRouteJson(): void;
package/dist/index.js CHANGED
@@ -105,6 +105,7 @@ var Renderable = class {
105
105
  _renderId;
106
106
  _currentRenderPhase = null;
107
107
  _asyncEffects = [];
108
+ parent = null;
108
109
  constructor(props) {
109
110
  this._renderId = `${globalRenderCounter++}`;
110
111
  this.children = [];
@@ -122,6 +123,9 @@ var Renderable = class {
122
123
  for (let i = phaseIndex + 1; i < orderedRenderPhases.length; i++) {
123
124
  this.renderPhaseStates[orderedRenderPhases[i]].dirty = true;
124
125
  }
126
+ if (this.parent?._markDirty) {
127
+ this.parent._markDirty(phase);
128
+ }
125
129
  }
126
130
  _queueAsyncEffect(effectName, effect) {
127
131
  const asyncEffect = {
@@ -3620,6 +3624,7 @@ var TraceHint = class extends PrimitiveComponent {
3620
3624
  var Group = class extends NormalComponent {
3621
3625
  pcb_group_id = null;
3622
3626
  subcircuit_id = null;
3627
+ _hasStartedAsyncAutorouting = false;
3623
3628
  _asyncAutoroutingResult = null;
3624
3629
  get config() {
3625
3630
  return {
@@ -3709,63 +3714,91 @@ var Group = class extends NormalComponent {
3709
3714
  });
3710
3715
  }
3711
3716
  }
3712
- doInitialPcbTraceRender() {
3713
- if (this.root?.pcbDisabled) return;
3714
- if (this._shouldUseTraceByTraceRouting()) return;
3715
- const serverUrl = this.props.autorouter?.serverUrl ?? "https://registry-api.tscircuit.com";
3716
- const serverMode = this.props.autorouter?.serverMode ?? "job";
3717
- const debug4 = Debug5("tscircuit:core:autorouting");
3717
+ _areChildSubcircuitsRouted() {
3718
+ const subcircuitChildren = this.selectAll("group").filter(
3719
+ (g) => g.isSubcircuit
3720
+ );
3721
+ for (const subcircuitChild of subcircuitChildren) {
3722
+ if (subcircuitChild._shouldRouteAsync() && !subcircuitChild._asyncAutoroutingResult) {
3723
+ return false;
3724
+ }
3725
+ }
3726
+ return true;
3727
+ }
3728
+ _shouldRouteAsync() {
3729
+ const props = this._parsedProps;
3730
+ if (props.autorouter === "auto-local") return true;
3731
+ if (props.autorouter === "auto-cloud") return true;
3732
+ if (props.autorouter === "sequential-trace") return false;
3733
+ if (typeof props.autorouter === "object") return true;
3734
+ return false;
3735
+ }
3736
+ async _runEffectMakeHttpAutoroutingRequest() {
3737
+ const debug4 = Debug5("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");
3738
+ const props = this._parsedProps;
3739
+ const serverUrl = props.autorouter?.serverUrl ?? "https://registry-api.tscircuit.com";
3740
+ const serverMode = props.autorouter?.serverMode ?? "job";
3718
3741
  const fetchWithDebug = (url, options) => {
3719
3742
  debug4("fetching", url);
3720
3743
  return fetch(url, options);
3721
3744
  };
3722
- this._queueAsyncEffect("make-http-autorouting-request", async () => {
3723
- if (serverMode === "solve-endpoint") {
3724
- if (this.props.autorouter?.inputFormat === "simplified") {
3725
- const { autorouting_result: autorouting_result2 } = await fetchWithDebug(
3726
- `${serverUrl}/autorouting/solve`,
3727
- {
3728
- method: "POST",
3729
- body: JSON.stringify({
3730
- input_simple_route_json: this._getSimpleRouteJsonFromPcbTraces()
3731
- }),
3732
- headers: { "Content-Type": "application/json" }
3733
- }
3734
- ).then((r) => r.json());
3735
- this._asyncAutoroutingResult = autorouting_result2;
3736
- this._markDirty("PcbTraceRender");
3737
- return;
3738
- }
3739
- const { autorouting_result } = await fetchWithDebug(
3745
+ if (serverMode === "solve-endpoint") {
3746
+ if (this.props.autorouter?.inputFormat === "simplified") {
3747
+ const { autorouting_result: autorouting_result2 } = await fetchWithDebug(
3740
3748
  `${serverUrl}/autorouting/solve`,
3741
3749
  {
3742
3750
  method: "POST",
3743
3751
  body: JSON.stringify({
3744
- input_circuit_json: this.root.db.toArray()
3752
+ input_simple_route_json: this._getSimpleRouteJsonFromPcbTraces()
3745
3753
  }),
3746
3754
  headers: { "Content-Type": "application/json" }
3747
3755
  }
3748
3756
  ).then((r) => r.json());
3749
- this._asyncAutoroutingResult = autorouting_result;
3757
+ this._asyncAutoroutingResult = autorouting_result2;
3750
3758
  this._markDirty("PcbTraceRender");
3751
3759
  return;
3752
3760
  }
3753
- const { autorouting_job } = await fetchWithDebug(
3754
- `${serverUrl}/autorouting/jobs/create`,
3761
+ const { autorouting_result } = await fetchWithDebug(
3762
+ `${serverUrl}/autorouting/solve`,
3763
+ {
3764
+ method: "POST",
3765
+ body: JSON.stringify({
3766
+ input_circuit_json: this.root.db.toArray()
3767
+ }),
3768
+ headers: { "Content-Type": "application/json" }
3769
+ }
3770
+ ).then((r) => r.json());
3771
+ this._asyncAutoroutingResult = autorouting_result;
3772
+ this._markDirty("PcbTraceRender");
3773
+ return;
3774
+ }
3775
+ const { autorouting_job } = await fetchWithDebug(
3776
+ `${serverUrl}/autorouting/jobs/create`,
3777
+ {
3778
+ method: "POST",
3779
+ body: JSON.stringify({
3780
+ input_circuit_json: this.root.db.toArray(),
3781
+ provider: "freerouting",
3782
+ autostart: true,
3783
+ display_name: this.root?.name
3784
+ }),
3785
+ headers: { "Content-Type": "application/json" }
3786
+ }
3787
+ ).then((r) => r.json());
3788
+ while (true) {
3789
+ const { autorouting_job: job } = await fetchWithDebug(
3790
+ `${serverUrl}/autorouting/jobs/get`,
3755
3791
  {
3756
3792
  method: "POST",
3757
3793
  body: JSON.stringify({
3758
- input_circuit_json: this.root.db.toArray(),
3759
- provider: "freerouting",
3760
- autostart: true,
3761
- display_name: this.root?.name
3794
+ autorouting_job_id: autorouting_job.autorouting_job_id
3762
3795
  }),
3763
3796
  headers: { "Content-Type": "application/json" }
3764
3797
  }
3765
3798
  ).then((r) => r.json());
3766
- while (true) {
3767
- const { autorouting_job: job } = await fetchWithDebug(
3768
- `${serverUrl}/autorouting/jobs/get`,
3799
+ if (job.is_finished) {
3800
+ const { autorouting_job_output } = await fetchWithDebug(
3801
+ `${serverUrl}/autorouting/jobs/get_output`,
3769
3802
  {
3770
3803
  method: "POST",
3771
3804
  body: JSON.stringify({
@@ -3774,33 +3807,51 @@ var Group = class extends NormalComponent {
3774
3807
  headers: { "Content-Type": "application/json" }
3775
3808
  }
3776
3809
  ).then((r) => r.json());
3777
- if (job.is_finished) {
3778
- const { autorouting_job_output } = await fetchWithDebug(
3779
- `${serverUrl}/autorouting/jobs/get_output`,
3780
- {
3781
- method: "POST",
3782
- body: JSON.stringify({
3783
- autorouting_job_id: autorouting_job.autorouting_job_id
3784
- }),
3785
- headers: { "Content-Type": "application/json" }
3786
- }
3787
- ).then((r) => r.json());
3788
- this._asyncAutoroutingResult = {
3789
- output_pcb_traces: autorouting_job_output.output_pcb_traces
3790
- };
3791
- this._markDirty("PcbTraceRender");
3792
- break;
3793
- }
3794
- if (job.has_error) {
3795
- throw new Error(
3796
- `Autorouting job failed: ${JSON.stringify(job.error)}`
3797
- );
3798
- }
3799
- await new Promise((resolve) => setTimeout(resolve, 100));
3810
+ this._asyncAutoroutingResult = {
3811
+ output_pcb_traces: autorouting_job_output.output_pcb_traces
3812
+ };
3813
+ this._markDirty("PcbTraceRender");
3814
+ break;
3800
3815
  }
3801
- });
3816
+ if (job.has_error) {
3817
+ throw new Error(`Autorouting job failed: ${JSON.stringify(job.error)}`);
3818
+ }
3819
+ await new Promise((resolve) => setTimeout(resolve, 100));
3820
+ }
3821
+ }
3822
+ _startAsyncAutorouting() {
3823
+ this._hasStartedAsyncAutorouting = true;
3824
+ this._queueAsyncEffect(
3825
+ "make-http-autorouting-request",
3826
+ async () => this._runEffectMakeHttpAutoroutingRequest()
3827
+ );
3828
+ }
3829
+ doInitialPcbTraceRender() {
3830
+ const debug4 = Debug5("tscircuit:core:doInitialPcbTraceRender");
3831
+ if (this.root?.pcbDisabled) return;
3832
+ if (this._shouldUseTraceByTraceRouting()) return;
3833
+ if (!this._areChildSubcircuitsRouted()) {
3834
+ debug4(
3835
+ `[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`
3836
+ );
3837
+ return;
3838
+ }
3839
+ debug4(
3840
+ `[${this.getString()}] no child subcircuits to wait for, initiating async routing`
3841
+ );
3842
+ this._startAsyncAutorouting();
3802
3843
  }
3803
3844
  updatePcbTraceRender() {
3845
+ const debug4 = Debug5("tscircuit:core:updatePcbTraceRender");
3846
+ if (this._shouldRouteAsync() && !this._hasStartedAsyncAutorouting) {
3847
+ if (this._areChildSubcircuitsRouted()) {
3848
+ debug4(
3849
+ `[${this.getString()}] child subcircuits are now routed, starting async autorouting`
3850
+ );
3851
+ this._startAsyncAutorouting();
3852
+ }
3853
+ return;
3854
+ }
3804
3855
  if (!this._asyncAutoroutingResult) return;
3805
3856
  if (this._shouldUseTraceByTraceRouting()) return;
3806
3857
  const { db } = this.root;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.276",
4
+ "version": "0.0.277",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",