@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/agent-evals.js +158 -154
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +158 -154
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/cli/index.js +158 -154
- package/dist/index.js +158 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -154
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11442,6 +11442,164 @@ async function invokeRegisteredEffect(effectMap, request) {
|
|
|
11442
11442
|
return resolved.handler(request.input, context);
|
|
11443
11443
|
}
|
|
11444
11444
|
|
|
11445
|
+
// src/client-normalizers.ts
|
|
11446
|
+
function createEmptyHeapSnapshot(now = Date.now()) {
|
|
11447
|
+
return {
|
|
11448
|
+
entriesByPath: {},
|
|
11449
|
+
listsByName: {},
|
|
11450
|
+
variablesByName: {},
|
|
11451
|
+
updatedAt: now
|
|
11452
|
+
};
|
|
11453
|
+
}
|
|
11454
|
+
function normalizeHeapSnapshot(raw) {
|
|
11455
|
+
if (!raw || typeof raw !== "object") {
|
|
11456
|
+
return createEmptyHeapSnapshot();
|
|
11457
|
+
}
|
|
11458
|
+
const heap = raw;
|
|
11459
|
+
return {
|
|
11460
|
+
entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
|
|
11461
|
+
listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
|
|
11462
|
+
variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
|
|
11463
|
+
updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
|
|
11464
|
+
};
|
|
11465
|
+
}
|
|
11466
|
+
function normalizeGraphPathSegment(value) {
|
|
11467
|
+
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
11468
|
+
}
|
|
11469
|
+
function extractRecordIdFromGraphPath(path, className) {
|
|
11470
|
+
const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
|
|
11471
|
+
if (path.startsWith(normalizedPrefix)) {
|
|
11472
|
+
return path.slice(normalizedPrefix.length);
|
|
11473
|
+
}
|
|
11474
|
+
const legacyPrefix = `${className}_`;
|
|
11475
|
+
if (path.startsWith(legacyPrefix)) {
|
|
11476
|
+
return path.slice(legacyPrefix.length);
|
|
11477
|
+
}
|
|
11478
|
+
return path;
|
|
11479
|
+
}
|
|
11480
|
+
function toRecordSearchResult(className, node) {
|
|
11481
|
+
const path = typeof node.path === "string" ? node.path : "";
|
|
11482
|
+
if (!path) return null;
|
|
11483
|
+
const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
|
|
11484
|
+
(submodel) => {
|
|
11485
|
+
const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
|
|
11486
|
+
if (!name) return [];
|
|
11487
|
+
if (typeof submodel.string_value === "string") {
|
|
11488
|
+
return [{ name, type: "string", value: submodel.string_value }];
|
|
11489
|
+
}
|
|
11490
|
+
if (typeof submodel.number_value === "number") {
|
|
11491
|
+
return [{ name, type: "number", value: submodel.number_value }];
|
|
11492
|
+
}
|
|
11493
|
+
if (typeof submodel.boolean_value === "boolean") {
|
|
11494
|
+
return [
|
|
11495
|
+
{
|
|
11496
|
+
name,
|
|
11497
|
+
type: "boolean",
|
|
11498
|
+
value: submodel.boolean_value
|
|
11499
|
+
}
|
|
11500
|
+
];
|
|
11501
|
+
}
|
|
11502
|
+
return [];
|
|
11503
|
+
}
|
|
11504
|
+
) : [];
|
|
11505
|
+
return {
|
|
11506
|
+
path,
|
|
11507
|
+
className,
|
|
11508
|
+
id: extractRecordIdFromGraphPath(path, className),
|
|
11509
|
+
label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path, className),
|
|
11510
|
+
description: typeof node.description === "string" && node.description.trim() ? node.description : null,
|
|
11511
|
+
fields
|
|
11512
|
+
};
|
|
11513
|
+
}
|
|
11514
|
+
function normalizeRecordSearchText(value) {
|
|
11515
|
+
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
|
|
11516
|
+
}
|
|
11517
|
+
function rankRecordSearchResult(result, query, index) {
|
|
11518
|
+
const normalizedQuery = normalizeRecordSearchText(query);
|
|
11519
|
+
if (!normalizedQuery) {
|
|
11520
|
+
return index;
|
|
11521
|
+
}
|
|
11522
|
+
const label = normalizeRecordSearchText(result.label || "");
|
|
11523
|
+
const id = normalizeRecordSearchText(result.id || "");
|
|
11524
|
+
const path = normalizeRecordSearchText(result.path || "");
|
|
11525
|
+
const className = normalizeRecordSearchText(result.className || "");
|
|
11526
|
+
const searchable = [label, id, path, className].filter(Boolean);
|
|
11527
|
+
if (label === normalizedQuery) return index;
|
|
11528
|
+
if (id === normalizedQuery || path === normalizedQuery) return 100 + index;
|
|
11529
|
+
if (label.startsWith(normalizedQuery)) return 200 + index;
|
|
11530
|
+
if (searchable.some((value) => value.startsWith(normalizedQuery))) {
|
|
11531
|
+
return 300 + index;
|
|
11532
|
+
}
|
|
11533
|
+
if (label.includes(normalizedQuery)) return 400 + index;
|
|
11534
|
+
if (searchable.some((value) => value.includes(normalizedQuery))) {
|
|
11535
|
+
return 500 + index;
|
|
11536
|
+
}
|
|
11537
|
+
return 900 + index;
|
|
11538
|
+
}
|
|
11539
|
+
function deriveRuntimeBaseUrl(apiEndpoint) {
|
|
11540
|
+
try {
|
|
11541
|
+
const endpoint = new URL(apiEndpoint);
|
|
11542
|
+
const graphqlSuffix = "/orchestrator/graphql";
|
|
11543
|
+
if (endpoint.pathname.endsWith(graphqlSuffix)) {
|
|
11544
|
+
endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
|
|
11545
|
+
} else if (endpoint.pathname.endsWith("/graphql")) {
|
|
11546
|
+
endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
|
|
11547
|
+
}
|
|
11548
|
+
endpoint.search = "";
|
|
11549
|
+
endpoint.hash = "";
|
|
11550
|
+
return endpoint.toString().replace(/\/$/, "");
|
|
11551
|
+
} catch {
|
|
11552
|
+
return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
|
|
11553
|
+
}
|
|
11554
|
+
}
|
|
11555
|
+
|
|
11556
|
+
// src/client-transport.ts
|
|
11557
|
+
function sleep(ms) {
|
|
11558
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11559
|
+
}
|
|
11560
|
+
function withTimeout(promise, timeoutMs, label) {
|
|
11561
|
+
let timer = null;
|
|
11562
|
+
const timeout = new Promise((_, reject) => {
|
|
11563
|
+
timer = setTimeout(() => {
|
|
11564
|
+
reject(new Error(`${label} timed out after ${timeoutMs}ms`));
|
|
11565
|
+
}, timeoutMs);
|
|
11566
|
+
});
|
|
11567
|
+
return Promise.race([promise, timeout]).finally(() => {
|
|
11568
|
+
if (timer) {
|
|
11569
|
+
clearTimeout(timer);
|
|
11570
|
+
}
|
|
11571
|
+
});
|
|
11572
|
+
}
|
|
11573
|
+
function isLocalControlUrl(url) {
|
|
11574
|
+
try {
|
|
11575
|
+
const parsed = new URL(url);
|
|
11576
|
+
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
11577
|
+
} catch {
|
|
11578
|
+
return false;
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
function isRetryableLocalWorkerRestart(status, body, url) {
|
|
11582
|
+
return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
|
|
11583
|
+
}
|
|
11584
|
+
function isRetryableRecordObjectsError(error) {
|
|
11585
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11586
|
+
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(
|
|
11587
|
+
message
|
|
11588
|
+
);
|
|
11589
|
+
}
|
|
11590
|
+
function isRetryableEffectRegistrationError(error) {
|
|
11591
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11592
|
+
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(
|
|
11593
|
+
message
|
|
11594
|
+
);
|
|
11595
|
+
}
|
|
11596
|
+
function isRetryableSessionDataError(error) {
|
|
11597
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11598
|
+
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(
|
|
11599
|
+
message
|
|
11600
|
+
);
|
|
11601
|
+
}
|
|
11602
|
+
|
|
11445
11603
|
// src/spend.ts
|
|
11446
11604
|
function toGranularHttpBase(apiUrl) {
|
|
11447
11605
|
const url = new URL(apiUrl);
|
|
@@ -12927,51 +13085,6 @@ function planRecordObjectsChunks(records, batchSize) {
|
|
|
12927
13085
|
}
|
|
12928
13086
|
return plans;
|
|
12929
13087
|
}
|
|
12930
|
-
function sleep(ms) {
|
|
12931
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
12932
|
-
}
|
|
12933
|
-
function withTimeout(promise, timeoutMs, label) {
|
|
12934
|
-
let timer = null;
|
|
12935
|
-
const timeout = new Promise((_, reject) => {
|
|
12936
|
-
timer = setTimeout(() => {
|
|
12937
|
-
reject(new Error(`${label} timed out after ${timeoutMs}ms`));
|
|
12938
|
-
}, timeoutMs);
|
|
12939
|
-
});
|
|
12940
|
-
return Promise.race([promise, timeout]).finally(() => {
|
|
12941
|
-
if (timer) {
|
|
12942
|
-
clearTimeout(timer);
|
|
12943
|
-
}
|
|
12944
|
-
});
|
|
12945
|
-
}
|
|
12946
|
-
function isLocalControlUrl(url) {
|
|
12947
|
-
try {
|
|
12948
|
-
const parsed = new URL(url);
|
|
12949
|
-
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
12950
|
-
} catch {
|
|
12951
|
-
return false;
|
|
12952
|
-
}
|
|
12953
|
-
}
|
|
12954
|
-
function isRetryableLocalWorkerRestart(status, body, url) {
|
|
12955
|
-
return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
|
|
12956
|
-
}
|
|
12957
|
-
function isRetryableRecordObjectsError(error) {
|
|
12958
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
12959
|
-
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(
|
|
12960
|
-
message
|
|
12961
|
-
);
|
|
12962
|
-
}
|
|
12963
|
-
function isRetryableEffectRegistrationError(error) {
|
|
12964
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
12965
|
-
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(
|
|
12966
|
-
message
|
|
12967
|
-
);
|
|
12968
|
-
}
|
|
12969
|
-
function isRetryableSessionDataError(error) {
|
|
12970
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
12971
|
-
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(
|
|
12972
|
-
message
|
|
12973
|
-
);
|
|
12974
|
-
}
|
|
12975
13088
|
function computeEffectKey2(effect) {
|
|
12976
13089
|
const attachedClass = effect.className?.trim();
|
|
12977
13090
|
if (!attachedClass) {
|
|
@@ -13026,115 +13139,6 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId, effectH
|
|
|
13026
13139
|
url.searchParams.set("clientId", clientId);
|
|
13027
13140
|
return url.toString();
|
|
13028
13141
|
}
|
|
13029
|
-
function createEmptyHeapSnapshot(now = Date.now()) {
|
|
13030
|
-
return {
|
|
13031
|
-
entriesByPath: {},
|
|
13032
|
-
listsByName: {},
|
|
13033
|
-
variablesByName: {},
|
|
13034
|
-
updatedAt: now
|
|
13035
|
-
};
|
|
13036
|
-
}
|
|
13037
|
-
function normalizeHeapSnapshot(raw) {
|
|
13038
|
-
if (!raw || typeof raw !== "object") {
|
|
13039
|
-
return createEmptyHeapSnapshot();
|
|
13040
|
-
}
|
|
13041
|
-
const heap = raw;
|
|
13042
|
-
return {
|
|
13043
|
-
entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
|
|
13044
|
-
listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
|
|
13045
|
-
variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
|
|
13046
|
-
updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
|
|
13047
|
-
};
|
|
13048
|
-
}
|
|
13049
|
-
function normalizeGraphPathSegment(value) {
|
|
13050
|
-
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
13051
|
-
}
|
|
13052
|
-
function extractRecordIdFromGraphPath(path, className) {
|
|
13053
|
-
const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
|
|
13054
|
-
if (path.startsWith(normalizedPrefix)) {
|
|
13055
|
-
return path.slice(normalizedPrefix.length);
|
|
13056
|
-
}
|
|
13057
|
-
const legacyPrefix = `${className}_`;
|
|
13058
|
-
if (path.startsWith(legacyPrefix)) {
|
|
13059
|
-
return path.slice(legacyPrefix.length);
|
|
13060
|
-
}
|
|
13061
|
-
return path;
|
|
13062
|
-
}
|
|
13063
|
-
function toRecordSearchResult(className, node) {
|
|
13064
|
-
const path = typeof node.path === "string" ? node.path : "";
|
|
13065
|
-
if (!path) return null;
|
|
13066
|
-
const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
|
|
13067
|
-
(submodel) => {
|
|
13068
|
-
const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
|
|
13069
|
-
if (!name) return [];
|
|
13070
|
-
if (typeof submodel.string_value === "string") {
|
|
13071
|
-
return [{ name, type: "string", value: submodel.string_value }];
|
|
13072
|
-
}
|
|
13073
|
-
if (typeof submodel.number_value === "number") {
|
|
13074
|
-
return [{ name, type: "number", value: submodel.number_value }];
|
|
13075
|
-
}
|
|
13076
|
-
if (typeof submodel.boolean_value === "boolean") {
|
|
13077
|
-
return [
|
|
13078
|
-
{
|
|
13079
|
-
name,
|
|
13080
|
-
type: "boolean",
|
|
13081
|
-
value: submodel.boolean_value
|
|
13082
|
-
}
|
|
13083
|
-
];
|
|
13084
|
-
}
|
|
13085
|
-
return [];
|
|
13086
|
-
}
|
|
13087
|
-
) : [];
|
|
13088
|
-
return {
|
|
13089
|
-
path,
|
|
13090
|
-
className,
|
|
13091
|
-
id: extractRecordIdFromGraphPath(path, className),
|
|
13092
|
-
label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path, className),
|
|
13093
|
-
description: typeof node.description === "string" && node.description.trim() ? node.description : null,
|
|
13094
|
-
fields
|
|
13095
|
-
};
|
|
13096
|
-
}
|
|
13097
|
-
function normalizeRecordSearchText(value) {
|
|
13098
|
-
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
|
|
13099
|
-
}
|
|
13100
|
-
function rankRecordSearchResult(result, query, index) {
|
|
13101
|
-
const normalizedQuery = normalizeRecordSearchText(query);
|
|
13102
|
-
if (!normalizedQuery) {
|
|
13103
|
-
return index;
|
|
13104
|
-
}
|
|
13105
|
-
const label = normalizeRecordSearchText(result.label || "");
|
|
13106
|
-
const id = normalizeRecordSearchText(result.id || "");
|
|
13107
|
-
const path = normalizeRecordSearchText(result.path || "");
|
|
13108
|
-
const className = normalizeRecordSearchText(result.className || "");
|
|
13109
|
-
const searchable = [label, id, path, className].filter(Boolean);
|
|
13110
|
-
if (label === normalizedQuery) return index;
|
|
13111
|
-
if (id === normalizedQuery || path === normalizedQuery) return 100 + index;
|
|
13112
|
-
if (label.startsWith(normalizedQuery)) return 200 + index;
|
|
13113
|
-
if (searchable.some((value) => value.startsWith(normalizedQuery))) {
|
|
13114
|
-
return 300 + index;
|
|
13115
|
-
}
|
|
13116
|
-
if (label.includes(normalizedQuery)) return 400 + index;
|
|
13117
|
-
if (searchable.some((value) => value.includes(normalizedQuery))) {
|
|
13118
|
-
return 500 + index;
|
|
13119
|
-
}
|
|
13120
|
-
return 900 + index;
|
|
13121
|
-
}
|
|
13122
|
-
function deriveRuntimeBaseUrl(apiEndpoint) {
|
|
13123
|
-
try {
|
|
13124
|
-
const endpoint = new URL(apiEndpoint);
|
|
13125
|
-
const graphqlSuffix = "/orchestrator/graphql";
|
|
13126
|
-
if (endpoint.pathname.endsWith(graphqlSuffix)) {
|
|
13127
|
-
endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
|
|
13128
|
-
} else if (endpoint.pathname.endsWith("/graphql")) {
|
|
13129
|
-
endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
|
|
13130
|
-
}
|
|
13131
|
-
endpoint.search = "";
|
|
13132
|
-
endpoint.hash = "";
|
|
13133
|
-
return endpoint.toString().replace(/\/$/, "");
|
|
13134
|
-
} catch {
|
|
13135
|
-
return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
|
|
13136
|
-
}
|
|
13137
|
-
}
|
|
13138
13142
|
function normalizeSubject(subject) {
|
|
13139
13143
|
const granularId = subject.granularId || subject.subjectId;
|
|
13140
13144
|
const userId = subject.userId || subject.identityId || granularId;
|