@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.
@@ -1,5 +1,5 @@
1
- import { a as EnvironmentSession, G as Granular } from './client-Dg0I_5B_.mjs';
2
- import { at as GranularSpendContext, ao as OpenAITokenSpend, P as Prompt, cX as RecordObjectOptions, dN as ManifestContent, d as SessionHeapSnapshot, T as ToolWithHandler, aP as ConnectOptions, bd as CreateEnvironmentData, aI as GranularOptions } from './spend-C8OQnF6E.mjs';
1
+ import { a as EnvironmentSession, G as Granular } from './client-IQeOoPnO.mjs';
2
+ import { at as GranularSpendContext, ao as OpenAITokenSpend, P as Prompt, cY as RecordObjectOptions, dO as ManifestContent, d as SessionHeapSnapshot, T as ToolWithHandler, aP as ConnectOptions, be as CreateEnvironmentData, aI as GranularOptions } from './spend-CDLmk-KW.mjs';
3
3
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.mjs';
4
4
  import '@automerge/automerge';
5
5
  import '@automerge/automerge/slim';
@@ -1,5 +1,5 @@
1
- import { a as EnvironmentSession, G as Granular } from './client-Bx5jIDGB.js';
2
- import { at as GranularSpendContext, ao as OpenAITokenSpend, P as Prompt, cX as RecordObjectOptions, dN as ManifestContent, d as SessionHeapSnapshot, T as ToolWithHandler, aP as ConnectOptions, bd as CreateEnvironmentData, aI as GranularOptions } from './spend-C8OQnF6E.js';
1
+ import { a as EnvironmentSession, G as Granular } from './client-BziqnDTl.js';
2
+ import { at as GranularSpendContext, ao as OpenAITokenSpend, P as Prompt, cY as RecordObjectOptions, dO as ManifestContent, d as SessionHeapSnapshot, T as ToolWithHandler, aP as ConnectOptions, be as CreateEnvironmentData, aI as GranularOptions } from './spend-CDLmk-KW.js';
3
3
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.js';
4
4
  import '@automerge/automerge';
5
5
  import '@automerge/automerge/slim';
@@ -12198,8 +12198,12 @@ external_exports.union([
12198
12198
  external_exports.array(external_exports.string()),
12199
12199
  external_exports.object({
12200
12200
  values: external_exports.array(external_exports.string()),
12201
+ labels: external_exports.array(external_exports.string().min(1)).optional(),
12201
12202
  message: external_exports.string().optional()
12202
- }).strict()
12203
+ }).strict().refine(
12204
+ (rule) => !rule.labels || rule.labels.length === rule.values.length,
12205
+ { message: "Enum labels must match enum values one-for-one" }
12206
+ )
12203
12207
  ]);
12204
12208
  external_exports.union([
12205
12209
  external_exports.boolean(),
@@ -12227,7 +12231,7 @@ var StateMachineStateSchema = external_exports.union([
12227
12231
  external_exports.string(),
12228
12232
  external_exports.object({
12229
12233
  name: external_exports.string().min(1),
12230
- label: external_exports.string().optional(),
12234
+ label: external_exports.string().min(1).optional(),
12231
12235
  description: external_exports.string().optional(),
12232
12236
  isFinal: external_exports.boolean().optional()
12233
12237
  }).strict()
@@ -13121,7 +13125,7 @@ function resolveHandlerForMode(effectMap, effect, request) {
13121
13125
  if (mode === "artifactOptions") {
13122
13126
  if (!effect.artifactOptionsHandler) {
13123
13127
  throw new Error(
13124
- `Artifact relationship options are not supported for ${request.effectKey}`
13128
+ `Artifact field options are not supported for ${request.effectKey}`
13125
13129
  );
13126
13130
  }
13127
13131
  return {
@@ -13623,18 +13627,24 @@ function normalizeEnumInput(enumSpec) {
13623
13627
  (value) => typeof value === "string" && value.length > 0
13624
13628
  );
13625
13629
  if (values.length === 0) return null;
13626
- return config.message ? { values, message: config.message } : { values };
13630
+ const labels = Array.isArray(config.labels) && config.labels.length === values.length ? config.labels : values;
13631
+ return {
13632
+ values,
13633
+ labels,
13634
+ ...config.message ? { message: config.message } : {}
13635
+ };
13627
13636
  }
13628
13637
  function buildEnumFieldMutations(fieldPath, enumSpec) {
13629
13638
  const normalized = normalizeEnumInput(enumSpec);
13630
13639
  if (!normalized) return [];
13631
13640
  const messageArg = normalized.message ? `, message: ${JSON.stringify(normalized.message)}` : "";
13641
+ const labelsArg = normalized.labels ? `, labels: ${JSON.stringify(normalized.labels)}` : "";
13632
13642
  return [
13633
13643
  {
13634
13644
  label: `set enum on ${fieldPath}`,
13635
13645
  query: `mutation { at(path: ${JSON.stringify(fieldPath)}) { set_enum(values: ${JSON.stringify(
13636
13646
  normalized.values
13637
- )}${messageArg}) { values } } }`
13647
+ )}${labelsArg}${messageArg}) { values labels } } }`
13638
13648
  }
13639
13649
  ];
13640
13650
  }
@@ -13644,7 +13654,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13644
13654
  fieldRows: [
13645
13655
  {
13646
13656
  key: "enum",
13647
- description: 'Allowed values. Accepts `["a", "b"]` or `{ "values": [...], "message": "..." }`.'
13657
+ description: 'Allowed values. Use `{ "values": [...], "labels": [...] }` for authored display labels; otherwise each unchanged value is its display fallback.'
13648
13658
  }
13649
13659
  ]
13650
13660
  },
@@ -13654,6 +13664,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13654
13664
  type EnumMetamodel {
13655
13665
  model: Model!
13656
13666
  values: [String!]!
13667
+ labels: [String!]!
13657
13668
  message: String
13658
13669
  }
13659
13670
 
@@ -13662,7 +13673,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13662
13673
  }
13663
13674
 
13664
13675
  extend type ModelMutation {
13665
- set_enum(values: [String!]!, message: String): EnumMetamodel
13676
+ set_enum(values: [String!]!, labels: [String!], message: String): EnumMetamodel
13666
13677
  }
13667
13678
  `
13668
13679
  ],
@@ -13671,15 +13682,19 @@ var enumMetamodelPackage = defineMetamodelPackage({
13671
13682
  EnumMetamodel: {
13672
13683
  model: (value) => value.model,
13673
13684
  values: (value) => value.values,
13685
+ labels: (value) => value.labels || [],
13674
13686
  message: (value) => value.message || null
13675
13687
  },
13676
13688
  Model: {
13677
13689
  enum_rule: async (ant) => await run(ant.enum_rule())
13678
13690
  },
13679
13691
  ModelMutation: {
13680
- set_enum: async (ant, { values, message }) => {
13681
- const model = await run(ant.set_enum(values, message));
13682
- return { model, values, message };
13692
+ set_enum: async (ant, { values, labels, message }) => {
13693
+ const resolvedLabels = Array.isArray(labels) && labels.length === values.length ? labels : values;
13694
+ const model = await run(
13695
+ ant.set_enum(values, resolvedLabels, message)
13696
+ );
13697
+ return { model, values, labels: resolvedLabels, message };
13683
13698
  }
13684
13699
  }
13685
13700
  };
@@ -13692,7 +13707,7 @@ var enumMetamodelPackage = defineMetamodelPackage({
13692
13707
  },
13693
13708
  summary: {
13694
13709
  selections: {
13695
- propertyFields: [`enum_rule { values message }`]
13710
+ propertyFields: [`enum_rule { values labels message }`]
13696
13711
  },
13697
13712
  readPropertySummary(rawProperty) {
13698
13713
  const values = Array.isArray(rawProperty.enum_rule?.values) ? rawProperty.enum_rule.values.filter(
@@ -13700,8 +13715,15 @@ var enumMetamodelPackage = defineMetamodelPackage({
13700
13715
  ) : [];
13701
13716
  if (values.length === 0) return { enumRule: null };
13702
13717
  const message = typeof rawProperty.enum_rule?.message === "string" ? rawProperty.enum_rule.message : null;
13718
+ const labels = Array.isArray(rawProperty.enum_rule?.labels) ? rawProperty.enum_rule.labels.filter(
13719
+ (label) => typeof label === "string" && label.length > 0
13720
+ ) : [];
13703
13721
  return {
13704
- enumRule: message ? { values, message } : { values }
13722
+ enumRule: {
13723
+ values,
13724
+ ...labels.length === values.length ? { labels } : {},
13725
+ ...message ? { message } : {}
13726
+ }
13705
13727
  };
13706
13728
  }
13707
13729
  },
@@ -15234,7 +15256,6 @@ function buildEffectMetamodelMutations(toolPath, spec) {
15234
15256
  // src/client.ts
15235
15257
  var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
15236
15258
  var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
15237
- var MAX_CONVERSATION_SESSION_LIST_OFFSET = 1e5;
15238
15259
  function requireUserEnvironmentSequence(value, field) {
15239
15260
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
15240
15261
  throw new Error(
@@ -15614,6 +15635,10 @@ var Environment = class _Environment {
15614
15635
  get sessions() {
15615
15636
  return {
15616
15637
  list: async (options = {}) => this.listSessions(options),
15638
+ page: async (options = {}) => this.granular.listSessionsPage({
15639
+ ...options,
15640
+ environmentId: this.environmentId
15641
+ }),
15617
15642
  create: async (options) => this.createSession(options),
15618
15643
  connect: async (sessionId, options) => this.connectSession(sessionId, options),
15619
15644
  reopen: async (sessionId, options) => this.reopenSession(sessionId, options),
@@ -15869,7 +15894,6 @@ var Environment = class _Environment {
15869
15894
  headers: {
15870
15895
  Authorization: `Bearer ${this._apiKey}`,
15871
15896
  "Content-Type": "application/json",
15872
- Connection: "close",
15873
15897
  ...options.headers
15874
15898
  }
15875
15899
  });
@@ -17393,8 +17417,7 @@ var EnvironmentSession = class extends Session {
17393
17417
  method: "POST",
17394
17418
  headers: {
17395
17419
  "Content-Type": "application/json",
17396
- Authorization: `Bearer ${this.environment.authToken}`,
17397
- Connection: "close"
17420
+ Authorization: `Bearer ${this.environment.authToken}`
17398
17421
  },
17399
17422
  body: JSON.stringify({
17400
17423
  reason: "sdk_disconnect_http_fallback",
@@ -18096,6 +18119,21 @@ var Granular = class _Granular {
18096
18119
  * List indexed sessions using ownership filters and bounded pagination.
18097
18120
  */
18098
18121
  async listSessions(options) {
18122
+ const items = [];
18123
+ let cursor = options.cursor?.trim() || void 0;
18124
+ let pageCount = 0;
18125
+ do {
18126
+ const page = await this.listSessionsPage({ ...options, cursor });
18127
+ items.push(...page.items);
18128
+ cursor = page.nextCursor || void 0;
18129
+ pageCount += 1;
18130
+ if (pageCount > 1e4) {
18131
+ throw new Error("Session pagination exceeded the safe page limit");
18132
+ }
18133
+ } while (cursor);
18134
+ return items;
18135
+ }
18136
+ async listSessionsPage(options) {
18099
18137
  const environmentId = options.environmentId?.trim();
18100
18138
  const sandboxId = options.sandboxId?.trim();
18101
18139
  const subjectId = options.subjectId?.trim();
@@ -18123,17 +18161,14 @@ var Granular = class _Granular {
18123
18161
  1,
18124
18162
  MAX_CONVERSATION_SESSION_LIST_LIMIT
18125
18163
  );
18126
- const offset = boundedSessionListInteger(
18127
- options.offset,
18128
- "offset",
18129
- 0,
18130
- 0,
18131
- MAX_CONVERSATION_SESSION_LIST_OFFSET
18132
- );
18164
+ const cursor = options.cursor?.trim();
18165
+ if (options.cursor !== void 0 && !cursor) {
18166
+ throw new Error("Session list cursor must be a non-empty string.");
18167
+ }
18133
18168
  const query = new URLSearchParams({
18134
- limit: String(limit),
18135
- offset: String(offset)
18169
+ limit: String(limit)
18136
18170
  });
18171
+ if (cursor) query.set("cursor", cursor);
18137
18172
  if (environmentId) query.set("environmentId", environmentId);
18138
18173
  if (sandboxId) query.set("sandboxId", sandboxId);
18139
18174
  if (subjectId) query.set("userId", subjectId);
@@ -18141,11 +18176,13 @@ var Granular = class _Granular {
18141
18176
  query.set("sessionScope", options.sessionScope.trim());
18142
18177
  }
18143
18178
  if (status !== "all") query.set("status", status);
18144
- const res = await this.request(
18145
- `/control/sessions?${query.toString()}`
18146
- );
18147
- const items = Array.isArray(res.items) ? res.items : [];
18148
- return items.map((row) => this.normalizeConversationSession(row));
18179
+ const res = await this.request(`/control/sessions?${query.toString()}`);
18180
+ const items = Array.isArray(res.items) ? res.items.map((row) => this.normalizeConversationSession(row)) : [];
18181
+ const nextCursor = res.nextCursor ?? null;
18182
+ if (nextCursor === cursor) {
18183
+ throw new Error("Session pagination cursor did not advance");
18184
+ }
18185
+ return { items, nextCursor };
18149
18186
  }
18150
18187
  /**
18151
18188
  * List active (open) sessions for an environment.
@@ -18172,9 +18209,6 @@ var Granular = class _Granular {
18172
18209
  if (typeof options.limit === "number") {
18173
18210
  query.set("limit", String(options.limit));
18174
18211
  }
18175
- if (typeof options.offset === "number") {
18176
- query.set("offset", String(options.offset));
18177
- }
18178
18212
  const state = await this.request(
18179
18213
  `/sdk/user-environment-state?${query.toString()}`
18180
18214
  );
@@ -19108,10 +19142,20 @@ var Granular = class _Granular {
19108
19142
  get environments() {
19109
19143
  return {
19110
19144
  list: async (sandboxId) => {
19111
- const result = await this.request(
19112
- `/control/sandboxes/${sandboxId}/environments`
19113
- );
19114
- return result.items.map(normalizeEnvironmentData);
19145
+ const environments = [];
19146
+ let cursor = null;
19147
+ do {
19148
+ const query = cursor ? `?limit=100&cursor=${encodeURIComponent(cursor)}` : "";
19149
+ const result = await this.request(
19150
+ `/control/sandboxes/${sandboxId}/environments${query}`
19151
+ );
19152
+ environments.push(...result.items.map(normalizeEnvironmentData));
19153
+ if (result.nextCursor && result.nextCursor === cursor) {
19154
+ throw new Error("Environment pagination cursor did not advance");
19155
+ }
19156
+ cursor = result.nextCursor;
19157
+ } while (cursor);
19158
+ return environments;
19115
19159
  },
19116
19160
  get: async (environmentId) => {
19117
19161
  return normalizeEnvironmentData(
@@ -19321,7 +19365,6 @@ var Granular = class _Granular {
19321
19365
  headers: {
19322
19366
  Authorization: `Bearer ${this.apiKey}`,
19323
19367
  "Content-Type": "application/json",
19324
- Connection: "close",
19325
19368
  ...options.headers
19326
19369
  }
19327
19370
  });