@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/cli/index.js +5567 -305
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -3928,6 +3928,12 @@ var READY_STATE_OPEN = 1;
|
|
|
3928
3928
|
var TOKEN_REFRESH_LEEWAY_MS = 2 * 60 * 1e3;
|
|
3929
3929
|
var TOKEN_REFRESH_RETRY_MS = 30 * 1e3;
|
|
3930
3930
|
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
3931
|
+
var DEBUG_WS = process.env.GRANULAR_DEBUG_WS === "1";
|
|
3932
|
+
function debugWs(...args) {
|
|
3933
|
+
if (DEBUG_WS) {
|
|
3934
|
+
console.log(...args);
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3931
3937
|
var WSClient = class {
|
|
3932
3938
|
ws = null;
|
|
3933
3939
|
url;
|
|
@@ -4227,7 +4233,7 @@ var WSClient = class {
|
|
|
4227
4233
|
}
|
|
4228
4234
|
handleMessage(message) {
|
|
4229
4235
|
if (typeof message !== "object" || message === null) return;
|
|
4230
|
-
|
|
4236
|
+
debugWs("[Granular DEBUG] Received message:", JSON.stringify(message).slice(0, 500));
|
|
4231
4237
|
if ("type" in message && message.type === "sync") {
|
|
4232
4238
|
const syncMessage = message;
|
|
4233
4239
|
let bytes;
|
|
@@ -4247,7 +4253,7 @@ var WSClient = class {
|
|
|
4247
4253
|
} else {
|
|
4248
4254
|
return;
|
|
4249
4255
|
}
|
|
4250
|
-
|
|
4256
|
+
debugWs("[Granular DEBUG] Applying sync bytes:", bytes.length);
|
|
4251
4257
|
const [newDoc, newSyncState] = Automerge.receiveSyncMessage(
|
|
4252
4258
|
this.doc,
|
|
4253
4259
|
this.syncState,
|
|
@@ -4257,19 +4263,19 @@ var WSClient = class {
|
|
|
4257
4263
|
this.syncState = newSyncState;
|
|
4258
4264
|
const docAny = this.doc;
|
|
4259
4265
|
if (docAny.catalog) {
|
|
4260
|
-
|
|
4261
|
-
|
|
4266
|
+
debugWs("[Granular DEBUG] Doc catalog sync applied. Keys in catalog:", Object.keys(docAny.catalog || {}));
|
|
4267
|
+
debugWs("[Granular DEBUG] RawToolCatalogs:", Object.keys(docAny.catalog.rawToolCatalogs || {}));
|
|
4262
4268
|
} else {
|
|
4263
|
-
|
|
4269
|
+
debugWs("[Granular DEBUG] Doc synced but no catalog yet. Keys in doc:", Object.keys(docAny));
|
|
4264
4270
|
}
|
|
4265
4271
|
this.emit("sync", this.doc);
|
|
4266
4272
|
} catch (e) {
|
|
4267
4273
|
try {
|
|
4268
|
-
|
|
4274
|
+
debugWs("[Granular DEBUG] receiveSyncMessage failed, trying applyChanges...");
|
|
4269
4275
|
const [newDoc] = Automerge.applyChanges(this.doc, [bytes]);
|
|
4270
4276
|
this.doc = newDoc;
|
|
4271
4277
|
this.emit("sync", this.doc);
|
|
4272
|
-
|
|
4278
|
+
debugWs("[Granular DEBUG] applyChanges succeeded. Doc:", JSON.stringify(Automerge.toJS(this.doc)));
|
|
4273
4279
|
} catch (applyError) {
|
|
4274
4280
|
console.warn("[Granular] Failed to apply sync message (both sync & applyChanges)", e, applyError);
|
|
4275
4281
|
}
|
|
@@ -4280,10 +4286,10 @@ var WSClient = class {
|
|
|
4280
4286
|
const snapshotMessage = message;
|
|
4281
4287
|
try {
|
|
4282
4288
|
const bytes = new Uint8Array(snapshotMessage.data);
|
|
4283
|
-
|
|
4289
|
+
debugWs("[Granular DEBUG] Loading Automerge session snapshot bytes:", bytes.length);
|
|
4284
4290
|
this.doc = Automerge.load(bytes);
|
|
4285
4291
|
this.emit("sync", this.doc);
|
|
4286
|
-
|
|
4292
|
+
debugWs("[Granular DEBUG] Automerge session snapshot loaded. Doc:", JSON.stringify(Automerge.toJS(this.doc)));
|
|
4287
4293
|
} catch (e) {
|
|
4288
4294
|
console.warn("[Granular] Failed to load snapshot message", e);
|
|
4289
4295
|
}
|
|
@@ -11321,6 +11327,7 @@ var Environment = class extends Session {
|
|
|
11321
11327
|
headers: {
|
|
11322
11328
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
11323
11329
|
"Content-Type": "application/json",
|
|
11330
|
+
"Connection": "close",
|
|
11324
11331
|
...options.headers
|
|
11325
11332
|
}
|
|
11326
11333
|
});
|
|
@@ -11355,7 +11362,8 @@ var Environment = class extends Session {
|
|
|
11355
11362
|
method: "POST",
|
|
11356
11363
|
headers: {
|
|
11357
11364
|
"Content-Type": "application/json",
|
|
11358
|
-
"Authorization": `Bearer ${this._apiKey}
|
|
11365
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
11366
|
+
"Connection": "close"
|
|
11359
11367
|
},
|
|
11360
11368
|
body: JSON.stringify({
|
|
11361
11369
|
reason: "sdk_disconnect_http_fallback",
|
|
@@ -12218,6 +12226,7 @@ var Granular = class _Granular {
|
|
|
12218
12226
|
WebSocketCtor;
|
|
12219
12227
|
onUnexpectedClose;
|
|
12220
12228
|
onReconnectError;
|
|
12229
|
+
debugHttp = process.env.GRANULAR_DEBUG_HTTP === "1";
|
|
12221
12230
|
/** Sandbox-level effect registry: sandboxId → (effectKey → ToolWithHandler) */
|
|
12222
12231
|
sandboxEffects = /* @__PURE__ */ new Map();
|
|
12223
12232
|
/** Live sandbox-scoped effect hosts keyed by sandboxId */
|
|
@@ -13086,12 +13095,15 @@ var Granular = class _Granular {
|
|
|
13086
13095
|
*/
|
|
13087
13096
|
async request(path, options = {}) {
|
|
13088
13097
|
const url = `${this.httpUrl}${path}`;
|
|
13089
|
-
|
|
13098
|
+
if (this.debugHttp) {
|
|
13099
|
+
console.log(`[SDK] Requesting: ${url}`);
|
|
13100
|
+
}
|
|
13090
13101
|
const response = await fetch(url, {
|
|
13091
13102
|
...options,
|
|
13092
13103
|
headers: {
|
|
13093
13104
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
13094
13105
|
"Content-Type": "application/json",
|
|
13106
|
+
"Connection": "close",
|
|
13095
13107
|
...options.headers
|
|
13096
13108
|
}
|
|
13097
13109
|
});
|