@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.
@@ -15208,7 +15208,6 @@ function buildEffectMetamodelMutations(toolPath, spec) {
15208
15208
  // src/client.ts
15209
15209
  var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
15210
15210
  var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
15211
- var MAX_CONVERSATION_SESSION_LIST_OFFSET = 1e5;
15212
15211
  function requireUserEnvironmentSequence(value, field) {
15213
15212
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
15214
15213
  throw new Error(
@@ -15588,6 +15587,10 @@ var Environment = class _Environment {
15588
15587
  get sessions() {
15589
15588
  return {
15590
15589
  list: async (options = {}) => this.listSessions(options),
15590
+ page: async (options = {}) => this.granular.listSessionsPage({
15591
+ ...options,
15592
+ environmentId: this.environmentId
15593
+ }),
15591
15594
  create: async (options) => this.createSession(options),
15592
15595
  connect: async (sessionId, options) => this.connectSession(sessionId, options),
15593
15596
  reopen: async (sessionId, options) => this.reopenSession(sessionId, options),
@@ -15843,7 +15846,6 @@ var Environment = class _Environment {
15843
15846
  headers: {
15844
15847
  Authorization: `Bearer ${this._apiKey}`,
15845
15848
  "Content-Type": "application/json",
15846
- Connection: "close",
15847
15849
  ...options.headers
15848
15850
  }
15849
15851
  });
@@ -17367,8 +17369,7 @@ var EnvironmentSession = class extends Session {
17367
17369
  method: "POST",
17368
17370
  headers: {
17369
17371
  "Content-Type": "application/json",
17370
- Authorization: `Bearer ${this.environment.authToken}`,
17371
- Connection: "close"
17372
+ Authorization: `Bearer ${this.environment.authToken}`
17372
17373
  },
17373
17374
  body: JSON.stringify({
17374
17375
  reason: "sdk_disconnect_http_fallback",
@@ -18070,6 +18071,21 @@ var Granular = class _Granular {
18070
18071
  * List indexed sessions using ownership filters and bounded pagination.
18071
18072
  */
18072
18073
  async listSessions(options) {
18074
+ const items = [];
18075
+ let cursor = options.cursor?.trim() || void 0;
18076
+ let pageCount = 0;
18077
+ do {
18078
+ const page = await this.listSessionsPage({ ...options, cursor });
18079
+ items.push(...page.items);
18080
+ cursor = page.nextCursor || void 0;
18081
+ pageCount += 1;
18082
+ if (pageCount > 1e4) {
18083
+ throw new Error("Session pagination exceeded the safe page limit");
18084
+ }
18085
+ } while (cursor);
18086
+ return items;
18087
+ }
18088
+ async listSessionsPage(options) {
18073
18089
  const environmentId = options.environmentId?.trim();
18074
18090
  const sandboxId = options.sandboxId?.trim();
18075
18091
  const subjectId = options.subjectId?.trim();
@@ -18097,17 +18113,14 @@ var Granular = class _Granular {
18097
18113
  1,
18098
18114
  MAX_CONVERSATION_SESSION_LIST_LIMIT
18099
18115
  );
18100
- const offset = boundedSessionListInteger(
18101
- options.offset,
18102
- "offset",
18103
- 0,
18104
- 0,
18105
- MAX_CONVERSATION_SESSION_LIST_OFFSET
18106
- );
18116
+ const cursor = options.cursor?.trim();
18117
+ if (options.cursor !== void 0 && !cursor) {
18118
+ throw new Error("Session list cursor must be a non-empty string.");
18119
+ }
18107
18120
  const query = new URLSearchParams({
18108
- limit: String(limit),
18109
- offset: String(offset)
18121
+ limit: String(limit)
18110
18122
  });
18123
+ if (cursor) query.set("cursor", cursor);
18111
18124
  if (environmentId) query.set("environmentId", environmentId);
18112
18125
  if (sandboxId) query.set("sandboxId", sandboxId);
18113
18126
  if (subjectId) query.set("userId", subjectId);
@@ -18115,11 +18128,13 @@ var Granular = class _Granular {
18115
18128
  query.set("sessionScope", options.sessionScope.trim());
18116
18129
  }
18117
18130
  if (status !== "all") query.set("status", status);
18118
- const res = await this.request(
18119
- `/control/sessions?${query.toString()}`
18120
- );
18121
- const items = Array.isArray(res.items) ? res.items : [];
18122
- return items.map((row) => this.normalizeConversationSession(row));
18131
+ const res = await this.request(`/control/sessions?${query.toString()}`);
18132
+ const items = Array.isArray(res.items) ? res.items.map((row) => this.normalizeConversationSession(row)) : [];
18133
+ const nextCursor = res.nextCursor ?? null;
18134
+ if (nextCursor === cursor) {
18135
+ throw new Error("Session pagination cursor did not advance");
18136
+ }
18137
+ return { items, nextCursor };
18123
18138
  }
18124
18139
  /**
18125
18140
  * List active (open) sessions for an environment.
@@ -18146,9 +18161,6 @@ var Granular = class _Granular {
18146
18161
  if (typeof options.limit === "number") {
18147
18162
  query.set("limit", String(options.limit));
18148
18163
  }
18149
- if (typeof options.offset === "number") {
18150
- query.set("offset", String(options.offset));
18151
- }
18152
18164
  const state = await this.request(
18153
18165
  `/sdk/user-environment-state?${query.toString()}`
18154
18166
  );
@@ -19082,10 +19094,20 @@ var Granular = class _Granular {
19082
19094
  get environments() {
19083
19095
  return {
19084
19096
  list: async (sandboxId) => {
19085
- const result = await this.request(
19086
- `/control/sandboxes/${sandboxId}/environments`
19087
- );
19088
- return result.items.map(normalizeEnvironmentData);
19097
+ const environments = [];
19098
+ let cursor = null;
19099
+ do {
19100
+ const query = cursor ? `?limit=100&cursor=${encodeURIComponent(cursor)}` : "";
19101
+ const result = await this.request(
19102
+ `/control/sandboxes/${sandboxId}/environments${query}`
19103
+ );
19104
+ environments.push(...result.items.map(normalizeEnvironmentData));
19105
+ if (result.nextCursor && result.nextCursor === cursor) {
19106
+ throw new Error("Environment pagination cursor did not advance");
19107
+ }
19108
+ cursor = result.nextCursor;
19109
+ } while (cursor);
19110
+ return environments;
19089
19111
  },
19090
19112
  get: async (environmentId) => {
19091
19113
  return normalizeEnvironmentData(
@@ -19295,7 +19317,6 @@ var Granular = class _Granular {
19295
19317
  headers: {
19296
19318
  Authorization: `Bearer ${this.apiKey}`,
19297
19319
  "Content-Type": "application/json",
19298
- Connection: "close",
19299
19320
  ...options.headers
19300
19321
  }
19301
19322
  });