@granular-software/sdk 0.4.43 → 0.4.45

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/dist/cli/index.js CHANGED
@@ -21583,6 +21583,164 @@ async function invokeRegisteredEffect(effectMap, request) {
21583
21583
  return resolved.handler(request.input, context);
21584
21584
  }
21585
21585
 
21586
+ // src/client-normalizers.ts
21587
+ function createEmptyHeapSnapshot(now = Date.now()) {
21588
+ return {
21589
+ entriesByPath: {},
21590
+ listsByName: {},
21591
+ variablesByName: {},
21592
+ updatedAt: now
21593
+ };
21594
+ }
21595
+ function normalizeHeapSnapshot(raw) {
21596
+ if (!raw || typeof raw !== "object") {
21597
+ return createEmptyHeapSnapshot();
21598
+ }
21599
+ const heap = raw;
21600
+ return {
21601
+ entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
21602
+ listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
21603
+ variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
21604
+ updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
21605
+ };
21606
+ }
21607
+ function normalizeGraphPathSegment(value) {
21608
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
21609
+ }
21610
+ function extractRecordIdFromGraphPath(path7, className) {
21611
+ const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
21612
+ if (path7.startsWith(normalizedPrefix)) {
21613
+ return path7.slice(normalizedPrefix.length);
21614
+ }
21615
+ const legacyPrefix = `${className}_`;
21616
+ if (path7.startsWith(legacyPrefix)) {
21617
+ return path7.slice(legacyPrefix.length);
21618
+ }
21619
+ return path7;
21620
+ }
21621
+ function toRecordSearchResult(className, node) {
21622
+ const path7 = typeof node.path === "string" ? node.path : "";
21623
+ if (!path7) return null;
21624
+ const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
21625
+ (submodel) => {
21626
+ const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
21627
+ if (!name) return [];
21628
+ if (typeof submodel.string_value === "string") {
21629
+ return [{ name, type: "string", value: submodel.string_value }];
21630
+ }
21631
+ if (typeof submodel.number_value === "number") {
21632
+ return [{ name, type: "number", value: submodel.number_value }];
21633
+ }
21634
+ if (typeof submodel.boolean_value === "boolean") {
21635
+ return [
21636
+ {
21637
+ name,
21638
+ type: "boolean",
21639
+ value: submodel.boolean_value
21640
+ }
21641
+ ];
21642
+ }
21643
+ return [];
21644
+ }
21645
+ ) : [];
21646
+ return {
21647
+ path: path7,
21648
+ className,
21649
+ id: extractRecordIdFromGraphPath(path7, className),
21650
+ label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path7, className),
21651
+ description: typeof node.description === "string" && node.description.trim() ? node.description : null,
21652
+ fields
21653
+ };
21654
+ }
21655
+ function normalizeRecordSearchText(value) {
21656
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
21657
+ }
21658
+ function rankRecordSearchResult(result, query, index) {
21659
+ const normalizedQuery = normalizeRecordSearchText(query);
21660
+ if (!normalizedQuery) {
21661
+ return index;
21662
+ }
21663
+ const label = normalizeRecordSearchText(result.label || "");
21664
+ const id = normalizeRecordSearchText(result.id || "");
21665
+ const path7 = normalizeRecordSearchText(result.path || "");
21666
+ const className = normalizeRecordSearchText(result.className || "");
21667
+ const searchable = [label, id, path7, className].filter(Boolean);
21668
+ if (label === normalizedQuery) return index;
21669
+ if (id === normalizedQuery || path7 === normalizedQuery) return 100 + index;
21670
+ if (label.startsWith(normalizedQuery)) return 200 + index;
21671
+ if (searchable.some((value) => value.startsWith(normalizedQuery))) {
21672
+ return 300 + index;
21673
+ }
21674
+ if (label.includes(normalizedQuery)) return 400 + index;
21675
+ if (searchable.some((value) => value.includes(normalizedQuery))) {
21676
+ return 500 + index;
21677
+ }
21678
+ return 900 + index;
21679
+ }
21680
+ function deriveRuntimeBaseUrl(apiEndpoint) {
21681
+ try {
21682
+ const endpoint = new URL(apiEndpoint);
21683
+ const graphqlSuffix = "/orchestrator/graphql";
21684
+ if (endpoint.pathname.endsWith(graphqlSuffix)) {
21685
+ endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
21686
+ } else if (endpoint.pathname.endsWith("/graphql")) {
21687
+ endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
21688
+ }
21689
+ endpoint.search = "";
21690
+ endpoint.hash = "";
21691
+ return endpoint.toString().replace(/\/$/, "");
21692
+ } catch {
21693
+ return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
21694
+ }
21695
+ }
21696
+
21697
+ // src/client-transport.ts
21698
+ function sleep(ms) {
21699
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
21700
+ }
21701
+ function withTimeout(promise, timeoutMs, label) {
21702
+ let timer = null;
21703
+ const timeout = new Promise((_, reject) => {
21704
+ timer = setTimeout(() => {
21705
+ reject(new Error(`${label} timed out after ${timeoutMs}ms`));
21706
+ }, timeoutMs);
21707
+ });
21708
+ return Promise.race([promise, timeout]).finally(() => {
21709
+ if (timer) {
21710
+ clearTimeout(timer);
21711
+ }
21712
+ });
21713
+ }
21714
+ function isLocalControlUrl(url) {
21715
+ try {
21716
+ const parsed = new URL(url);
21717
+ return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
21718
+ } catch {
21719
+ return false;
21720
+ }
21721
+ }
21722
+ function isRetryableLocalWorkerRestart(status, body, url) {
21723
+ return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
21724
+ }
21725
+ function isRetryableRecordObjectsError(error2) {
21726
+ const message = error2 instanceof Error ? error2.message : String(error2);
21727
+ return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out|bad gateway|too many requests|gateway timeout|control plane api error \((?:429|500|502|503|504)\)|graphql api error \((?:429|500|502|503|504)\)|failed to record batch/i.test(
21728
+ message
21729
+ );
21730
+ }
21731
+ function isRetryableEffectRegistrationError(error2) {
21732
+ const message = error2 instanceof Error ? error2.message : String(error2);
21733
+ return /timed out|websocket disconnected|websocket not connected|rpc timeout|worker restarted mid-request|network connection lost|bad gateway|gateway timeout|too many requests|(?:control plane|granular|graphql) api error \((?:429|500|502|503|504)\)/i.test(
21734
+ message
21735
+ );
21736
+ }
21737
+ function isRetryableSessionDataError(error2) {
21738
+ const message = error2 instanceof Error ? error2.message : String(error2);
21739
+ return /network connection lost|worker restarted mid-request|econnreset|socket connection was closed unexpectedly|bad gateway|gateway timeout|service unavailable|session data api error \((?:429|500|502|503|504)\)/i.test(
21740
+ message
21741
+ );
21742
+ }
21743
+
21586
21744
  // src/spend.ts
21587
21745
  function toGranularHttpBase(apiUrl) {
21588
21746
  const url = new URL(apiUrl);
@@ -21784,51 +21942,6 @@ function planRecordObjectsChunks(records, batchSize) {
21784
21942
  }
21785
21943
  return plans;
21786
21944
  }
21787
- function sleep(ms) {
21788
- return new Promise((resolve2) => setTimeout(resolve2, ms));
21789
- }
21790
- function withTimeout(promise, timeoutMs, label) {
21791
- let timer = null;
21792
- const timeout = new Promise((_, reject) => {
21793
- timer = setTimeout(() => {
21794
- reject(new Error(`${label} timed out after ${timeoutMs}ms`));
21795
- }, timeoutMs);
21796
- });
21797
- return Promise.race([promise, timeout]).finally(() => {
21798
- if (timer) {
21799
- clearTimeout(timer);
21800
- }
21801
- });
21802
- }
21803
- function isLocalControlUrl(url) {
21804
- try {
21805
- const parsed = new URL(url);
21806
- return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
21807
- } catch {
21808
- return false;
21809
- }
21810
- }
21811
- function isRetryableLocalWorkerRestart(status, body, url) {
21812
- return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
21813
- }
21814
- function isRetryableRecordObjectsError(error2) {
21815
- const message = error2 instanceof Error ? error2.message : String(error2);
21816
- return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out|bad gateway|too many requests|gateway timeout|control plane api error \((?:429|500|502|503|504)\)|graphql api error \((?:429|500|502|503|504)\)|failed to record batch/i.test(
21817
- message
21818
- );
21819
- }
21820
- function isRetryableEffectRegistrationError(error2) {
21821
- const message = error2 instanceof Error ? error2.message : String(error2);
21822
- return /timed out|websocket disconnected|websocket not connected|rpc timeout|worker restarted mid-request|network connection lost|bad gateway|gateway timeout|too many requests|(?:control plane|granular|graphql) api error \((?:429|500|502|503|504)\)/i.test(
21823
- message
21824
- );
21825
- }
21826
- function isRetryableSessionDataError(error2) {
21827
- const message = error2 instanceof Error ? error2.message : String(error2);
21828
- return /network connection lost|worker restarted mid-request|econnreset|socket connection was closed unexpectedly|bad gateway|gateway timeout|service unavailable|session data api error \((?:429|500|502|503|504)\)/i.test(
21829
- message
21830
- );
21831
- }
21832
21945
  function computeEffectKey2(effect) {
21833
21946
  const attachedClass = effect.className?.trim();
21834
21947
  if (!attachedClass) {
@@ -21883,115 +21996,6 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId, effectH
21883
21996
  url.searchParams.set("clientId", clientId);
21884
21997
  return url.toString();
21885
21998
  }
21886
- function createEmptyHeapSnapshot(now = Date.now()) {
21887
- return {
21888
- entriesByPath: {},
21889
- listsByName: {},
21890
- variablesByName: {},
21891
- updatedAt: now
21892
- };
21893
- }
21894
- function normalizeHeapSnapshot(raw) {
21895
- if (!raw || typeof raw !== "object") {
21896
- return createEmptyHeapSnapshot();
21897
- }
21898
- const heap = raw;
21899
- return {
21900
- entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
21901
- listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
21902
- variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
21903
- updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
21904
- };
21905
- }
21906
- function normalizeGraphPathSegment(value) {
21907
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
21908
- }
21909
- function extractRecordIdFromGraphPath(path7, className) {
21910
- const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
21911
- if (path7.startsWith(normalizedPrefix)) {
21912
- return path7.slice(normalizedPrefix.length);
21913
- }
21914
- const legacyPrefix = `${className}_`;
21915
- if (path7.startsWith(legacyPrefix)) {
21916
- return path7.slice(legacyPrefix.length);
21917
- }
21918
- return path7;
21919
- }
21920
- function toRecordSearchResult(className, node) {
21921
- const path7 = typeof node.path === "string" ? node.path : "";
21922
- if (!path7) return null;
21923
- const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
21924
- (submodel) => {
21925
- const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
21926
- if (!name) return [];
21927
- if (typeof submodel.string_value === "string") {
21928
- return [{ name, type: "string", value: submodel.string_value }];
21929
- }
21930
- if (typeof submodel.number_value === "number") {
21931
- return [{ name, type: "number", value: submodel.number_value }];
21932
- }
21933
- if (typeof submodel.boolean_value === "boolean") {
21934
- return [
21935
- {
21936
- name,
21937
- type: "boolean",
21938
- value: submodel.boolean_value
21939
- }
21940
- ];
21941
- }
21942
- return [];
21943
- }
21944
- ) : [];
21945
- return {
21946
- path: path7,
21947
- className,
21948
- id: extractRecordIdFromGraphPath(path7, className),
21949
- label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path7, className),
21950
- description: typeof node.description === "string" && node.description.trim() ? node.description : null,
21951
- fields
21952
- };
21953
- }
21954
- function normalizeRecordSearchText(value) {
21955
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
21956
- }
21957
- function rankRecordSearchResult(result, query, index) {
21958
- const normalizedQuery = normalizeRecordSearchText(query);
21959
- if (!normalizedQuery) {
21960
- return index;
21961
- }
21962
- const label = normalizeRecordSearchText(result.label || "");
21963
- const id = normalizeRecordSearchText(result.id || "");
21964
- const path7 = normalizeRecordSearchText(result.path || "");
21965
- const className = normalizeRecordSearchText(result.className || "");
21966
- const searchable = [label, id, path7, className].filter(Boolean);
21967
- if (label === normalizedQuery) return index;
21968
- if (id === normalizedQuery || path7 === normalizedQuery) return 100 + index;
21969
- if (label.startsWith(normalizedQuery)) return 200 + index;
21970
- if (searchable.some((value) => value.startsWith(normalizedQuery))) {
21971
- return 300 + index;
21972
- }
21973
- if (label.includes(normalizedQuery)) return 400 + index;
21974
- if (searchable.some((value) => value.includes(normalizedQuery))) {
21975
- return 500 + index;
21976
- }
21977
- return 900 + index;
21978
- }
21979
- function deriveRuntimeBaseUrl(apiEndpoint) {
21980
- try {
21981
- const endpoint = new URL(apiEndpoint);
21982
- const graphqlSuffix = "/orchestrator/graphql";
21983
- if (endpoint.pathname.endsWith(graphqlSuffix)) {
21984
- endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
21985
- } else if (endpoint.pathname.endsWith("/graphql")) {
21986
- endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
21987
- }
21988
- endpoint.search = "";
21989
- endpoint.hash = "";
21990
- return endpoint.toString().replace(/\/$/, "");
21991
- } catch {
21992
- return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
21993
- }
21994
- }
21995
21999
  function normalizeSubject(subject) {
21996
22000
  const granularId = subject.granularId || subject.subjectId;
21997
22001
  const userId = subject.userId || subject.identityId || granularId;
package/dist/index.js CHANGED
@@ -11464,6 +11464,164 @@ async function invokeRegisteredEffect(effectMap, request) {
11464
11464
  return resolved.handler(request.input, context);
11465
11465
  }
11466
11466
 
11467
+ // src/client-normalizers.ts
11468
+ function createEmptyHeapSnapshot(now = Date.now()) {
11469
+ return {
11470
+ entriesByPath: {},
11471
+ listsByName: {},
11472
+ variablesByName: {},
11473
+ updatedAt: now
11474
+ };
11475
+ }
11476
+ function normalizeHeapSnapshot(raw) {
11477
+ if (!raw || typeof raw !== "object") {
11478
+ return createEmptyHeapSnapshot();
11479
+ }
11480
+ const heap = raw;
11481
+ return {
11482
+ entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
11483
+ listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
11484
+ variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
11485
+ updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
11486
+ };
11487
+ }
11488
+ function normalizeGraphPathSegment(value) {
11489
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
11490
+ }
11491
+ function extractRecordIdFromGraphPath(path, className) {
11492
+ const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
11493
+ if (path.startsWith(normalizedPrefix)) {
11494
+ return path.slice(normalizedPrefix.length);
11495
+ }
11496
+ const legacyPrefix = `${className}_`;
11497
+ if (path.startsWith(legacyPrefix)) {
11498
+ return path.slice(legacyPrefix.length);
11499
+ }
11500
+ return path;
11501
+ }
11502
+ function toRecordSearchResult(className, node) {
11503
+ const path = typeof node.path === "string" ? node.path : "";
11504
+ if (!path) return null;
11505
+ const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
11506
+ (submodel) => {
11507
+ const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
11508
+ if (!name) return [];
11509
+ if (typeof submodel.string_value === "string") {
11510
+ return [{ name, type: "string", value: submodel.string_value }];
11511
+ }
11512
+ if (typeof submodel.number_value === "number") {
11513
+ return [{ name, type: "number", value: submodel.number_value }];
11514
+ }
11515
+ if (typeof submodel.boolean_value === "boolean") {
11516
+ return [
11517
+ {
11518
+ name,
11519
+ type: "boolean",
11520
+ value: submodel.boolean_value
11521
+ }
11522
+ ];
11523
+ }
11524
+ return [];
11525
+ }
11526
+ ) : [];
11527
+ return {
11528
+ path,
11529
+ className,
11530
+ id: extractRecordIdFromGraphPath(path, className),
11531
+ label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path, className),
11532
+ description: typeof node.description === "string" && node.description.trim() ? node.description : null,
11533
+ fields
11534
+ };
11535
+ }
11536
+ function normalizeRecordSearchText(value) {
11537
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
11538
+ }
11539
+ function rankRecordSearchResult(result, query, index) {
11540
+ const normalizedQuery = normalizeRecordSearchText(query);
11541
+ if (!normalizedQuery) {
11542
+ return index;
11543
+ }
11544
+ const label = normalizeRecordSearchText(result.label || "");
11545
+ const id = normalizeRecordSearchText(result.id || "");
11546
+ const path = normalizeRecordSearchText(result.path || "");
11547
+ const className = normalizeRecordSearchText(result.className || "");
11548
+ const searchable = [label, id, path, className].filter(Boolean);
11549
+ if (label === normalizedQuery) return index;
11550
+ if (id === normalizedQuery || path === normalizedQuery) return 100 + index;
11551
+ if (label.startsWith(normalizedQuery)) return 200 + index;
11552
+ if (searchable.some((value) => value.startsWith(normalizedQuery))) {
11553
+ return 300 + index;
11554
+ }
11555
+ if (label.includes(normalizedQuery)) return 400 + index;
11556
+ if (searchable.some((value) => value.includes(normalizedQuery))) {
11557
+ return 500 + index;
11558
+ }
11559
+ return 900 + index;
11560
+ }
11561
+ function deriveRuntimeBaseUrl(apiEndpoint) {
11562
+ try {
11563
+ const endpoint = new URL(apiEndpoint);
11564
+ const graphqlSuffix = "/orchestrator/graphql";
11565
+ if (endpoint.pathname.endsWith(graphqlSuffix)) {
11566
+ endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
11567
+ } else if (endpoint.pathname.endsWith("/graphql")) {
11568
+ endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
11569
+ }
11570
+ endpoint.search = "";
11571
+ endpoint.hash = "";
11572
+ return endpoint.toString().replace(/\/$/, "");
11573
+ } catch {
11574
+ return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
11575
+ }
11576
+ }
11577
+
11578
+ // src/client-transport.ts
11579
+ function sleep(ms) {
11580
+ return new Promise((resolve) => setTimeout(resolve, ms));
11581
+ }
11582
+ function withTimeout(promise, timeoutMs, label) {
11583
+ let timer = null;
11584
+ const timeout = new Promise((_, reject) => {
11585
+ timer = setTimeout(() => {
11586
+ reject(new Error(`${label} timed out after ${timeoutMs}ms`));
11587
+ }, timeoutMs);
11588
+ });
11589
+ return Promise.race([promise, timeout]).finally(() => {
11590
+ if (timer) {
11591
+ clearTimeout(timer);
11592
+ }
11593
+ });
11594
+ }
11595
+ function isLocalControlUrl(url) {
11596
+ try {
11597
+ const parsed = new URL(url);
11598
+ return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
11599
+ } catch {
11600
+ return false;
11601
+ }
11602
+ }
11603
+ function isRetryableLocalWorkerRestart(status, body, url) {
11604
+ return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
11605
+ }
11606
+ function isRetryableRecordObjectsError(error) {
11607
+ const message = error instanceof Error ? error.message : String(error);
11608
+ return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out|bad gateway|too many requests|gateway timeout|control plane api error \((?:429|500|502|503|504)\)|graphql api error \((?:429|500|502|503|504)\)|failed to record batch/i.test(
11609
+ message
11610
+ );
11611
+ }
11612
+ function isRetryableEffectRegistrationError(error) {
11613
+ const message = error instanceof Error ? error.message : String(error);
11614
+ return /timed out|websocket disconnected|websocket not connected|rpc timeout|worker restarted mid-request|network connection lost|bad gateway|gateway timeout|too many requests|(?:control plane|granular|graphql) api error \((?:429|500|502|503|504)\)/i.test(
11615
+ message
11616
+ );
11617
+ }
11618
+ function isRetryableSessionDataError(error) {
11619
+ const message = error instanceof Error ? error.message : String(error);
11620
+ return /network connection lost|worker restarted mid-request|econnreset|socket connection was closed unexpectedly|bad gateway|gateway timeout|service unavailable|session data api error \((?:429|500|502|503|504)\)/i.test(
11621
+ message
11622
+ );
11623
+ }
11624
+
11467
11625
  // src/spend.ts
11468
11626
  function toGranularHttpBase(apiUrl) {
11469
11627
  const url = new URL(apiUrl);
@@ -12949,51 +13107,6 @@ function planRecordObjectsChunks(records, batchSize) {
12949
13107
  }
12950
13108
  return plans;
12951
13109
  }
12952
- function sleep(ms) {
12953
- return new Promise((resolve) => setTimeout(resolve, ms));
12954
- }
12955
- function withTimeout(promise, timeoutMs, label) {
12956
- let timer = null;
12957
- const timeout = new Promise((_, reject) => {
12958
- timer = setTimeout(() => {
12959
- reject(new Error(`${label} timed out after ${timeoutMs}ms`));
12960
- }, timeoutMs);
12961
- });
12962
- return Promise.race([promise, timeout]).finally(() => {
12963
- if (timer) {
12964
- clearTimeout(timer);
12965
- }
12966
- });
12967
- }
12968
- function isLocalControlUrl(url) {
12969
- try {
12970
- const parsed = new URL(url);
12971
- return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
12972
- } catch {
12973
- return false;
12974
- }
12975
- }
12976
- function isRetryableLocalWorkerRestart(status, body, url) {
12977
- return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
12978
- }
12979
- function isRetryableRecordObjectsError(error) {
12980
- const message = error instanceof Error ? error.message : String(error);
12981
- return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out|bad gateway|too many requests|gateway timeout|control plane api error \((?:429|500|502|503|504)\)|graphql api error \((?:429|500|502|503|504)\)|failed to record batch/i.test(
12982
- message
12983
- );
12984
- }
12985
- function isRetryableEffectRegistrationError(error) {
12986
- const message = error instanceof Error ? error.message : String(error);
12987
- return /timed out|websocket disconnected|websocket not connected|rpc timeout|worker restarted mid-request|network connection lost|bad gateway|gateway timeout|too many requests|(?:control plane|granular|graphql) api error \((?:429|500|502|503|504)\)/i.test(
12988
- message
12989
- );
12990
- }
12991
- function isRetryableSessionDataError(error) {
12992
- const message = error instanceof Error ? error.message : String(error);
12993
- return /network connection lost|worker restarted mid-request|econnreset|socket connection was closed unexpectedly|bad gateway|gateway timeout|service unavailable|session data api error \((?:429|500|502|503|504)\)/i.test(
12994
- message
12995
- );
12996
- }
12997
13110
  function computeEffectKey2(effect) {
12998
13111
  const attachedClass = effect.className?.trim();
12999
13112
  if (!attachedClass) {
@@ -13048,115 +13161,6 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId, effectH
13048
13161
  url.searchParams.set("clientId", clientId);
13049
13162
  return url.toString();
13050
13163
  }
13051
- function createEmptyHeapSnapshot(now = Date.now()) {
13052
- return {
13053
- entriesByPath: {},
13054
- listsByName: {},
13055
- variablesByName: {},
13056
- updatedAt: now
13057
- };
13058
- }
13059
- function normalizeHeapSnapshot(raw) {
13060
- if (!raw || typeof raw !== "object") {
13061
- return createEmptyHeapSnapshot();
13062
- }
13063
- const heap = raw;
13064
- return {
13065
- entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
13066
- listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
13067
- variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
13068
- updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
13069
- };
13070
- }
13071
- function normalizeGraphPathSegment(value) {
13072
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
13073
- }
13074
- function extractRecordIdFromGraphPath(path, className) {
13075
- const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
13076
- if (path.startsWith(normalizedPrefix)) {
13077
- return path.slice(normalizedPrefix.length);
13078
- }
13079
- const legacyPrefix = `${className}_`;
13080
- if (path.startsWith(legacyPrefix)) {
13081
- return path.slice(legacyPrefix.length);
13082
- }
13083
- return path;
13084
- }
13085
- function toRecordSearchResult(className, node) {
13086
- const path = typeof node.path === "string" ? node.path : "";
13087
- if (!path) return null;
13088
- const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
13089
- (submodel) => {
13090
- const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
13091
- if (!name) return [];
13092
- if (typeof submodel.string_value === "string") {
13093
- return [{ name, type: "string", value: submodel.string_value }];
13094
- }
13095
- if (typeof submodel.number_value === "number") {
13096
- return [{ name, type: "number", value: submodel.number_value }];
13097
- }
13098
- if (typeof submodel.boolean_value === "boolean") {
13099
- return [
13100
- {
13101
- name,
13102
- type: "boolean",
13103
- value: submodel.boolean_value
13104
- }
13105
- ];
13106
- }
13107
- return [];
13108
- }
13109
- ) : [];
13110
- return {
13111
- path,
13112
- className,
13113
- id: extractRecordIdFromGraphPath(path, className),
13114
- label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path, className),
13115
- description: typeof node.description === "string" && node.description.trim() ? node.description : null,
13116
- fields
13117
- };
13118
- }
13119
- function normalizeRecordSearchText(value) {
13120
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
13121
- }
13122
- function rankRecordSearchResult(result, query, index) {
13123
- const normalizedQuery = normalizeRecordSearchText(query);
13124
- if (!normalizedQuery) {
13125
- return index;
13126
- }
13127
- const label = normalizeRecordSearchText(result.label || "");
13128
- const id = normalizeRecordSearchText(result.id || "");
13129
- const path = normalizeRecordSearchText(result.path || "");
13130
- const className = normalizeRecordSearchText(result.className || "");
13131
- const searchable = [label, id, path, className].filter(Boolean);
13132
- if (label === normalizedQuery) return index;
13133
- if (id === normalizedQuery || path === normalizedQuery) return 100 + index;
13134
- if (label.startsWith(normalizedQuery)) return 200 + index;
13135
- if (searchable.some((value) => value.startsWith(normalizedQuery))) {
13136
- return 300 + index;
13137
- }
13138
- if (label.includes(normalizedQuery)) return 400 + index;
13139
- if (searchable.some((value) => value.includes(normalizedQuery))) {
13140
- return 500 + index;
13141
- }
13142
- return 900 + index;
13143
- }
13144
- function deriveRuntimeBaseUrl(apiEndpoint) {
13145
- try {
13146
- const endpoint = new URL(apiEndpoint);
13147
- const graphqlSuffix = "/orchestrator/graphql";
13148
- if (endpoint.pathname.endsWith(graphqlSuffix)) {
13149
- endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
13150
- } else if (endpoint.pathname.endsWith("/graphql")) {
13151
- endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
13152
- }
13153
- endpoint.search = "";
13154
- endpoint.hash = "";
13155
- return endpoint.toString().replace(/\/$/, "");
13156
- } catch {
13157
- return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
13158
- }
13159
- }
13160
13164
  function normalizeSubject(subject) {
13161
13165
  const granularId = subject.granularId || subject.subjectId;
13162
13166
  const userId = subject.userId || subject.identityId || granularId;