@granular-software/sdk 0.4.52 → 0.4.53

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,4 +1,4 @@
1
- import { a as EnvironmentSession, G as Granular } from './client-B2OyGOHE.mjs';
1
+ import { a as EnvironmentSession, G as Granular } from './client-CfTDojJF.mjs';
2
2
  import { G as GranularSpendContext, h as OpenAITokenSpend, P as Prompt, bW as RecordObjectOptions, cL as ManifestContent, c as SessionHeapSnapshot, T as ToolWithHandler, K as ConnectOptions, ag as CreateEnvironmentData, y as GranularOptions } from './spend-DpRRCrAr.mjs';
3
3
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.mjs';
4
4
  import '@automerge/automerge';
@@ -1,4 +1,4 @@
1
- import { a as EnvironmentSession, G as Granular } from './client-BMfjRJTs.js';
1
+ import { a as EnvironmentSession, G as Granular } from './client-DcRzwuGp.js';
2
2
  import { G as GranularSpendContext, h as OpenAITokenSpend, P as Prompt, bW as RecordObjectOptions, cL as ManifestContent, c as SessionHeapSnapshot, T as ToolWithHandler, K as ConnectOptions, ag as CreateEnvironmentData, y as GranularOptions } from './spend-DpRRCrAr.js';
3
3
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.js';
4
4
  import '@automerge/automerge';
@@ -16356,6 +16356,55 @@ var Granular = class _Granular {
16356
16356
  throw error;
16357
16357
  }
16358
16358
  }
16359
+ /**
16360
+ * Resolve one exact environment only when Granular confirms that it belongs
16361
+ * to the given external user in the requested sandbox (and, optionally,
16362
+ * tag). This is deliberately read-only: callers use it to keep an already
16363
+ * opened delegated workspace stable while a newer active environment is
16364
+ * being prepared in the background.
16365
+ */
16366
+ async getEnvironmentForUser(options) {
16367
+ const sandboxId = options.sandboxId.trim();
16368
+ const userId = options.userId.trim();
16369
+ const environmentId = options.environmentId.trim();
16370
+ const tagName = options.tag?.trim();
16371
+ if (!sandboxId || !userId || !environmentId) {
16372
+ throw new Error(
16373
+ "getEnvironmentForUser() requires sandboxId, userId, and environmentId."
16374
+ );
16375
+ }
16376
+ const subjects = await this.request(
16377
+ `/control/subjects?identityId=${encodeURIComponent(userId)}`
16378
+ );
16379
+ const subject = (subjects.items || []).find(
16380
+ (item) => item.identityId === userId || item.userId === userId
16381
+ );
16382
+ const subjectId = subject?.subjectId || subject?.granularId;
16383
+ if (!subjectId) return null;
16384
+ let environment;
16385
+ try {
16386
+ environment = await this.environments.get(environmentId);
16387
+ } catch (error) {
16388
+ const message = error instanceof Error ? error.message : String(error);
16389
+ if (message.includes("404") || message.includes("not found")) {
16390
+ return null;
16391
+ }
16392
+ throw error;
16393
+ }
16394
+ if (environment.sandboxId !== sandboxId || environment.subjectId !== subjectId) {
16395
+ return null;
16396
+ }
16397
+ if (tagName) {
16398
+ const tags = await this.request(`/control/sandboxes/${encodeURIComponent(sandboxId)}/tags`);
16399
+ const tag = (tags.items || []).find(
16400
+ (candidate) => candidate?.name === tagName
16401
+ );
16402
+ if (!tag || environment.tagId !== tag.tagId) {
16403
+ return null;
16404
+ }
16405
+ }
16406
+ return this.bindEnvironmentHandle(environment);
16407
+ }
16359
16408
  /**
16360
16409
  * Register one reviewed, pre-existing environment as the active workspace
16361
16410
  * for an external user. This is for a controlled migration only: it does