@granular-software/sdk 0.4.17 → 0.4.18

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
@@ -1739,6 +1739,7 @@ declare class Granular {
1739
1739
  private WebSocketCtor?;
1740
1740
  private onUnexpectedClose?;
1741
1741
  private onReconnectError?;
1742
+ private debugHttp;
1742
1743
  /** Sandbox-level effect registry: sandboxId → (effectKey → ToolWithHandler) */
1743
1744
  private sandboxEffects;
1744
1745
  /** Live sandbox-scoped effect hosts keyed by sandboxId */
package/dist/index.d.ts CHANGED
@@ -1739,6 +1739,7 @@ declare class Granular {
1739
1739
  private WebSocketCtor?;
1740
1740
  private onUnexpectedClose?;
1741
1741
  private onReconnectError?;
1742
+ private debugHttp;
1742
1743
  /** Sandbox-level effect registry: sandboxId → (effectKey → ToolWithHandler) */
1743
1744
  private sandboxEffects;
1744
1745
  /** Live sandbox-scoped effect hosts keyed by sandboxId */
package/dist/index.js CHANGED
@@ -3950,6 +3950,12 @@ var READY_STATE_OPEN = 1;
3950
3950
  var TOKEN_REFRESH_LEEWAY_MS = 2 * 60 * 1e3;
3951
3951
  var TOKEN_REFRESH_RETRY_MS = 30 * 1e3;
3952
3952
  var MAX_TIMER_DELAY_MS = 2147483647;
3953
+ var DEBUG_WS = process.env.GRANULAR_DEBUG_WS === "1";
3954
+ function debugWs(...args) {
3955
+ if (DEBUG_WS) {
3956
+ console.log(...args);
3957
+ }
3958
+ }
3953
3959
  var WSClient = class {
3954
3960
  ws = null;
3955
3961
  url;
@@ -4249,7 +4255,7 @@ var WSClient = class {
4249
4255
  }
4250
4256
  handleMessage(message) {
4251
4257
  if (typeof message !== "object" || message === null) return;
4252
- console.log("[Granular DEBUG] Received message:", JSON.stringify(message).slice(0, 500));
4258
+ debugWs("[Granular DEBUG] Received message:", JSON.stringify(message).slice(0, 500));
4253
4259
  if ("type" in message && message.type === "sync") {
4254
4260
  const syncMessage = message;
4255
4261
  let bytes;
@@ -4269,7 +4275,7 @@ var WSClient = class {
4269
4275
  } else {
4270
4276
  return;
4271
4277
  }
4272
- console.log("[Granular DEBUG] Applying sync bytes:", bytes.length);
4278
+ debugWs("[Granular DEBUG] Applying sync bytes:", bytes.length);
4273
4279
  const [newDoc, newSyncState] = Automerge__namespace.receiveSyncMessage(
4274
4280
  this.doc,
4275
4281
  this.syncState,
@@ -4279,19 +4285,19 @@ var WSClient = class {
4279
4285
  this.syncState = newSyncState;
4280
4286
  const docAny = this.doc;
4281
4287
  if (docAny.catalog) {
4282
- console.log("[Granular DEBUG] Doc catalog sync applied. Keys in catalog:", Object.keys(docAny.catalog || {}));
4283
- console.log("[Granular DEBUG] RawToolCatalogs:", Object.keys(docAny.catalog.rawToolCatalogs || {}));
4288
+ debugWs("[Granular DEBUG] Doc catalog sync applied. Keys in catalog:", Object.keys(docAny.catalog || {}));
4289
+ debugWs("[Granular DEBUG] RawToolCatalogs:", Object.keys(docAny.catalog.rawToolCatalogs || {}));
4284
4290
  } else {
4285
- console.log("[Granular DEBUG] Doc synced but no catalog yet. Keys in doc:", Object.keys(docAny));
4291
+ debugWs("[Granular DEBUG] Doc synced but no catalog yet. Keys in doc:", Object.keys(docAny));
4286
4292
  }
4287
4293
  this.emit("sync", this.doc);
4288
4294
  } catch (e) {
4289
4295
  try {
4290
- console.log("[Granular DEBUG] receiveSyncMessage failed, trying applyChanges...");
4296
+ debugWs("[Granular DEBUG] receiveSyncMessage failed, trying applyChanges...");
4291
4297
  const [newDoc] = Automerge__namespace.applyChanges(this.doc, [bytes]);
4292
4298
  this.doc = newDoc;
4293
4299
  this.emit("sync", this.doc);
4294
- console.log("[Granular DEBUG] applyChanges succeeded. Doc:", JSON.stringify(Automerge__namespace.toJS(this.doc)));
4300
+ debugWs("[Granular DEBUG] applyChanges succeeded. Doc:", JSON.stringify(Automerge__namespace.toJS(this.doc)));
4295
4301
  } catch (applyError) {
4296
4302
  console.warn("[Granular] Failed to apply sync message (both sync & applyChanges)", e, applyError);
4297
4303
  }
@@ -4302,10 +4308,10 @@ var WSClient = class {
4302
4308
  const snapshotMessage = message;
4303
4309
  try {
4304
4310
  const bytes = new Uint8Array(snapshotMessage.data);
4305
- console.log("[Granular DEBUG] Loading Automerge session snapshot bytes:", bytes.length);
4311
+ debugWs("[Granular DEBUG] Loading Automerge session snapshot bytes:", bytes.length);
4306
4312
  this.doc = Automerge__namespace.load(bytes);
4307
4313
  this.emit("sync", this.doc);
4308
- console.log("[Granular DEBUG] Automerge session snapshot loaded. Doc:", JSON.stringify(Automerge__namespace.toJS(this.doc)));
4314
+ debugWs("[Granular DEBUG] Automerge session snapshot loaded. Doc:", JSON.stringify(Automerge__namespace.toJS(this.doc)));
4309
4315
  } catch (e) {
4310
4316
  console.warn("[Granular] Failed to load snapshot message", e);
4311
4317
  }
@@ -11343,6 +11349,7 @@ var Environment = class extends Session {
11343
11349
  headers: {
11344
11350
  "Authorization": `Bearer ${this._apiKey}`,
11345
11351
  "Content-Type": "application/json",
11352
+ "Connection": "close",
11346
11353
  ...options.headers
11347
11354
  }
11348
11355
  });
@@ -11377,7 +11384,8 @@ var Environment = class extends Session {
11377
11384
  method: "POST",
11378
11385
  headers: {
11379
11386
  "Content-Type": "application/json",
11380
- "Authorization": `Bearer ${this._apiKey}`
11387
+ "Authorization": `Bearer ${this._apiKey}`,
11388
+ "Connection": "close"
11381
11389
  },
11382
11390
  body: JSON.stringify({
11383
11391
  reason: "sdk_disconnect_http_fallback",
@@ -12240,6 +12248,7 @@ var Granular = class _Granular {
12240
12248
  WebSocketCtor;
12241
12249
  onUnexpectedClose;
12242
12250
  onReconnectError;
12251
+ debugHttp = process.env.GRANULAR_DEBUG_HTTP === "1";
12243
12252
  /** Sandbox-level effect registry: sandboxId → (effectKey → ToolWithHandler) */
12244
12253
  sandboxEffects = /* @__PURE__ */ new Map();
12245
12254
  /** Live sandbox-scoped effect hosts keyed by sandboxId */
@@ -13108,12 +13117,15 @@ var Granular = class _Granular {
13108
13117
  */
13109
13118
  async request(path, options = {}) {
13110
13119
  const url = `${this.httpUrl}${path}`;
13111
- console.log(`[SDK] Requesting: ${url}`);
13120
+ if (this.debugHttp) {
13121
+ console.log(`[SDK] Requesting: ${url}`);
13122
+ }
13112
13123
  const response = await fetch(url, {
13113
13124
  ...options,
13114
13125
  headers: {
13115
13126
  "Authorization": `Bearer ${this.apiKey}`,
13116
13127
  "Content-Type": "application/json",
13128
+ "Connection": "close",
13117
13129
  ...options.headers
13118
13130
  }
13119
13131
  });