@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.mjs CHANGED
@@ -15331,7 +15331,6 @@ function buildEffectMetamodelMutations(toolPath, spec) {
15331
15331
  // src/client.ts
15332
15332
  var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
15333
15333
  var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
15334
- var MAX_CONVERSATION_SESSION_LIST_OFFSET = 1e5;
15335
15334
  function requireUserEnvironmentSequence(value, field) {
15336
15335
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
15337
15336
  throw new Error(
@@ -15711,6 +15710,10 @@ var Environment = class _Environment {
15711
15710
  get sessions() {
15712
15711
  return {
15713
15712
  list: async (options = {}) => this.listSessions(options),
15713
+ page: async (options = {}) => this.granular.listSessionsPage({
15714
+ ...options,
15715
+ environmentId: this.environmentId
15716
+ }),
15714
15717
  create: async (options) => this.createSession(options),
15715
15718
  connect: async (sessionId, options) => this.connectSession(sessionId, options),
15716
15719
  reopen: async (sessionId, options) => this.reopenSession(sessionId, options),
@@ -15966,7 +15969,6 @@ var Environment = class _Environment {
15966
15969
  headers: {
15967
15970
  Authorization: `Bearer ${this._apiKey}`,
15968
15971
  "Content-Type": "application/json",
15969
- Connection: "close",
15970
15972
  ...options.headers
15971
15973
  }
15972
15974
  });
@@ -17490,8 +17492,7 @@ var EnvironmentSession = class extends Session {
17490
17492
  method: "POST",
17491
17493
  headers: {
17492
17494
  "Content-Type": "application/json",
17493
- Authorization: `Bearer ${this.environment.authToken}`,
17494
- Connection: "close"
17495
+ Authorization: `Bearer ${this.environment.authToken}`
17495
17496
  },
17496
17497
  body: JSON.stringify({
17497
17498
  reason: "sdk_disconnect_http_fallback",
@@ -18193,6 +18194,21 @@ var Granular = class _Granular {
18193
18194
  * List indexed sessions using ownership filters and bounded pagination.
18194
18195
  */
18195
18196
  async listSessions(options) {
18197
+ const items = [];
18198
+ let cursor = options.cursor?.trim() || void 0;
18199
+ let pageCount = 0;
18200
+ do {
18201
+ const page = await this.listSessionsPage({ ...options, cursor });
18202
+ items.push(...page.items);
18203
+ cursor = page.nextCursor || void 0;
18204
+ pageCount += 1;
18205
+ if (pageCount > 1e4) {
18206
+ throw new Error("Session pagination exceeded the safe page limit");
18207
+ }
18208
+ } while (cursor);
18209
+ return items;
18210
+ }
18211
+ async listSessionsPage(options) {
18196
18212
  const environmentId = options.environmentId?.trim();
18197
18213
  const sandboxId = options.sandboxId?.trim();
18198
18214
  const subjectId = options.subjectId?.trim();
@@ -18220,17 +18236,14 @@ var Granular = class _Granular {
18220
18236
  1,
18221
18237
  MAX_CONVERSATION_SESSION_LIST_LIMIT
18222
18238
  );
18223
- const offset = boundedSessionListInteger(
18224
- options.offset,
18225
- "offset",
18226
- 0,
18227
- 0,
18228
- MAX_CONVERSATION_SESSION_LIST_OFFSET
18229
- );
18239
+ const cursor = options.cursor?.trim();
18240
+ if (options.cursor !== void 0 && !cursor) {
18241
+ throw new Error("Session list cursor must be a non-empty string.");
18242
+ }
18230
18243
  const query = new URLSearchParams({
18231
- limit: String(limit),
18232
- offset: String(offset)
18244
+ limit: String(limit)
18233
18245
  });
18246
+ if (cursor) query.set("cursor", cursor);
18234
18247
  if (environmentId) query.set("environmentId", environmentId);
18235
18248
  if (sandboxId) query.set("sandboxId", sandboxId);
18236
18249
  if (subjectId) query.set("userId", subjectId);
@@ -18238,11 +18251,13 @@ var Granular = class _Granular {
18238
18251
  query.set("sessionScope", options.sessionScope.trim());
18239
18252
  }
18240
18253
  if (status !== "all") query.set("status", status);
18241
- const res = await this.request(
18242
- `/control/sessions?${query.toString()}`
18243
- );
18244
- const items = Array.isArray(res.items) ? res.items : [];
18245
- return items.map((row) => this.normalizeConversationSession(row));
18254
+ const res = await this.request(`/control/sessions?${query.toString()}`);
18255
+ const items = Array.isArray(res.items) ? res.items.map((row) => this.normalizeConversationSession(row)) : [];
18256
+ const nextCursor = res.nextCursor ?? null;
18257
+ if (nextCursor === cursor) {
18258
+ throw new Error("Session pagination cursor did not advance");
18259
+ }
18260
+ return { items, nextCursor };
18246
18261
  }
18247
18262
  /**
18248
18263
  * List active (open) sessions for an environment.
@@ -18269,9 +18284,6 @@ var Granular = class _Granular {
18269
18284
  if (typeof options.limit === "number") {
18270
18285
  query.set("limit", String(options.limit));
18271
18286
  }
18272
- if (typeof options.offset === "number") {
18273
- query.set("offset", String(options.offset));
18274
- }
18275
18287
  const state = await this.request(
18276
18288
  `/sdk/user-environment-state?${query.toString()}`
18277
18289
  );
@@ -19205,10 +19217,20 @@ var Granular = class _Granular {
19205
19217
  get environments() {
19206
19218
  return {
19207
19219
  list: async (sandboxId) => {
19208
- const result = await this.request(
19209
- `/control/sandboxes/${sandboxId}/environments`
19210
- );
19211
- return result.items.map(normalizeEnvironmentData);
19220
+ const environments = [];
19221
+ let cursor = null;
19222
+ do {
19223
+ const query = cursor ? `?limit=100&cursor=${encodeURIComponent(cursor)}` : "";
19224
+ const result = await this.request(
19225
+ `/control/sandboxes/${sandboxId}/environments${query}`
19226
+ );
19227
+ environments.push(...result.items.map(normalizeEnvironmentData));
19228
+ if (result.nextCursor && result.nextCursor === cursor) {
19229
+ throw new Error("Environment pagination cursor did not advance");
19230
+ }
19231
+ cursor = result.nextCursor;
19232
+ } while (cursor);
19233
+ return environments;
19212
19234
  },
19213
19235
  get: async (environmentId) => {
19214
19236
  return normalizeEnvironmentData(
@@ -19418,7 +19440,6 @@ var Granular = class _Granular {
19418
19440
  headers: {
19419
19441
  Authorization: `Bearer ${this.apiKey}`,
19420
19442
  "Content-Type": "application/json",
19421
- Connection: "close",
19422
19443
  ...options.headers
19423
19444
  }
19424
19445
  });