@granular-software/sdk 0.4.7 → 0.4.8

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.mjs CHANGED
@@ -4474,6 +4474,18 @@ var Session = class {
4474
4474
  this.setupEventHandlers();
4475
4475
  this.setupToolInvokeHandler();
4476
4476
  }
4477
+ extractDomainRevisionFromDoc(doc) {
4478
+ const domain = doc?.domain;
4479
+ const active = domain?.active;
4480
+ if (typeof active === "string" && active.trim()) {
4481
+ return active;
4482
+ }
4483
+ const nestedRevision = active?.domainRevision;
4484
+ if (typeof nestedRevision === "string" && nestedRevision.trim()) {
4485
+ return nestedRevision;
4486
+ }
4487
+ return null;
4488
+ }
4477
4489
  buildLegacyEffectContext() {
4478
4490
  return {
4479
4491
  effectClientId: this.clientId,
@@ -4568,7 +4580,14 @@ var Session = class {
4568
4580
  * execute locally and return the result to the sandbox.
4569
4581
  */
4570
4582
  async submitJob(code, domainRevision) {
4571
- const revision = domainRevision || this.currentDomainRevision || this.client.doc?.domain?.active || void 0;
4583
+ let revision = domainRevision || this.currentDomainRevision || this.extractDomainRevisionFromDoc(this.client.doc) || void 0;
4584
+ if (!revision) {
4585
+ try {
4586
+ const summary = await this.getDomain();
4587
+ revision = summary.activeDomainRevision || this.extractDomainRevisionFromDoc(this.client.doc) || void 0;
4588
+ } catch {
4589
+ }
4590
+ }
4572
4591
  if (!revision) {
4573
4592
  throw new Error("No domain revision available. Register live effects or ensure the build schema is activated.");
4574
4593
  }
@@ -4693,7 +4712,13 @@ var Session = class {
4693
4712
  * Get the current domain state and available tools
4694
4713
  */
4695
4714
  async getDomain() {
4696
- return this.client.call("domain.getSummary", {});
4715
+ const summary = await this.client.call("domain.getSummary", {});
4716
+ if (summary.activeDomainRevision) {
4717
+ this.currentDomainRevision = summary.activeDomainRevision;
4718
+ } else {
4719
+ this.currentDomainRevision = this.extractDomainRevisionFromDoc(this.client.doc);
4720
+ }
4721
+ return summary;
4697
4722
  }
4698
4723
  /**
4699
4724
  * Fetch a domain package part from the backend (no fallback).
@@ -4911,6 +4936,7 @@ import { ${allImports} } from "./sandbox-tools";
4911
4936
  }
4912
4937
  setupEventHandlers() {
4913
4938
  this.client.on("sync", (doc) => {
4939
+ this.currentDomainRevision = this.extractDomainRevisionFromDoc(doc);
4914
4940
  this.emit("sync", doc);
4915
4941
  this.checkForToolChanges();
4916
4942
  });