@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.d.mts CHANGED
@@ -884,6 +884,7 @@ declare class Session {
884
884
  /** Last known tools for diffing */
885
885
  private lastKnownTools;
886
886
  constructor(client: WSClient, clientId?: string);
887
+ private extractDomainRevisionFromDoc;
887
888
  private buildLegacyEffectContext;
888
889
  get document(): Doc<Record<string, unknown>>;
889
890
  get domainRevision(): string | null;
package/dist/index.d.ts CHANGED
@@ -884,6 +884,7 @@ declare class Session {
884
884
  /** Last known tools for diffing */
885
885
  private lastKnownTools;
886
886
  constructor(client: WSClient, clientId?: string);
887
+ private extractDomainRevisionFromDoc;
887
888
  private buildLegacyEffectContext;
888
889
  get document(): Doc<Record<string, unknown>>;
889
890
  get domainRevision(): string | null;
package/dist/index.js CHANGED
@@ -4496,6 +4496,18 @@ var Session = class {
4496
4496
  this.setupEventHandlers();
4497
4497
  this.setupToolInvokeHandler();
4498
4498
  }
4499
+ extractDomainRevisionFromDoc(doc) {
4500
+ const domain = doc?.domain;
4501
+ const active = domain?.active;
4502
+ if (typeof active === "string" && active.trim()) {
4503
+ return active;
4504
+ }
4505
+ const nestedRevision = active?.domainRevision;
4506
+ if (typeof nestedRevision === "string" && nestedRevision.trim()) {
4507
+ return nestedRevision;
4508
+ }
4509
+ return null;
4510
+ }
4499
4511
  buildLegacyEffectContext() {
4500
4512
  return {
4501
4513
  effectClientId: this.clientId,
@@ -4590,7 +4602,14 @@ var Session = class {
4590
4602
  * execute locally and return the result to the sandbox.
4591
4603
  */
4592
4604
  async submitJob(code, domainRevision) {
4593
- const revision = domainRevision || this.currentDomainRevision || this.client.doc?.domain?.active || void 0;
4605
+ let revision = domainRevision || this.currentDomainRevision || this.extractDomainRevisionFromDoc(this.client.doc) || void 0;
4606
+ if (!revision) {
4607
+ try {
4608
+ const summary = await this.getDomain();
4609
+ revision = summary.activeDomainRevision || this.extractDomainRevisionFromDoc(this.client.doc) || void 0;
4610
+ } catch {
4611
+ }
4612
+ }
4594
4613
  if (!revision) {
4595
4614
  throw new Error("No domain revision available. Register live effects or ensure the build schema is activated.");
4596
4615
  }
@@ -4715,7 +4734,13 @@ var Session = class {
4715
4734
  * Get the current domain state and available tools
4716
4735
  */
4717
4736
  async getDomain() {
4718
- return this.client.call("domain.getSummary", {});
4737
+ const summary = await this.client.call("domain.getSummary", {});
4738
+ if (summary.activeDomainRevision) {
4739
+ this.currentDomainRevision = summary.activeDomainRevision;
4740
+ } else {
4741
+ this.currentDomainRevision = this.extractDomainRevisionFromDoc(this.client.doc);
4742
+ }
4743
+ return summary;
4719
4744
  }
4720
4745
  /**
4721
4746
  * Fetch a domain package part from the backend (no fallback).
@@ -4933,6 +4958,7 @@ import { ${allImports} } from "./sandbox-tools";
4933
4958
  }
4934
4959
  setupEventHandlers() {
4935
4960
  this.client.on("sync", (doc) => {
4961
+ this.currentDomainRevision = this.extractDomainRevisionFromDoc(doc);
4936
4962
  this.emit("sync", doc);
4937
4963
  this.checkForToolChanges();
4938
4964
  });