@granular-software/sdk 0.4.62 → 0.4.64

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
@@ -12219,8 +12219,12 @@ external_exports.union([
12219
12219
  external_exports.array(external_exports.string()),
12220
12220
  external_exports.object({
12221
12221
  values: external_exports.array(external_exports.string()),
12222
+ labels: external_exports.array(external_exports.string().min(1)).optional(),
12222
12223
  message: external_exports.string().optional()
12223
- }).strict()
12224
+ }).strict().refine(
12225
+ (rule) => !rule.labels || rule.labels.length === rule.values.length,
12226
+ { message: "Enum labels must match enum values one-for-one" }
12227
+ )
12224
12228
  ]);
12225
12229
  external_exports.union([
12226
12230
  external_exports.boolean(),
@@ -12248,7 +12252,7 @@ var StateMachineStateSchema = external_exports.union([
12248
12252
  external_exports.string(),
12249
12253
  external_exports.object({
12250
12254
  name: external_exports.string().min(1),
12251
- label: external_exports.string().optional(),
12255
+ label: external_exports.string().min(1).optional(),
12252
12256
  description: external_exports.string().optional(),
12253
12257
  isFinal: external_exports.boolean().optional()
12254
12258
  }).strict()
@@ -13142,7 +13146,7 @@ function resolveHandlerForMode(effectMap, effect, request) {
13142
13146
  if (mode === "artifactOptions") {
13143
13147
  if (!effect.artifactOptionsHandler) {
13144
13148
  throw new Error(
13145
- `Artifact relationship options are not supported for ${request.effectKey}`
13149
+ `Artifact field options are not supported for ${request.effectKey}`
13146
13150
  );
13147
13151
  }
13148
13152
  return {
@@ -13644,18 +13648,24 @@ function normalizeEnumInput(enumSpec) {
13644
13648
  (value) => typeof value === "string" && value.length > 0
13645
13649
  );
13646
13650
  if (values.length === 0) return null;
13647
- return config.message ? { values, message: config.message } : { values };
13651
+ const labels = Array.isArray(config.labels) && config.labels.length === values.length ? config.labels : values;
13652
+ return {
13653
+ values,
13654
+ labels,
13655
+ ...config.message ? { message: config.message } : {}
13656
+ };
13648
13657
  }
13649
13658
  function buildEnumFieldMutations(fieldPath, enumSpec) {
13650
13659
  const normalized = normalizeEnumInput(enumSpec);
13651
13660
  if (!normalized) return [];
13652
13661
  const messageArg = normalized.message ? `, message: ${JSON.stringify(normalized.message)}` : "";
13662
+ const labelsArg = normalized.labels ? `, labels: ${JSON.stringify(normalized.labels)}` : "";
13653
13663
  return [
13654
13664
  {
13655
13665
  label: `set enum on ${fieldPath}`,
13656
13666
  query: `mutation { at(path: ${JSON.stringify(fieldPath)}) { set_enum(values: ${JSON.stringify(
13657
13667
  normalized.values
13658
- )}${messageArg}) { values } } }`
13668
+ )}${labelsArg}${messageArg}) { values labels } } }`
13659
13669
  }
13660
13670
  ];
13661
13671
  }
@@ -13665,7 +13675,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13665
13675
  fieldRows: [
13666
13676
  {
13667
13677
  key: "enum",
13668
- description: 'Allowed values. Accepts `["a", "b"]` or `{ "values": [...], "message": "..." }`.'
13678
+ description: 'Allowed values. Use `{ "values": [...], "labels": [...] }` for authored display labels; otherwise each unchanged value is its display fallback.'
13669
13679
  }
13670
13680
  ]
13671
13681
  },
@@ -13675,6 +13685,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13675
13685
  type EnumMetamodel {
13676
13686
  model: Model!
13677
13687
  values: [String!]!
13688
+ labels: [String!]!
13678
13689
  message: String
13679
13690
  }
13680
13691
 
@@ -13683,7 +13694,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13683
13694
  }
13684
13695
 
13685
13696
  extend type ModelMutation {
13686
- set_enum(values: [String!]!, message: String): EnumMetamodel
13697
+ set_enum(values: [String!]!, labels: [String!], message: String): EnumMetamodel
13687
13698
  }
13688
13699
  `
13689
13700
  ],
@@ -13692,15 +13703,19 @@ var enumMetamodelPackage = defineMetamodelPackage({
13692
13703
  EnumMetamodel: {
13693
13704
  model: (value) => value.model,
13694
13705
  values: (value) => value.values,
13706
+ labels: (value) => value.labels || [],
13695
13707
  message: (value) => value.message || null
13696
13708
  },
13697
13709
  Model: {
13698
13710
  enum_rule: async (ant) => await run(ant.enum_rule())
13699
13711
  },
13700
13712
  ModelMutation: {
13701
- set_enum: async (ant, { values, message }) => {
13702
- const model = await run(ant.set_enum(values, message));
13703
- return { model, values, message };
13713
+ set_enum: async (ant, { values, labels, message }) => {
13714
+ const resolvedLabels = Array.isArray(labels) && labels.length === values.length ? labels : values;
13715
+ const model = await run(
13716
+ ant.set_enum(values, resolvedLabels, message)
13717
+ );
13718
+ return { model, values, labels: resolvedLabels, message };
13704
13719
  }
13705
13720
  }
13706
13721
  };
@@ -13713,7 +13728,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13713
13728
  },
13714
13729
  summary: {
13715
13730
  selections: {
13716
- propertyFields: [`enum_rule { values message }`]
13731
+ propertyFields: [`enum_rule { values labels message }`]
13717
13732
  },
13718
13733
  readPropertySummary(rawProperty) {
13719
13734
  const values = Array.isArray(rawProperty.enum_rule?.values) ? rawProperty.enum_rule.values.filter(
@@ -13721,8 +13736,15 @@ var enumMetamodelPackage = defineMetamodelPackage({
13721
13736
  ) : [];
13722
13737
  if (values.length === 0) return { enumRule: null };
13723
13738
  const message = typeof rawProperty.enum_rule?.message === "string" ? rawProperty.enum_rule.message : null;
13739
+ const labels = Array.isArray(rawProperty.enum_rule?.labels) ? rawProperty.enum_rule.labels.filter(
13740
+ (label) => typeof label === "string" && label.length > 0
13741
+ ) : [];
13724
13742
  return {
13725
- enumRule: message ? { values, message } : { values }
13743
+ enumRule: {
13744
+ values,
13745
+ ...labels.length === values.length ? { labels } : {},
13746
+ ...message ? { message } : {}
13747
+ }
13726
13748
  };
13727
13749
  }
13728
13750
  },
@@ -15353,7 +15375,6 @@ function buildEffectMetamodelMutations(toolPath, spec) {
15353
15375
  // src/client.ts
15354
15376
  var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
15355
15377
  var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
15356
- var MAX_CONVERSATION_SESSION_LIST_OFFSET = 1e5;
15357
15378
  function requireUserEnvironmentSequence(value, field) {
15358
15379
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
15359
15380
  throw new Error(
@@ -15733,6 +15754,10 @@ var Environment = class _Environment {
15733
15754
  get sessions() {
15734
15755
  return {
15735
15756
  list: async (options = {}) => this.listSessions(options),
15757
+ page: async (options = {}) => this.granular.listSessionsPage({
15758
+ ...options,
15759
+ environmentId: this.environmentId
15760
+ }),
15736
15761
  create: async (options) => this.createSession(options),
15737
15762
  connect: async (sessionId, options) => this.connectSession(sessionId, options),
15738
15763
  reopen: async (sessionId, options) => this.reopenSession(sessionId, options),
@@ -15988,7 +16013,6 @@ var Environment = class _Environment {
15988
16013
  headers: {
15989
16014
  Authorization: `Bearer ${this._apiKey}`,
15990
16015
  "Content-Type": "application/json",
15991
- Connection: "close",
15992
16016
  ...options.headers
15993
16017
  }
15994
16018
  });
@@ -17512,8 +17536,7 @@ var EnvironmentSession = class extends Session {
17512
17536
  method: "POST",
17513
17537
  headers: {
17514
17538
  "Content-Type": "application/json",
17515
- Authorization: `Bearer ${this.environment.authToken}`,
17516
- Connection: "close"
17539
+ Authorization: `Bearer ${this.environment.authToken}`
17517
17540
  },
17518
17541
  body: JSON.stringify({
17519
17542
  reason: "sdk_disconnect_http_fallback",
@@ -18215,6 +18238,21 @@ var Granular = class _Granular {
18215
18238
  * List indexed sessions using ownership filters and bounded pagination.
18216
18239
  */
18217
18240
  async listSessions(options) {
18241
+ const items = [];
18242
+ let cursor = options.cursor?.trim() || void 0;
18243
+ let pageCount = 0;
18244
+ do {
18245
+ const page = await this.listSessionsPage({ ...options, cursor });
18246
+ items.push(...page.items);
18247
+ cursor = page.nextCursor || void 0;
18248
+ pageCount += 1;
18249
+ if (pageCount > 1e4) {
18250
+ throw new Error("Session pagination exceeded the safe page limit");
18251
+ }
18252
+ } while (cursor);
18253
+ return items;
18254
+ }
18255
+ async listSessionsPage(options) {
18218
18256
  const environmentId = options.environmentId?.trim();
18219
18257
  const sandboxId = options.sandboxId?.trim();
18220
18258
  const subjectId = options.subjectId?.trim();
@@ -18242,17 +18280,14 @@ var Granular = class _Granular {
18242
18280
  1,
18243
18281
  MAX_CONVERSATION_SESSION_LIST_LIMIT
18244
18282
  );
18245
- const offset = boundedSessionListInteger(
18246
- options.offset,
18247
- "offset",
18248
- 0,
18249
- 0,
18250
- MAX_CONVERSATION_SESSION_LIST_OFFSET
18251
- );
18283
+ const cursor = options.cursor?.trim();
18284
+ if (options.cursor !== void 0 && !cursor) {
18285
+ throw new Error("Session list cursor must be a non-empty string.");
18286
+ }
18252
18287
  const query = new URLSearchParams({
18253
- limit: String(limit),
18254
- offset: String(offset)
18288
+ limit: String(limit)
18255
18289
  });
18290
+ if (cursor) query.set("cursor", cursor);
18256
18291
  if (environmentId) query.set("environmentId", environmentId);
18257
18292
  if (sandboxId) query.set("sandboxId", sandboxId);
18258
18293
  if (subjectId) query.set("userId", subjectId);
@@ -18260,11 +18295,13 @@ var Granular = class _Granular {
18260
18295
  query.set("sessionScope", options.sessionScope.trim());
18261
18296
  }
18262
18297
  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));
18298
+ const res = await this.request(`/control/sessions?${query.toString()}`);
18299
+ const items = Array.isArray(res.items) ? res.items.map((row) => this.normalizeConversationSession(row)) : [];
18300
+ const nextCursor = res.nextCursor ?? null;
18301
+ if (nextCursor === cursor) {
18302
+ throw new Error("Session pagination cursor did not advance");
18303
+ }
18304
+ return { items, nextCursor };
18268
18305
  }
18269
18306
  /**
18270
18307
  * List active (open) sessions for an environment.
@@ -18291,9 +18328,6 @@ var Granular = class _Granular {
18291
18328
  if (typeof options.limit === "number") {
18292
18329
  query.set("limit", String(options.limit));
18293
18330
  }
18294
- if (typeof options.offset === "number") {
18295
- query.set("offset", String(options.offset));
18296
- }
18297
18331
  const state = await this.request(
18298
18332
  `/sdk/user-environment-state?${query.toString()}`
18299
18333
  );
@@ -19227,10 +19261,20 @@ var Granular = class _Granular {
19227
19261
  get environments() {
19228
19262
  return {
19229
19263
  list: async (sandboxId) => {
19230
- const result = await this.request(
19231
- `/control/sandboxes/${sandboxId}/environments`
19232
- );
19233
- return result.items.map(normalizeEnvironmentData);
19264
+ const environments = [];
19265
+ let cursor = null;
19266
+ do {
19267
+ const query = cursor ? `?limit=100&cursor=${encodeURIComponent(cursor)}` : "";
19268
+ const result = await this.request(
19269
+ `/control/sandboxes/${sandboxId}/environments${query}`
19270
+ );
19271
+ environments.push(...result.items.map(normalizeEnvironmentData));
19272
+ if (result.nextCursor && result.nextCursor === cursor) {
19273
+ throw new Error("Environment pagination cursor did not advance");
19274
+ }
19275
+ cursor = result.nextCursor;
19276
+ } while (cursor);
19277
+ return environments;
19234
19278
  },
19235
19279
  get: async (environmentId) => {
19236
19280
  return normalizeEnvironmentData(
@@ -19440,7 +19484,6 @@ var Granular = class _Granular {
19440
19484
  headers: {
19441
19485
  Authorization: `Bearer ${this.apiKey}`,
19442
19486
  "Content-Type": "application/json",
19443
- Connection: "close",
19444
19487
  ...options.headers
19445
19488
  }
19446
19489
  });