@granular-software/sdk 0.4.60 → 0.4.62

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/README.md CHANGED
@@ -420,6 +420,14 @@ Built-in profiles are materialized by `granular init` and `granular pull`:
420
420
  - `confirm-all`: exposes every declared action but requires confirmation.
421
421
  - `deny-all`: exposes no executable actions.
422
422
 
423
+ `openEnvironment({ permissions: [...] })` resolves each entry by exact profile
424
+ name or profile ID. Unknown entries fail before the SDK writes an assignment;
425
+ they are never generated as permissive profiles. The only compatibility
426
+ exception is the explicit `allow-all` name, which the SDK may provision when it
427
+ is missing. Sync custom, `confirm-all`, and `deny-all` profiles with
428
+ `granular build` or `granular deploy` first. Map application roles to reviewed
429
+ profile names or IDs instead of forwarding unchecked end-user input.
430
+
423
431
  Manifest-level logic policies live on effects and apply to every profile:
424
432
 
425
433
  ```json
@@ -1,5 +1,5 @@
1
- import { a as EnvironmentSession, G as Granular } from './client-DSkGcmmX.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-CNe-Ff6U.mjs';
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';
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-BzgQvNyG.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-CNe-Ff6U.js';
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';
3
3
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.js';
4
4
  import '@automerge/automerge';
5
5
  import '@automerge/automerge/slim';
@@ -12274,6 +12274,7 @@ var StateTransitionInputBindingSchema = external_exports.lazy(
12274
12274
  );
12275
12275
  var StateTransitionActionSchema = external_exports.object({
12276
12276
  effect: external_exports.string().min(1),
12277
+ providerLabel: external_exports.string().optional(),
12277
12278
  input: external_exports.record(external_exports.string(), StateTransitionInputBindingSchema).optional()
12278
12279
  }).strict();
12279
12280
  var StateTransitionAssigneeSchema = external_exports.object({
@@ -14761,6 +14762,15 @@ var stateMachineMetamodelPackage = defineMetamodelPackage({
14761
14762
  is_final: Boolean!
14762
14763
  history: [StateMachineTransitionEvent!]!
14763
14764
  instances_in_state(state: String!): [Model!]!
14765
+ instance_population(state: String!, page: Int = 1, per_page: Int = 50): StateMachineInstancePopulation!
14766
+ }
14767
+
14768
+ type StateMachineInstancePopulation {
14769
+ count: Int!
14770
+ instances: [Model!]!
14771
+ page: Int!
14772
+ per_page: Int!
14773
+ has_more: Boolean!
14764
14774
  }
14765
14775
 
14766
14776
  type StateMachineState {
@@ -14969,6 +14979,13 @@ var stateMachineMetamodelPackage = defineMetamodelPackage({
14969
14979
  value.model.target || value.model,
14970
14980
  value.name,
14971
14981
  state
14982
+ ),
14983
+ instance_population: async (value, { state, page, per_page }) => await stateMachines.instancePopulation(
14984
+ value.model.target || value.model,
14985
+ value.name,
14986
+ state,
14987
+ page,
14988
+ per_page
14972
14989
  )
14973
14990
  }
14974
14991
  };
@@ -17905,11 +17922,16 @@ var Granular = class _Granular {
17905
17922
  `${methodName}() requires at least one permission so the SDK can ensure assignments for new users.`
17906
17923
  );
17907
17924
  }
17908
- for (const profileName of user.permissions) {
17909
- const profileId = await this.ensurePermissionProfile(
17910
- sandbox.sandboxId,
17911
- profileName
17925
+ const permissionProfileIds = [];
17926
+ for (const profileReference of user.permissions) {
17927
+ permissionProfileIds.push(
17928
+ await this.ensurePermissionProfile(
17929
+ sandbox.sandboxId,
17930
+ profileReference
17931
+ )
17912
17932
  );
17933
+ }
17934
+ for (const profileId of permissionProfileIds) {
17913
17935
  await this.ensureAssignment(
17914
17936
  user.granularId,
17915
17937
  sandbox.sandboxId,
@@ -18914,25 +18936,37 @@ var Granular = class _Granular {
18914
18936
  }
18915
18937
  }
18916
18938
  /**
18917
- * Ensure a permission profile exists for a sandbox, creating it if needed.
18918
- * If profileName matches an existing profile name, returns its ID.
18919
- * Otherwise, creates a v1 source-profile file shape with an allow default.
18939
+ * Resolve an existing permission profile by exact name or ID.
18940
+ *
18941
+ * `allow-all` is the sole compatibility profile that the SDK may provision
18942
+ * automatically. Every other missing reference fails closed so a typo or
18943
+ * untrusted role value cannot become an allow-default profile.
18920
18944
  */
18921
- async ensurePermissionProfile(sandboxId, profileName) {
18922
- try {
18923
- const profiles = await this.permissionProfiles.list(sandboxId);
18924
- const existing = profiles.find((p) => p.name === profileName);
18925
- if (existing) {
18926
- return existing.permissionProfileId;
18927
- }
18928
- } catch {
18945
+ async ensurePermissionProfile(sandboxId, profileReference) {
18946
+ const normalizedReference = typeof profileReference === "string" ? profileReference.trim() : "";
18947
+ if (!normalizedReference) {
18948
+ throw new Error(
18949
+ "Permission profile references must be non-empty names or IDs."
18950
+ );
18951
+ }
18952
+ const profiles = await this.permissionProfiles.list(sandboxId);
18953
+ const existing = profiles.find(
18954
+ (profile) => profile.name === normalizedReference || profile.permissionProfileId === normalizedReference
18955
+ );
18956
+ if (existing) {
18957
+ return existing.permissionProfileId;
18958
+ }
18959
+ if (normalizedReference !== "allow-all") {
18960
+ throw new Error(
18961
+ `Permission profile "${normalizedReference}" was not found in sandbox ${sandboxId}. Provision it with granular build or granular deploy before calling openEnvironment(). Only the reserved "allow-all" profile can be created automatically.`
18962
+ );
18929
18963
  }
18930
18964
  const created = await this.permissionProfiles.create(sandboxId, {
18931
- name: profileName,
18965
+ name: normalizedReference,
18932
18966
  rules: {
18933
18967
  schemaVersion: 1,
18934
- name: profileName,
18935
- description: profileName === "allow-all" ? "Every declared action is visible unless a manifest policy denies it." : `Generated permission profile ${profileName}`,
18968
+ name: normalizedReference,
18969
+ description: "Every declared action is visible unless a manifest policy denies it.",
18936
18970
  defaults: { actionPolicy: "allow" },
18937
18971
  actions: []
18938
18972
  }