@granular-software/sdk 0.4.62 → 0.4.63

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.js CHANGED
@@ -15353,7 +15353,6 @@ function buildEffectMetamodelMutations(toolPath, spec) {
15353
15353
  // src/client.ts
15354
15354
  var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
15355
15355
  var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
15356
- var MAX_CONVERSATION_SESSION_LIST_OFFSET = 1e5;
15357
15356
  function requireUserEnvironmentSequence(value, field) {
15358
15357
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
15359
15358
  throw new Error(
@@ -15733,6 +15732,10 @@ var Environment = class _Environment {
15733
15732
  get sessions() {
15734
15733
  return {
15735
15734
  list: async (options = {}) => this.listSessions(options),
15735
+ page: async (options = {}) => this.granular.listSessionsPage({
15736
+ ...options,
15737
+ environmentId: this.environmentId
15738
+ }),
15736
15739
  create: async (options) => this.createSession(options),
15737
15740
  connect: async (sessionId, options) => this.connectSession(sessionId, options),
15738
15741
  reopen: async (sessionId, options) => this.reopenSession(sessionId, options),
@@ -15988,7 +15991,6 @@ var Environment = class _Environment {
15988
15991
  headers: {
15989
15992
  Authorization: `Bearer ${this._apiKey}`,
15990
15993
  "Content-Type": "application/json",
15991
- Connection: "close",
15992
15994
  ...options.headers
15993
15995
  }
15994
15996
  });
@@ -17512,8 +17514,7 @@ var EnvironmentSession = class extends Session {
17512
17514
  method: "POST",
17513
17515
  headers: {
17514
17516
  "Content-Type": "application/json",
17515
- Authorization: `Bearer ${this.environment.authToken}`,
17516
- Connection: "close"
17517
+ Authorization: `Bearer ${this.environment.authToken}`
17517
17518
  },
17518
17519
  body: JSON.stringify({
17519
17520
  reason: "sdk_disconnect_http_fallback",
@@ -18215,6 +18216,21 @@ var Granular = class _Granular {
18215
18216
  * List indexed sessions using ownership filters and bounded pagination.
18216
18217
  */
18217
18218
  async listSessions(options) {
18219
+ const items = [];
18220
+ let cursor = options.cursor?.trim() || void 0;
18221
+ let pageCount = 0;
18222
+ do {
18223
+ const page = await this.listSessionsPage({ ...options, cursor });
18224
+ items.push(...page.items);
18225
+ cursor = page.nextCursor || void 0;
18226
+ pageCount += 1;
18227
+ if (pageCount > 1e4) {
18228
+ throw new Error("Session pagination exceeded the safe page limit");
18229
+ }
18230
+ } while (cursor);
18231
+ return items;
18232
+ }
18233
+ async listSessionsPage(options) {
18218
18234
  const environmentId = options.environmentId?.trim();
18219
18235
  const sandboxId = options.sandboxId?.trim();
18220
18236
  const subjectId = options.subjectId?.trim();
@@ -18242,17 +18258,14 @@ var Granular = class _Granular {
18242
18258
  1,
18243
18259
  MAX_CONVERSATION_SESSION_LIST_LIMIT
18244
18260
  );
18245
- const offset = boundedSessionListInteger(
18246
- options.offset,
18247
- "offset",
18248
- 0,
18249
- 0,
18250
- MAX_CONVERSATION_SESSION_LIST_OFFSET
18251
- );
18261
+ const cursor = options.cursor?.trim();
18262
+ if (options.cursor !== void 0 && !cursor) {
18263
+ throw new Error("Session list cursor must be a non-empty string.");
18264
+ }
18252
18265
  const query = new URLSearchParams({
18253
- limit: String(limit),
18254
- offset: String(offset)
18266
+ limit: String(limit)
18255
18267
  });
18268
+ if (cursor) query.set("cursor", cursor);
18256
18269
  if (environmentId) query.set("environmentId", environmentId);
18257
18270
  if (sandboxId) query.set("sandboxId", sandboxId);
18258
18271
  if (subjectId) query.set("userId", subjectId);
@@ -18260,11 +18273,13 @@ var Granular = class _Granular {
18260
18273
  query.set("sessionScope", options.sessionScope.trim());
18261
18274
  }
18262
18275
  if (status !== "all") query.set("status", status);
18263
- const res = await this.request(
18264
- `/control/sessions?${query.toString()}`
18265
- );
18266
- const items = Array.isArray(res.items) ? res.items : [];
18267
- return items.map((row) => this.normalizeConversationSession(row));
18276
+ const res = await this.request(`/control/sessions?${query.toString()}`);
18277
+ const items = Array.isArray(res.items) ? res.items.map((row) => this.normalizeConversationSession(row)) : [];
18278
+ const nextCursor = res.nextCursor ?? null;
18279
+ if (nextCursor === cursor) {
18280
+ throw new Error("Session pagination cursor did not advance");
18281
+ }
18282
+ return { items, nextCursor };
18268
18283
  }
18269
18284
  /**
18270
18285
  * List active (open) sessions for an environment.
@@ -18291,9 +18306,6 @@ var Granular = class _Granular {
18291
18306
  if (typeof options.limit === "number") {
18292
18307
  query.set("limit", String(options.limit));
18293
18308
  }
18294
- if (typeof options.offset === "number") {
18295
- query.set("offset", String(options.offset));
18296
- }
18297
18309
  const state = await this.request(
18298
18310
  `/sdk/user-environment-state?${query.toString()}`
18299
18311
  );
@@ -19227,10 +19239,20 @@ var Granular = class _Granular {
19227
19239
  get environments() {
19228
19240
  return {
19229
19241
  list: async (sandboxId) => {
19230
- const result = await this.request(
19231
- `/control/sandboxes/${sandboxId}/environments`
19232
- );
19233
- return result.items.map(normalizeEnvironmentData);
19242
+ const environments = [];
19243
+ let cursor = null;
19244
+ do {
19245
+ const query = cursor ? `?limit=100&cursor=${encodeURIComponent(cursor)}` : "";
19246
+ const result = await this.request(
19247
+ `/control/sandboxes/${sandboxId}/environments${query}`
19248
+ );
19249
+ environments.push(...result.items.map(normalizeEnvironmentData));
19250
+ if (result.nextCursor && result.nextCursor === cursor) {
19251
+ throw new Error("Environment pagination cursor did not advance");
19252
+ }
19253
+ cursor = result.nextCursor;
19254
+ } while (cursor);
19255
+ return environments;
19234
19256
  },
19235
19257
  get: async (environmentId) => {
19236
19258
  return normalizeEnvironmentData(
@@ -19440,7 +19462,6 @@ var Granular = class _Granular {
19440
19462
  headers: {
19441
19463
  Authorization: `Bearer ${this.apiKey}`,
19442
19464
  "Content-Type": "application/json",
19443
- Connection: "close",
19444
19465
  ...options.headers
19445
19466
  }
19446
19467
  });