@granular-software/sdk 0.4.52 → 0.4.54

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-DL4S9uRc.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-BKde5VzV.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';
@@ -14362,6 +14362,7 @@ var Environment = class _Environment {
14362
14362
  import: async (records, options) => this.enqueueRecordImport(records, options),
14363
14363
  listImports: async (status) => this.listRecordImports(status),
14364
14364
  getImport: async (importId) => this.getRecordImport(importId),
14365
+ listImportItems: async (importId, status) => this.listRecordImportItems(importId, status),
14365
14366
  getImportSummary: async () => this.getRecordImportSummary(),
14366
14367
  cancelImport: async (importId) => this.cancelRecordImport(importId),
14367
14368
  getAwaitingCount: async () => this.getAwaitingRecordCount()
@@ -15540,6 +15541,15 @@ var Environment = class _Environment {
15540
15541
  `/control/record-imports/${importId}`
15541
15542
  );
15542
15543
  }
15544
+ /**
15545
+ * List the individual records persisted for one asynchronous import. This
15546
+ * makes terminal import failures diagnosable without database access.
15547
+ */
15548
+ async listRecordImportItems(importId, status) {
15549
+ const suffix = status ? `?status=${encodeURIComponent(status)}` : "";
15550
+ const response = await this.controlPlaneRequest(`/control/record-imports/${importId}/items${suffix}`);
15551
+ return Array.isArray(response.items) ? response.items : [];
15552
+ }
15543
15553
  /**
15544
15554
  * Cancel a queued/background record import.
15545
15555
  */
@@ -16356,6 +16366,55 @@ var Granular = class _Granular {
16356
16366
  throw error;
16357
16367
  }
16358
16368
  }
16369
+ /**
16370
+ * Resolve one exact environment only when Granular confirms that it belongs
16371
+ * to the given external user in the requested sandbox (and, optionally,
16372
+ * tag). This is deliberately read-only: callers use it to keep an already
16373
+ * opened delegated workspace stable while a newer active environment is
16374
+ * being prepared in the background.
16375
+ */
16376
+ async getEnvironmentForUser(options) {
16377
+ const sandboxId = options.sandboxId.trim();
16378
+ const userId = options.userId.trim();
16379
+ const environmentId = options.environmentId.trim();
16380
+ const tagName = options.tag?.trim();
16381
+ if (!sandboxId || !userId || !environmentId) {
16382
+ throw new Error(
16383
+ "getEnvironmentForUser() requires sandboxId, userId, and environmentId."
16384
+ );
16385
+ }
16386
+ const subjects = await this.request(
16387
+ `/control/subjects?identityId=${encodeURIComponent(userId)}`
16388
+ );
16389
+ const subject = (subjects.items || []).find(
16390
+ (item) => item.identityId === userId || item.userId === userId
16391
+ );
16392
+ const subjectId = subject?.subjectId || subject?.granularId;
16393
+ if (!subjectId) return null;
16394
+ let environment;
16395
+ try {
16396
+ environment = await this.environments.get(environmentId);
16397
+ } catch (error) {
16398
+ const message = error instanceof Error ? error.message : String(error);
16399
+ if (message.includes("404") || message.includes("not found")) {
16400
+ return null;
16401
+ }
16402
+ throw error;
16403
+ }
16404
+ if (environment.sandboxId !== sandboxId || environment.subjectId !== subjectId) {
16405
+ return null;
16406
+ }
16407
+ if (tagName) {
16408
+ const tags = await this.request(`/control/sandboxes/${encodeURIComponent(sandboxId)}/tags`);
16409
+ const tag = (tags.items || []).find(
16410
+ (candidate) => candidate?.name === tagName
16411
+ );
16412
+ if (!tag || environment.tagId !== tag.tagId) {
16413
+ return null;
16414
+ }
16415
+ }
16416
+ return this.bindEnvironmentHandle(environment);
16417
+ }
16359
16418
  /**
16360
16419
  * Register one reviewed, pre-existing environment as the active workspace
16361
16420
  * for an external user. This is for a controlled migration only: it does