@granular-software/sdk 0.4.33 → 0.4.34

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 { P as Prompt, f as EnvironmentSession, c as SessionHeapSnapshot, bf as ManifestContent, aN as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, J as CreateEnvironmentData, k as GranularOptions } from './client-DTvI5MUG.mjs';
1
+ import { P as Prompt, f as EnvironmentSession, c as SessionHeapSnapshot, bg as ManifestContent, aO as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, J as CreateEnvironmentData, k as GranularOptions } from './client-iw76FL_8.mjs';
2
2
  import { GeneratedJobCodeIssue, HarnessControllerBudgets } from './agent-harness.mjs';
3
3
  import '@automerge/automerge';
4
4
  import '@automerge/automerge/slim';
@@ -1,4 +1,4 @@
1
- import { P as Prompt, f as EnvironmentSession, c as SessionHeapSnapshot, bf as ManifestContent, aN as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, J as CreateEnvironmentData, k as GranularOptions } from './client-DTvI5MUG.js';
1
+ import { P as Prompt, f as EnvironmentSession, c as SessionHeapSnapshot, bg as ManifestContent, aO as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, J as CreateEnvironmentData, k as GranularOptions } from './client-iw76FL_8.js';
2
2
  import { GeneratedJobCodeIssue, HarnessControllerBudgets } from './agent-harness.js';
3
3
  import '@automerge/automerge';
4
4
  import '@automerge/automerge/slim';
@@ -10891,6 +10891,50 @@ function computeEffectKey(effect) {
10891
10891
  }
10892
10892
  return effect.static ? `class:${attachedClass}:static:${effect.name}` : `class:${attachedClass}:instance:${effect.name}`;
10893
10893
  }
10894
+ function computeEffectVersionSelectorSpecificity(selector) {
10895
+ if (!selector || selector.mode === "all") {
10896
+ return 0;
10897
+ }
10898
+ if (selector.mode === "exact") {
10899
+ return 2;
10900
+ }
10901
+ return 1;
10902
+ }
10903
+ function matchesEffectVersionSelector(selector, buildVersionNumber) {
10904
+ if (!selector || selector.mode === "all") {
10905
+ return true;
10906
+ }
10907
+ if (typeof buildVersionNumber !== "number" || !Number.isFinite(buildVersionNumber)) {
10908
+ return false;
10909
+ }
10910
+ if (selector.mode === "exact") {
10911
+ return buildVersionNumber === selector.versionNumber;
10912
+ }
10913
+ if (selector.mode === "before") {
10914
+ return buildVersionNumber < selector.versionNumber;
10915
+ }
10916
+ return buildVersionNumber > selector.versionNumber;
10917
+ }
10918
+ function selectRegisteredEffect(effectMap, effectKey, buildVersionNumber) {
10919
+ let bestEffect;
10920
+ let bestSpecificity = Number.NEGATIVE_INFINITY;
10921
+ for (const effect of effectMap.values()) {
10922
+ if (computeEffectKey(effect) !== effectKey) {
10923
+ continue;
10924
+ }
10925
+ if (!matchesEffectVersionSelector(effect.versionSelector, buildVersionNumber)) {
10926
+ continue;
10927
+ }
10928
+ const specificity = computeEffectVersionSelectorSpecificity(
10929
+ effect.versionSelector
10930
+ );
10931
+ if (!bestEffect || specificity > bestSpecificity) {
10932
+ bestEffect = effect;
10933
+ bestSpecificity = specificity;
10934
+ }
10935
+ }
10936
+ return bestEffect;
10937
+ }
10894
10938
  function normalizeEffectBehaviors(value) {
10895
10939
  return normalizeEffectBehaviorSummary(
10896
10940
  value
@@ -10911,9 +10955,17 @@ function resolveReverseEffect(effectMap, currentEffect, request, behaviors) {
10911
10955
  return void 0;
10912
10956
  }
10913
10957
  if (reverseHandler.includes(":")) {
10914
- return effectMap.get(reverseHandler);
10958
+ return selectRegisteredEffect(
10959
+ effectMap,
10960
+ reverseHandler,
10961
+ request.context?.buildVersionNumber
10962
+ );
10915
10963
  }
10916
- const directMatch = effectMap.get(reverseHandler);
10964
+ const directMatch = selectRegisteredEffect(
10965
+ effectMap,
10966
+ reverseHandler,
10967
+ request.context?.buildVersionNumber
10968
+ );
10917
10969
  if (directMatch) {
10918
10970
  return directMatch;
10919
10971
  }
@@ -10928,7 +10980,11 @@ function resolveReverseEffect(effectMap, currentEffect, request, behaviors) {
10928
10980
  })
10929
10981
  ];
10930
10982
  for (const candidateKey of candidateKeys) {
10931
- const candidate = effectMap.get(candidateKey);
10983
+ const candidate = selectRegisteredEffect(
10984
+ effectMap,
10985
+ candidateKey,
10986
+ request.context?.buildVersionNumber
10987
+ );
10932
10988
  if (candidate) {
10933
10989
  return candidate;
10934
10990
  }
@@ -10964,7 +11020,11 @@ function resolveHandlerForMode(effectMap, effect, request) {
10964
11020
  return { effect, mode, handler: effect.handler };
10965
11021
  }
10966
11022
  async function invokeRegisteredEffect(effectMap, request) {
10967
- const effect = effectMap.get(request.effectKey);
11023
+ const effect = selectRegisteredEffect(
11024
+ effectMap,
11025
+ request.effectKey,
11026
+ request.context?.buildVersionNumber
11027
+ );
10968
11028
  if (!effect) {
10969
11029
  throw new Error(`Effect handler not found: ${request.effectKey}`);
10970
11030
  }
@@ -12223,6 +12283,17 @@ function computeEffectKey2(effect) {
12223
12283
  }
12224
12284
  return effect.static ? `class:${attachedClass}:static:${effect.name}` : `class:${attachedClass}:instance:${effect.name}`;
12225
12285
  }
12286
+ function computeEffectVersionSelectorKey(selector) {
12287
+ if (!selector || selector.mode === "all") {
12288
+ return "all";
12289
+ }
12290
+ return `${selector.mode}:${selector.versionNumber}`;
12291
+ }
12292
+ function computeEffectRegistrationKey(effect) {
12293
+ return `${computeEffectKey2(effect)}@${computeEffectVersionSelectorKey(
12294
+ effect.versionSelector
12295
+ )}`;
12296
+ }
12226
12297
  function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId) {
12227
12298
  const url = new URL(apiUrl);
12228
12299
  if (url.pathname.endsWith("/granular/ws/connect")) {
@@ -13744,7 +13815,7 @@ var Granular = class _Granular {
13744
13815
  onUnexpectedClose;
13745
13816
  onReconnectError;
13746
13817
  debugHttp = process.env.GRANULAR_DEBUG_HTTP === "1";
13747
- /** Sandbox-level effect registry: sandboxId → (effectKey → ToolWithHandler) */
13818
+ /** Sandbox-level effect registry: sandboxId → (effectKey@selector → ToolWithHandler) */
13748
13819
  sandboxEffects = /* @__PURE__ */ new Map();
13749
13820
  /** Live sandbox-scoped effect hosts keyed by sandboxId */
13750
13821
  sandboxEffectHosts = /* @__PURE__ */ new Map();
@@ -14163,7 +14234,8 @@ var Granular = class _Granular {
14163
14234
  provenance: effect.provenance || { source: "custom" },
14164
14235
  tags: effect.tags,
14165
14236
  className: effect.className,
14166
- static: effect.static
14237
+ static: effect.static,
14238
+ versionSelector: effect.versionSelector
14167
14239
  };
14168
14240
  }
14169
14241
  async publishSandboxEffectCatalog(host) {
@@ -14351,7 +14423,10 @@ var Granular = class _Granular {
14351
14423
  async registerEffect(sandboxNameOrId, effect) {
14352
14424
  const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
14353
14425
  const sandboxId = sandbox.sandboxId;
14354
- this.getSandboxEffectMap(sandboxId).set(computeEffectKey2(effect), effect);
14426
+ this.getSandboxEffectMap(sandboxId).set(
14427
+ computeEffectRegistrationKey(effect),
14428
+ effect
14429
+ );
14355
14430
  await this.syncSandboxEffectCatalog(sandboxId);
14356
14431
  }
14357
14432
  /**
@@ -14364,7 +14439,7 @@ var Granular = class _Granular {
14364
14439
  const sandboxId = sandbox.sandboxId;
14365
14440
  const map = this.getSandboxEffectMap(sandboxId);
14366
14441
  for (const effect of effects) {
14367
- map.set(computeEffectKey2(effect), effect);
14442
+ map.set(computeEffectRegistrationKey(effect), effect);
14368
14443
  }
14369
14444
  await this.syncSandboxEffectCatalog(sandboxId);
14370
14445
  }
@@ -14382,7 +14457,7 @@ var Granular = class _Granular {
14382
14457
  return;
14383
14458
  }
14384
14459
  const nextEntries = Array.from(currentMap.entries()).filter(
14385
- ([effectKey, effect]) => effectKey !== name && effect.name !== name
14460
+ ([, effect]) => computeEffectKey2(effect) !== name && effect.name !== name
14386
14461
  );
14387
14462
  if (nextEntries.length === currentMap.size) {
14388
14463
  return;