@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.mjs CHANGED
@@ -12197,8 +12197,12 @@ external_exports.union([
12197
12197
  external_exports.array(external_exports.string()),
12198
12198
  external_exports.object({
12199
12199
  values: external_exports.array(external_exports.string()),
12200
+ labels: external_exports.array(external_exports.string().min(1)).optional(),
12200
12201
  message: external_exports.string().optional()
12201
- }).strict()
12202
+ }).strict().refine(
12203
+ (rule) => !rule.labels || rule.labels.length === rule.values.length,
12204
+ { message: "Enum labels must match enum values one-for-one" }
12205
+ )
12202
12206
  ]);
12203
12207
  external_exports.union([
12204
12208
  external_exports.boolean(),
@@ -12226,7 +12230,7 @@ var StateMachineStateSchema = external_exports.union([
12226
12230
  external_exports.string(),
12227
12231
  external_exports.object({
12228
12232
  name: external_exports.string().min(1),
12229
- label: external_exports.string().optional(),
12233
+ label: external_exports.string().min(1).optional(),
12230
12234
  description: external_exports.string().optional(),
12231
12235
  isFinal: external_exports.boolean().optional()
12232
12236
  }).strict()
@@ -13120,7 +13124,7 @@ function resolveHandlerForMode(effectMap, effect, request) {
13120
13124
  if (mode === "artifactOptions") {
13121
13125
  if (!effect.artifactOptionsHandler) {
13122
13126
  throw new Error(
13123
- `Artifact relationship options are not supported for ${request.effectKey}`
13127
+ `Artifact field options are not supported for ${request.effectKey}`
13124
13128
  );
13125
13129
  }
13126
13130
  return {
@@ -13622,18 +13626,24 @@ function normalizeEnumInput(enumSpec) {
13622
13626
  (value) => typeof value === "string" && value.length > 0
13623
13627
  );
13624
13628
  if (values.length === 0) return null;
13625
- return config.message ? { values, message: config.message } : { values };
13629
+ const labels = Array.isArray(config.labels) && config.labels.length === values.length ? config.labels : values;
13630
+ return {
13631
+ values,
13632
+ labels,
13633
+ ...config.message ? { message: config.message } : {}
13634
+ };
13626
13635
  }
13627
13636
  function buildEnumFieldMutations(fieldPath, enumSpec) {
13628
13637
  const normalized = normalizeEnumInput(enumSpec);
13629
13638
  if (!normalized) return [];
13630
13639
  const messageArg = normalized.message ? `, message: ${JSON.stringify(normalized.message)}` : "";
13640
+ const labelsArg = normalized.labels ? `, labels: ${JSON.stringify(normalized.labels)}` : "";
13631
13641
  return [
13632
13642
  {
13633
13643
  label: `set enum on ${fieldPath}`,
13634
13644
  query: `mutation { at(path: ${JSON.stringify(fieldPath)}) { set_enum(values: ${JSON.stringify(
13635
13645
  normalized.values
13636
- )}${messageArg}) { values } } }`
13646
+ )}${labelsArg}${messageArg}) { values labels } } }`
13637
13647
  }
13638
13648
  ];
13639
13649
  }
@@ -13643,7 +13653,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13643
13653
  fieldRows: [
13644
13654
  {
13645
13655
  key: "enum",
13646
- description: 'Allowed values. Accepts `["a", "b"]` or `{ "values": [...], "message": "..." }`.'
13656
+ description: 'Allowed values. Use `{ "values": [...], "labels": [...] }` for authored display labels; otherwise each unchanged value is its display fallback.'
13647
13657
  }
13648
13658
  ]
13649
13659
  },
@@ -13653,6 +13663,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13653
13663
  type EnumMetamodel {
13654
13664
  model: Model!
13655
13665
  values: [String!]!
13666
+ labels: [String!]!
13656
13667
  message: String
13657
13668
  }
13658
13669
 
@@ -13661,7 +13672,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13661
13672
  }
13662
13673
 
13663
13674
  extend type ModelMutation {
13664
- set_enum(values: [String!]!, message: String): EnumMetamodel
13675
+ set_enum(values: [String!]!, labels: [String!], message: String): EnumMetamodel
13665
13676
  }
13666
13677
  `
13667
13678
  ],
@@ -13670,15 +13681,19 @@ var enumMetamodelPackage = defineMetamodelPackage({
13670
13681
  EnumMetamodel: {
13671
13682
  model: (value) => value.model,
13672
13683
  values: (value) => value.values,
13684
+ labels: (value) => value.labels || [],
13673
13685
  message: (value) => value.message || null
13674
13686
  },
13675
13687
  Model: {
13676
13688
  enum_rule: async (ant) => await run(ant.enum_rule())
13677
13689
  },
13678
13690
  ModelMutation: {
13679
- set_enum: async (ant, { values, message }) => {
13680
- const model = await run(ant.set_enum(values, message));
13681
- return { model, values, message };
13691
+ set_enum: async (ant, { values, labels, message }) => {
13692
+ const resolvedLabels = Array.isArray(labels) && labels.length === values.length ? labels : values;
13693
+ const model = await run(
13694
+ ant.set_enum(values, resolvedLabels, message)
13695
+ );
13696
+ return { model, values, labels: resolvedLabels, message };
13682
13697
  }
13683
13698
  }
13684
13699
  };
@@ -13691,7 +13706,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13691
13706
  },
13692
13707
  summary: {
13693
13708
  selections: {
13694
- propertyFields: [`enum_rule { values message }`]
13709
+ propertyFields: [`enum_rule { values labels message }`]
13695
13710
  },
13696
13711
  readPropertySummary(rawProperty) {
13697
13712
  const values = Array.isArray(rawProperty.enum_rule?.values) ? rawProperty.enum_rule.values.filter(
@@ -13699,8 +13714,15 @@ var enumMetamodelPackage = defineMetamodelPackage({
13699
13714
  ) : [];
13700
13715
  if (values.length === 0) return { enumRule: null };
13701
13716
  const message = typeof rawProperty.enum_rule?.message === "string" ? rawProperty.enum_rule.message : null;
13717
+ const labels = Array.isArray(rawProperty.enum_rule?.labels) ? rawProperty.enum_rule.labels.filter(
13718
+ (label) => typeof label === "string" && label.length > 0
13719
+ ) : [];
13702
13720
  return {
13703
- enumRule: message ? { values, message } : { values }
13721
+ enumRule: {
13722
+ values,
13723
+ ...labels.length === values.length ? { labels } : {},
13724
+ ...message ? { message } : {}
13725
+ }
13704
13726
  };
13705
13727
  }
13706
13728
  },
@@ -15331,7 +15353,6 @@ function buildEffectMetamodelMutations(toolPath, spec) {
15331
15353
  // src/client.ts
15332
15354
  var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
15333
15355
  var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
15334
- var MAX_CONVERSATION_SESSION_LIST_OFFSET = 1e5;
15335
15356
  function requireUserEnvironmentSequence(value, field) {
15336
15357
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
15337
15358
  throw new Error(
@@ -15711,6 +15732,10 @@ var Environment = class _Environment {
15711
15732
  get sessions() {
15712
15733
  return {
15713
15734
  list: async (options = {}) => this.listSessions(options),
15735
+ page: async (options = {}) => this.granular.listSessionsPage({
15736
+ ...options,
15737
+ environmentId: this.environmentId
15738
+ }),
15714
15739
  create: async (options) => this.createSession(options),
15715
15740
  connect: async (sessionId, options) => this.connectSession(sessionId, options),
15716
15741
  reopen: async (sessionId, options) => this.reopenSession(sessionId, options),
@@ -15966,7 +15991,6 @@ var Environment = class _Environment {
15966
15991
  headers: {
15967
15992
  Authorization: `Bearer ${this._apiKey}`,
15968
15993
  "Content-Type": "application/json",
15969
- Connection: "close",
15970
15994
  ...options.headers
15971
15995
  }
15972
15996
  });
@@ -17490,8 +17514,7 @@ var EnvironmentSession = class extends Session {
17490
17514
  method: "POST",
17491
17515
  headers: {
17492
17516
  "Content-Type": "application/json",
17493
- Authorization: `Bearer ${this.environment.authToken}`,
17494
- Connection: "close"
17517
+ Authorization: `Bearer ${this.environment.authToken}`
17495
17518
  },
17496
17519
  body: JSON.stringify({
17497
17520
  reason: "sdk_disconnect_http_fallback",
@@ -18193,6 +18216,21 @@ var Granular = class _Granular {
18193
18216
  * List indexed sessions using ownership filters and bounded pagination.
18194
18217
  */
18195
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) {
18196
18234
  const environmentId = options.environmentId?.trim();
18197
18235
  const sandboxId = options.sandboxId?.trim();
18198
18236
  const subjectId = options.subjectId?.trim();
@@ -18220,17 +18258,14 @@ var Granular = class _Granular {
18220
18258
  1,
18221
18259
  MAX_CONVERSATION_SESSION_LIST_LIMIT
18222
18260
  );
18223
- const offset = boundedSessionListInteger(
18224
- options.offset,
18225
- "offset",
18226
- 0,
18227
- 0,
18228
- MAX_CONVERSATION_SESSION_LIST_OFFSET
18229
- );
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
+ }
18230
18265
  const query = new URLSearchParams({
18231
- limit: String(limit),
18232
- offset: String(offset)
18266
+ limit: String(limit)
18233
18267
  });
18268
+ if (cursor) query.set("cursor", cursor);
18234
18269
  if (environmentId) query.set("environmentId", environmentId);
18235
18270
  if (sandboxId) query.set("sandboxId", sandboxId);
18236
18271
  if (subjectId) query.set("userId", subjectId);
@@ -18238,11 +18273,13 @@ var Granular = class _Granular {
18238
18273
  query.set("sessionScope", options.sessionScope.trim());
18239
18274
  }
18240
18275
  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));
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 };
18246
18283
  }
18247
18284
  /**
18248
18285
  * List active (open) sessions for an environment.
@@ -18269,9 +18306,6 @@ var Granular = class _Granular {
18269
18306
  if (typeof options.limit === "number") {
18270
18307
  query.set("limit", String(options.limit));
18271
18308
  }
18272
- if (typeof options.offset === "number") {
18273
- query.set("offset", String(options.offset));
18274
- }
18275
18309
  const state = await this.request(
18276
18310
  `/sdk/user-environment-state?${query.toString()}`
18277
18311
  );
@@ -19205,10 +19239,20 @@ var Granular = class _Granular {
19205
19239
  get environments() {
19206
19240
  return {
19207
19241
  list: async (sandboxId) => {
19208
- const result = await this.request(
19209
- `/control/sandboxes/${sandboxId}/environments`
19210
- );
19211
- 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;
19212
19256
  },
19213
19257
  get: async (environmentId) => {
19214
19258
  return normalizeEnvironmentData(
@@ -19418,7 +19462,6 @@ var Granular = class _Granular {
19418
19462
  headers: {
19419
19463
  Authorization: `Bearer ${this.apiKey}`,
19420
19464
  "Content-Type": "application/json",
19421
- Connection: "close",
19422
19465
  ...options.headers
19423
19466
  }
19424
19467
  });