deepline 0.3.230 → 0.3.232
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/bundling-sources/sdk/src/client.ts +16 -523
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/tool-calls.ts +530 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-work.ts +11 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +33 -415
- package/dist/bundling-sources/shared_libs/play-runtime/play-http-request.ts +419 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-reliability-policy.ts +10 -0
- package/dist/cli/index.js +838 -805
- package/dist/cli/index.mjs +838 -800
- package/dist/index.d.mts +191 -190
- package/dist/index.d.ts +191 -190
- package/dist/index.js +489 -472
- package/dist/index.mjs +489 -472
- package/dist/install-integrity.json +2 -0
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +1 -1
- package/dist/release.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -814,6 +814,409 @@ function resolveConfig(options) {
|
|
|
814
814
|
};
|
|
815
815
|
}
|
|
816
816
|
|
|
817
|
+
// ../integration-contracts/theirstack/execution-policy.ts
|
|
818
|
+
var THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS = 135e3;
|
|
819
|
+
var THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS = 6e4 + THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS + 15e3;
|
|
820
|
+
var THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS = 21e4;
|
|
821
|
+
var LONG_JOB_SEARCH_WINDOW_MS = 365 * 24 * 60 * 60 * 1e3;
|
|
822
|
+
var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
823
|
+
function parseDateOnly(value) {
|
|
824
|
+
if (typeof value !== "string" || !DATE_ONLY_PATTERN.test(value)) {
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
const timestamp = Date.parse(`${value}T00:00:00.000Z`);
|
|
828
|
+
if (!Number.isFinite(timestamp)) {
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
return new Date(timestamp).toISOString().slice(0, 10) === value ? timestamp : null;
|
|
832
|
+
}
|
|
833
|
+
function usesLongExplicitDateWindow(payload) {
|
|
834
|
+
const postedAtGte = parseDateOnly(payload.posted_at_gte);
|
|
835
|
+
const postedAtLte = parseDateOnly(payload.posted_at_lte);
|
|
836
|
+
if (postedAtGte !== null && postedAtLte !== null) {
|
|
837
|
+
return postedAtLte - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
838
|
+
}
|
|
839
|
+
if (postedAtGte !== null) {
|
|
840
|
+
return Date.now() - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
841
|
+
}
|
|
842
|
+
return postedAtLte !== null && payload.posted_at_gte == null;
|
|
843
|
+
}
|
|
844
|
+
function parseMaxAgeDays(value) {
|
|
845
|
+
if (typeof value === "number") {
|
|
846
|
+
return Number.isFinite(value) ? value : null;
|
|
847
|
+
}
|
|
848
|
+
if (typeof value !== "string" || !/^-?\d+$/.test(value.trim())) {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
const parsed = Number(value.trim());
|
|
852
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
853
|
+
}
|
|
854
|
+
function usesExtendedTheirstackJobSearchBudget(endpointId, payload) {
|
|
855
|
+
if (endpointId !== "theirstack_job_search") {
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
if (payload.include_total_results === true) {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
const maxAgeDays = parseMaxAgeDays(payload.posted_at_max_age_days);
|
|
862
|
+
return maxAgeDays !== null && maxAgeDays >= 365 ? true : usesLongExplicitDateWindow(payload);
|
|
863
|
+
}
|
|
864
|
+
function resolveTheirstackClientTimeoutMs(endpointId, payload) {
|
|
865
|
+
if (endpointId === "theirstack_company_search") {
|
|
866
|
+
return THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS;
|
|
867
|
+
}
|
|
868
|
+
return usesExtendedTheirstackJobSearchBudget(endpointId, payload) ? THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS : null;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// ../integration-contracts/waterfall/execution-policy.ts
|
|
872
|
+
var WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS = 18e4;
|
|
873
|
+
var WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
874
|
+
"prospector",
|
|
875
|
+
"deepline_native_prospector"
|
|
876
|
+
]);
|
|
877
|
+
function resolveWaterfallClientTimeoutMs(toolId) {
|
|
878
|
+
return WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase()) ? WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS : null;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// ../integration-contracts/bettercontact/execution-policy.ts
|
|
882
|
+
var BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS = 12e4;
|
|
883
|
+
var BETTERCONTACT_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
884
|
+
"bettercontact_enrich",
|
|
885
|
+
"bettercontact_bulk_enrich"
|
|
886
|
+
]);
|
|
887
|
+
function usesExtendedBetterContactLauncherBudget(toolId) {
|
|
888
|
+
return BETTERCONTACT_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase());
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// ../plays/tool-response-contract.ts
|
|
892
|
+
var RAW_V2_TOOL_RESPONSE_CONTRACT = "raw-v2";
|
|
893
|
+
function legacyRawFromToolResponseRawV2(rawV2, view, responseMeta) {
|
|
894
|
+
const legacyRaw = view === "data" && rawV2 && typeof rawV2 === "object" && !Array.isArray(rawV2) ? rawV2.data : rawV2;
|
|
895
|
+
const deeplineBilling = responseMeta?.deepline_billing;
|
|
896
|
+
if (view === "rawV2" && deeplineBilling !== void 0 && legacyRaw && typeof legacyRaw === "object" && !Array.isArray(legacyRaw)) {
|
|
897
|
+
return {
|
|
898
|
+
...legacyRaw,
|
|
899
|
+
deepline_billing: deeplineBilling
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
return legacyRaw;
|
|
903
|
+
}
|
|
904
|
+
function providerMetaFromToolResponseRawV2(rawV2, view) {
|
|
905
|
+
if (view !== "data" || !rawV2 || typeof rawV2 !== "object" || Array.isArray(rawV2)) {
|
|
906
|
+
return void 0;
|
|
907
|
+
}
|
|
908
|
+
const meta = rawV2.meta;
|
|
909
|
+
return meta && typeof meta === "object" && !Array.isArray(meta) ? meta : void 0;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// src/tool-calls.ts
|
|
913
|
+
var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
|
|
914
|
+
var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
|
|
915
|
+
var EXECUTE_RESPONSE_INTENT_HEADER = "x-deepline-execute-response-intent";
|
|
916
|
+
var RAW_V2_EXECUTE_RESPONSE_CONTRACT = RAW_V2_TOOL_RESPONSE_CONTRACT;
|
|
917
|
+
var DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
918
|
+
function validateExecutionIdempotencyKey(key) {
|
|
919
|
+
if (typeof key !== "string" || key.length < 1 || key.length > 200 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
|
|
920
|
+
throw new DeeplineError(
|
|
921
|
+
"Execution idempotency keys must be 1\u2013200 ASCII letters, digits, dots, underscores, colons, or hyphens.",
|
|
922
|
+
void 0,
|
|
923
|
+
"IDEMPOTENCY_KEY_INVALID"
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
function getExecutionRecoveryState(value) {
|
|
928
|
+
if (!isRecord2(value) || !isRecord2(value.executionRecovery)) return null;
|
|
929
|
+
const state = value.executionRecovery.state;
|
|
930
|
+
return state === "running" || state === "completed" || state === "outcome_unknown" ? state : null;
|
|
931
|
+
}
|
|
932
|
+
function isRecoverableExecutionAttemptError(error) {
|
|
933
|
+
if (error instanceof ToolExecutionError) {
|
|
934
|
+
return error.code === "EXECUTION_IN_PROGRESS" || error.origin === "deepline" && error.category === "network" && error.networkScope === "client_to_deepline";
|
|
935
|
+
}
|
|
936
|
+
return error instanceof DeeplineError && (error.code === "EXECUTION_IN_PROGRESS" || error.code?.startsWith("NETWORK_") === true && error.statusCode === void 0);
|
|
937
|
+
}
|
|
938
|
+
function isRecoverableExecutionLookupError(error) {
|
|
939
|
+
if (isRecoverableExecutionAttemptError(error)) return true;
|
|
940
|
+
return error instanceof DeeplineError && (error.statusCode === 429 || error.statusCode !== void 0 && error.statusCode >= 500);
|
|
941
|
+
}
|
|
942
|
+
function timeoutWithinRecoveryBudget(requestTimeoutMs, defaultRequestTimeoutMs, remainingMs) {
|
|
943
|
+
return Math.min(requestTimeoutMs ?? defaultRequestTimeoutMs, remainingMs);
|
|
944
|
+
}
|
|
945
|
+
function executionRecoveryError(input) {
|
|
946
|
+
return new ToolExecutionError(input.message, {
|
|
947
|
+
toolId: input.toolId,
|
|
948
|
+
provider: null,
|
|
949
|
+
operation: input.toolId,
|
|
950
|
+
code: input.code,
|
|
951
|
+
origin: "deepline",
|
|
952
|
+
category: input.code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown" : "conflict",
|
|
953
|
+
retryable: input.code !== "EXECUTION_OUTCOME_UNKNOWN",
|
|
954
|
+
statusCode: null,
|
|
955
|
+
requestId: null,
|
|
956
|
+
retryAfterMs: null,
|
|
957
|
+
networkKind: null,
|
|
958
|
+
networkScope: null,
|
|
959
|
+
publicDetails: { idempotencyKey: input.idempotencyKey }
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
963
|
+
var APIFY_SYNC_DEFAULT_TIMEOUT_MS = 3e5;
|
|
964
|
+
var APIFY_SYNC_RESPONSE_GRACE_MS = 9e4;
|
|
965
|
+
function resolveToolExecuteTimeoutMs(toolId, input) {
|
|
966
|
+
const normalized = toolId.trim().toLowerCase();
|
|
967
|
+
if (normalized === "apify_run_actor_sync") {
|
|
968
|
+
const requestedTimeoutMs = input.timeoutMs ?? APIFY_SYNC_DEFAULT_TIMEOUT_MS;
|
|
969
|
+
if (typeof requestedTimeoutMs === "number" && Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0) {
|
|
970
|
+
return Math.floor(requestedTimeoutMs) + APIFY_SYNC_RESPONSE_GRACE_MS;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
const theirstackTimeoutMs = resolveTheirstackClientTimeoutMs(
|
|
974
|
+
normalized,
|
|
975
|
+
input
|
|
976
|
+
);
|
|
977
|
+
if (theirstackTimeoutMs !== null) return theirstackTimeoutMs;
|
|
978
|
+
const waterfallTimeoutMs = resolveWaterfallClientTimeoutMs(normalized);
|
|
979
|
+
if (waterfallTimeoutMs !== null) return waterfallTimeoutMs;
|
|
980
|
+
if (usesExtendedBetterContactLauncherBudget(normalized)) {
|
|
981
|
+
return BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS;
|
|
982
|
+
}
|
|
983
|
+
return normalized === "deeplineagent" || normalized === "deeplineagent_deeplineagent" || normalized === "ai_inference" || normalized === "deeplineagent_ai_inference" || normalized === "ai_evaluate" || normalized === "deeplineagent_ai_evaluate" || normalized === "aiinference" ? DEEPLINEAGENT_EXECUTE_TIMEOUT_MS : void 0;
|
|
984
|
+
}
|
|
985
|
+
function isRecord2(value) {
|
|
986
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
987
|
+
}
|
|
988
|
+
function materializeToolExecutionResponse(response) {
|
|
989
|
+
const toolResponse = response.toolResponse;
|
|
990
|
+
if (!toolResponse && isRecord2(response.result)) {
|
|
991
|
+
const legacyResult = response.result;
|
|
992
|
+
if (Object.prototype.hasOwnProperty.call(legacyResult, "data")) {
|
|
993
|
+
const legacyMeta = isRecord2(legacyResult.meta) ? legacyResult.meta : void 0;
|
|
994
|
+
return {
|
|
995
|
+
...response,
|
|
996
|
+
toolResponse: {
|
|
997
|
+
raw: legacyResult.data,
|
|
998
|
+
...legacyMeta ? { meta: legacyMeta } : {}
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (!toolResponse || Object.prototype.hasOwnProperty.call(toolResponse, "raw")) {
|
|
1004
|
+
return response;
|
|
1005
|
+
}
|
|
1006
|
+
const rawV2 = toolResponse.rawV2;
|
|
1007
|
+
const view = toolResponse.view;
|
|
1008
|
+
const providerMeta = providerMetaFromToolResponseRawV2(
|
|
1009
|
+
rawV2,
|
|
1010
|
+
view ?? "rawV2"
|
|
1011
|
+
);
|
|
1012
|
+
const responseMeta = isRecord2(toolResponse.responseMeta) ? toolResponse.responseMeta : void 0;
|
|
1013
|
+
return {
|
|
1014
|
+
...response,
|
|
1015
|
+
toolResponse: {
|
|
1016
|
+
...toolResponse,
|
|
1017
|
+
raw: legacyRawFromToolResponseRawV2(
|
|
1018
|
+
rawV2,
|
|
1019
|
+
view ?? "rawV2",
|
|
1020
|
+
responseMeta
|
|
1021
|
+
),
|
|
1022
|
+
...toolResponse.meta || providerMeta || responseMeta ? {
|
|
1023
|
+
meta: {
|
|
1024
|
+
...toolResponse.meta ?? {},
|
|
1025
|
+
...providerMeta ?? {},
|
|
1026
|
+
...responseMeta ?? {}
|
|
1027
|
+
}
|
|
1028
|
+
} : {}
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
var ToolCalls = class {
|
|
1033
|
+
constructor(http, defaultRequestTimeoutMs) {
|
|
1034
|
+
this.http = http;
|
|
1035
|
+
this.defaultRequestTimeoutMs = defaultRequestTimeoutMs;
|
|
1036
|
+
}
|
|
1037
|
+
async call(toolId, input, options) {
|
|
1038
|
+
const inputSnapshot = JSON.parse(JSON.stringify(input));
|
|
1039
|
+
const metadataSnapshot = options?.metadata ? JSON.parse(JSON.stringify(options.metadata)) : void 0;
|
|
1040
|
+
const idempotencyKey = options?.idempotencyKey ?? (options?.recover ? crypto.randomUUID() : void 0);
|
|
1041
|
+
if (idempotencyKey !== void 0) {
|
|
1042
|
+
validateExecutionIdempotencyKey(idempotencyKey);
|
|
1043
|
+
if (options?.recoveryTimeoutMs !== void 0 && (!Number.isFinite(options.recoveryTimeoutMs) || options.recoveryTimeoutMs < 0)) {
|
|
1044
|
+
throw new DeeplineError(
|
|
1045
|
+
"recoveryTimeoutMs must be a finite, non-negative number.",
|
|
1046
|
+
void 0,
|
|
1047
|
+
"IDEMPOTENCY_KEY_INVALID"
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
await options?.onExecution?.({ idempotencyKey });
|
|
1051
|
+
}
|
|
1052
|
+
const timeoutMs = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
|
|
1053
|
+
if (idempotencyKey !== void 0) {
|
|
1054
|
+
await this.lookupExecutionByKey(idempotencyKey, timeoutMs);
|
|
1055
|
+
}
|
|
1056
|
+
const isApifySync = toolId.trim().toLowerCase() === "apify_run_actor_sync";
|
|
1057
|
+
const headers = {
|
|
1058
|
+
[EXECUTE_RESPONSE_CONTRACT_HEADER]: RAW_V2_EXECUTE_RESPONSE_CONTRACT,
|
|
1059
|
+
...isApifySync ? { "X-Deepline-Apify-Sync-Response-Budget": "extended-v1" } : {},
|
|
1060
|
+
[TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
|
|
1061
|
+
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
1062
|
+
),
|
|
1063
|
+
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
1064
|
+
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw",
|
|
1065
|
+
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
|
|
1066
|
+
...options?.searchRef ? { "x-deepline-search-ref": options.searchRef } : {}
|
|
1067
|
+
};
|
|
1068
|
+
const request = (requestTimeoutMs) => this.http.post(
|
|
1069
|
+
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
1070
|
+
{
|
|
1071
|
+
payload: inputSnapshot,
|
|
1072
|
+
...metadataSnapshot ? { metadata: metadataSnapshot } : {}
|
|
1073
|
+
},
|
|
1074
|
+
headers,
|
|
1075
|
+
{
|
|
1076
|
+
timeout: requestTimeoutMs,
|
|
1077
|
+
maxRetries: idempotencyKey ? 0 : options?.maxRetries ?? 0,
|
|
1078
|
+
retryApiErrors: options?.retryApiErrors === true,
|
|
1079
|
+
exactUrlOnly: true,
|
|
1080
|
+
toolId,
|
|
1081
|
+
idempotencyKey
|
|
1082
|
+
}
|
|
1083
|
+
);
|
|
1084
|
+
let response;
|
|
1085
|
+
let recoveryDeadline = null;
|
|
1086
|
+
const recoveryTimeoutMs = options?.recoveryTimeoutMs ?? DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS;
|
|
1087
|
+
let retryDelayMs = 1e3;
|
|
1088
|
+
const recoveryTimeoutError = () => executionRecoveryError({
|
|
1089
|
+
toolId,
|
|
1090
|
+
idempotencyKey,
|
|
1091
|
+
code: "EXECUTION_RECOVERY_TIMEOUT",
|
|
1092
|
+
message: `Execution recovery for ${idempotencyKey} did not finish before the recovery timeout. Inspect client.executions.getByKey() and resume with the same idempotency key.`
|
|
1093
|
+
});
|
|
1094
|
+
const waitForRecoveryRetry = async (deadline) => {
|
|
1095
|
+
const remainingMs = deadline - Date.now();
|
|
1096
|
+
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
1097
|
+
await new Promise(
|
|
1098
|
+
(resolve2) => setTimeout(resolve2, Math.min(retryDelayMs, remainingMs))
|
|
1099
|
+
);
|
|
1100
|
+
retryDelayMs = Math.min(retryDelayMs * 2, 5e3);
|
|
1101
|
+
};
|
|
1102
|
+
const lookupDuringRecovery = async () => {
|
|
1103
|
+
while (true) {
|
|
1104
|
+
const remainingMs = recoveryDeadline - Date.now();
|
|
1105
|
+
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
1106
|
+
try {
|
|
1107
|
+
return await this.lookupExecutionByKey(
|
|
1108
|
+
idempotencyKey,
|
|
1109
|
+
timeoutWithinRecoveryBudget(
|
|
1110
|
+
timeoutMs,
|
|
1111
|
+
this.defaultRequestTimeoutMs,
|
|
1112
|
+
remainingMs
|
|
1113
|
+
)
|
|
1114
|
+
);
|
|
1115
|
+
} catch (error) {
|
|
1116
|
+
if (!isRecoverableExecutionLookupError(error)) throw error;
|
|
1117
|
+
await waitForRecoveryRetry(recoveryDeadline);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
while (true) {
|
|
1122
|
+
const remainingMs = recoveryDeadline === null ? null : recoveryDeadline - Date.now();
|
|
1123
|
+
if (remainingMs !== null && remainingMs <= 0) {
|
|
1124
|
+
throw recoveryTimeoutError();
|
|
1125
|
+
}
|
|
1126
|
+
try {
|
|
1127
|
+
response = await request(
|
|
1128
|
+
remainingMs === null ? timeoutMs : timeoutWithinRecoveryBudget(
|
|
1129
|
+
timeoutMs,
|
|
1130
|
+
this.defaultRequestTimeoutMs,
|
|
1131
|
+
remainingMs
|
|
1132
|
+
)
|
|
1133
|
+
);
|
|
1134
|
+
const recoveryState = getExecutionRecoveryState(response);
|
|
1135
|
+
if (recoveryState === "outcome_unknown") {
|
|
1136
|
+
if (!idempotencyKey) break;
|
|
1137
|
+
throw executionRecoveryError({
|
|
1138
|
+
toolId,
|
|
1139
|
+
idempotencyKey,
|
|
1140
|
+
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
1141
|
+
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
if (!idempotencyKey || recoveryState !== "running") {
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
if (recoveryDeadline === null) {
|
|
1148
|
+
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
1149
|
+
}
|
|
1150
|
+
} catch (error) {
|
|
1151
|
+
if (idempotencyKey && error instanceof DeeplineError && error.code === "EXECUTION_OUTCOME_UNKNOWN") {
|
|
1152
|
+
throw executionRecoveryError({
|
|
1153
|
+
toolId,
|
|
1154
|
+
idempotencyKey,
|
|
1155
|
+
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
1156
|
+
message: error.message
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
if (!idempotencyKey || !isRecoverableExecutionAttemptError(error)) {
|
|
1160
|
+
throw error;
|
|
1161
|
+
}
|
|
1162
|
+
if (recoveryDeadline === null) {
|
|
1163
|
+
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
await waitForRecoveryRetry(recoveryDeadline);
|
|
1167
|
+
const recovered = await lookupDuringRecovery();
|
|
1168
|
+
if (getExecutionRecoveryState(recovered) === "outcome_unknown") {
|
|
1169
|
+
throw executionRecoveryError({
|
|
1170
|
+
toolId,
|
|
1171
|
+
idempotencyKey,
|
|
1172
|
+
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
1173
|
+
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const materialized = materializeToolExecutionResponse(response);
|
|
1178
|
+
return idempotencyKey ? { ...materialized, idempotencyKey } : materialized;
|
|
1179
|
+
}
|
|
1180
|
+
/** Read the durable state of a keyed tool execution. */
|
|
1181
|
+
async getByKey(idempotencyKey) {
|
|
1182
|
+
validateExecutionIdempotencyKey(idempotencyKey);
|
|
1183
|
+
const result = await this.lookupExecutionByKey(idempotencyKey);
|
|
1184
|
+
if (!result) {
|
|
1185
|
+
throw new DeeplineError(
|
|
1186
|
+
`No execution exists for idempotency key ${idempotencyKey}.`,
|
|
1187
|
+
404,
|
|
1188
|
+
"EXECUTION_NOT_FOUND"
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
return result;
|
|
1192
|
+
}
|
|
1193
|
+
async lookupExecutionByKey(idempotencyKey, timeoutMs) {
|
|
1194
|
+
validateExecutionIdempotencyKey(idempotencyKey);
|
|
1195
|
+
let supported = false;
|
|
1196
|
+
const result = await this.http.get(
|
|
1197
|
+
`/api/v2/executions/by-key/${encodeURIComponent(idempotencyKey)}`,
|
|
1198
|
+
{
|
|
1199
|
+
exactUrlOnly: true,
|
|
1200
|
+
maxRetries: 0,
|
|
1201
|
+
timeout: timeoutMs,
|
|
1202
|
+
idempotencyKey,
|
|
1203
|
+
allowNotFound: true,
|
|
1204
|
+
onResponse: (response) => {
|
|
1205
|
+
supported = response.headers.get("X-Deepline-Idempotency-Supported") === "true";
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
);
|
|
1209
|
+
if (!supported) {
|
|
1210
|
+
throw new DeeplineError(
|
|
1211
|
+
"This Deepline server does not support recoverable tool executions; no tool was dispatched.",
|
|
1212
|
+
422,
|
|
1213
|
+
"IDEMPOTENCY_NOT_SUPPORTED"
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
return result;
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
|
|
817
1220
|
// ../plays/artifact-contract-version.ts
|
|
818
1221
|
var CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION = 2;
|
|
819
1222
|
|
|
@@ -864,7 +1267,7 @@ var SDK_RELEASE = {
|
|
|
864
1267
|
// getters keep their established compatibility behavior.
|
|
865
1268
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
866
1269
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
867
|
-
version: "0.3.
|
|
1270
|
+
version: "0.3.232",
|
|
868
1271
|
updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
|
|
869
1272
|
packageCapabilities: {
|
|
870
1273
|
updatePreferences: 1
|
|
@@ -1511,7 +1914,7 @@ function providerLabelFromToolId(toolId) {
|
|
|
1511
1914
|
const provider = normalized.split(/[_:./-]+/)[0];
|
|
1512
1915
|
return provider || normalized || "provider";
|
|
1513
1916
|
}
|
|
1514
|
-
function
|
|
1917
|
+
function isRecord3(value) {
|
|
1515
1918
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1516
1919
|
}
|
|
1517
1920
|
var HttpClient = class {
|
|
@@ -1663,7 +2066,7 @@ var HttpClient = class {
|
|
|
1663
2066
|
const parsed = parseResponseBody(body);
|
|
1664
2067
|
const structuredToolError = options?.toolId && !response.ok ? deserializeToolExecutionFailure(
|
|
1665
2068
|
apiErrorMessage(parsed, response.status),
|
|
1666
|
-
|
|
2069
|
+
isRecord3(parsed) ? parsed.tool_error : null,
|
|
1667
2070
|
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
1668
2071
|
) : null;
|
|
1669
2072
|
if (structuredToolError) {
|
|
@@ -2709,11 +3112,11 @@ function buildPlayDocflowNodeErrorPreview(error, redactor = createSecretRedactio
|
|
|
2709
3112
|
return "Non-Error value thrown (message unavailable)";
|
|
2710
3113
|
}
|
|
2711
3114
|
}
|
|
2712
|
-
function
|
|
3115
|
+
function isRecord4(value) {
|
|
2713
3116
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
2714
3117
|
}
|
|
2715
3118
|
function normalizePreview(value, depth) {
|
|
2716
|
-
if (!
|
|
3119
|
+
if (!isRecord4(value) || typeof value.kind !== "string") return null;
|
|
2717
3120
|
if (value.kind === "null") return { kind: "null" };
|
|
2718
3121
|
if (value.kind === "scalar") {
|
|
2719
3122
|
if (typeof value.value === "string" || typeof value.value === "boolean" || typeof value.value === "number" && Number.isFinite(value.value)) {
|
|
@@ -2778,7 +3181,7 @@ function normalizePreview(value, depth) {
|
|
|
2778
3181
|
...value.truncated === true || totalItems > items.length ? { truncated: true } : {}
|
|
2779
3182
|
};
|
|
2780
3183
|
}
|
|
2781
|
-
if (value.kind === "object" &&
|
|
3184
|
+
if (value.kind === "object" && isRecord4(value.fields)) {
|
|
2782
3185
|
const fields = {};
|
|
2783
3186
|
for (const [key, field] of Object.entries(value.fields).slice(
|
|
2784
3187
|
0,
|
|
@@ -2798,10 +3201,10 @@ function normalizePreview(value, depth) {
|
|
|
2798
3201
|
return null;
|
|
2799
3202
|
}
|
|
2800
3203
|
function normalizePlayDocflowNodeIoState(value) {
|
|
2801
|
-
if (!
|
|
3204
|
+
if (!isRecord4(value)) return void 0;
|
|
2802
3205
|
const attempt = typeof value.attempt === "number" && Number.isFinite(value.attempt) ? Math.max(0, Math.floor(value.attempt)) : 0;
|
|
2803
3206
|
const normalizeMap = (raw) => {
|
|
2804
|
-
if (!
|
|
3207
|
+
if (!isRecord4(raw)) return void 0;
|
|
2805
3208
|
const output = {};
|
|
2806
3209
|
for (const [path, preview] of Object.entries(raw).slice(
|
|
2807
3210
|
0,
|
|
@@ -2838,11 +3241,11 @@ function normalizePlayDocflowNodeIoState(value) {
|
|
|
2838
3241
|
}
|
|
2839
3242
|
|
|
2840
3243
|
// ../play-runtime/activity-observation.ts
|
|
2841
|
-
function
|
|
3244
|
+
function isRecord5(value) {
|
|
2842
3245
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
2843
3246
|
}
|
|
2844
3247
|
function isPlayActivityObservation(value) {
|
|
2845
|
-
if (!
|
|
3248
|
+
if (!isRecord5(value) || value.schemaVersion !== void 0 && value.schemaVersion !== 1 || typeof value.activityId !== "string" || !value.activityId.trim() || typeof value.observedAt !== "number" || !Number.isFinite(value.observedAt) || !isRecord5(value.target) || !isRecord5(value.state)) {
|
|
2846
3249
|
return false;
|
|
2847
3250
|
}
|
|
2848
3251
|
const targetKinds = /* @__PURE__ */ new Set([
|
|
@@ -3142,7 +3545,7 @@ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
3142
3545
|
"terminated",
|
|
3143
3546
|
"timed_out"
|
|
3144
3547
|
]);
|
|
3145
|
-
function
|
|
3548
|
+
function isRecord6(value) {
|
|
3146
3549
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3147
3550
|
}
|
|
3148
3551
|
function finiteNumber(value) {
|
|
@@ -3157,7 +3560,7 @@ function isWorkCounterSegmentId(value) {
|
|
|
3157
3560
|
);
|
|
3158
3561
|
}
|
|
3159
3562
|
function normalizePlayRunLedgerTerminalWorkCounterSegment(value) {
|
|
3160
|
-
if (!
|
|
3563
|
+
if (!isRecord6(value)) return void 0;
|
|
3161
3564
|
if (!nonnegativeSafeInteger(value.attempt) || !nonnegativeSafeInteger(value.invocationSeq) || value.invocationSeq === 0 || !isWorkCounterSegmentId(value.segmentId)) {
|
|
3162
3565
|
return void 0;
|
|
3163
3566
|
}
|
|
@@ -3181,7 +3584,7 @@ function hasConfirmedPlayRunLedgerWorkCounters(snapshot) {
|
|
|
3181
3584
|
);
|
|
3182
3585
|
}
|
|
3183
3586
|
function normalizeWorkCounters(value) {
|
|
3184
|
-
if (!
|
|
3587
|
+
if (!isRecord6(value)) return void 0;
|
|
3185
3588
|
for (const field of [
|
|
3186
3589
|
"attempt",
|
|
3187
3590
|
"invocationSeq",
|
|
@@ -3271,8 +3674,8 @@ function summarizeRunRowOutcomes(snapshot) {
|
|
|
3271
3674
|
const stepTotal = finiteNumber(progress.total);
|
|
3272
3675
|
totalRows += stepTotal !== null && stepTotal >= 0 ? stepTotal : Math.max(0, finiteNumber(progress.completed) ?? 0) + Math.max(0, finiteNumber(progress.failed) ?? 0) + Math.max(0, finiteNumber(progress.supersededRows) ?? 0);
|
|
3273
3676
|
}
|
|
3274
|
-
const resultSummary =
|
|
3275
|
-
const resultRowOutcomes =
|
|
3677
|
+
const resultSummary = isRecord6(snapshot.resultSummary) ? snapshot.resultSummary : null;
|
|
3678
|
+
const resultRowOutcomes = isRecord6(resultSummary?.rowOutcomes) ? resultSummary.rowOutcomes : null;
|
|
3276
3679
|
const terminalCompletedRows = finiteNumber(resultRowOutcomes?.completedRows);
|
|
3277
3680
|
const terminalFailedRows = finiteNumber(resultRowOutcomes?.failedRows);
|
|
3278
3681
|
const terminalTotalRows = finiteNumber(resultRowOutcomes?.totalRows);
|
|
@@ -3321,21 +3724,21 @@ function createEmptyPlayRunLedgerSnapshot(input) {
|
|
|
3321
3724
|
};
|
|
3322
3725
|
}
|
|
3323
3726
|
function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
3324
|
-
if (!
|
|
3727
|
+
if (!isRecord6(value)) {
|
|
3325
3728
|
return createEmptyPlayRunLedgerSnapshot(fallback);
|
|
3326
3729
|
}
|
|
3327
3730
|
const orderedStepIds = Array.isArray(value.orderedStepIds) ? value.orderedStepIds.filter(
|
|
3328
3731
|
(entry) => typeof entry === "string" && Boolean(entry.trim())
|
|
3329
3732
|
) : [];
|
|
3330
|
-
const rawSteps =
|
|
3733
|
+
const rawSteps = isRecord6(value.stepsById) ? value.stepsById : {};
|
|
3331
3734
|
const stepsById = {};
|
|
3332
3735
|
for (const [stepId, rawStep] of Object.entries(rawSteps)) {
|
|
3333
|
-
if (!stepId.trim() || !
|
|
3736
|
+
if (!stepId.trim() || !isRecord6(rawStep)) continue;
|
|
3334
3737
|
const rawStatus = normalizeStepStatus(rawStep.status);
|
|
3335
3738
|
if (!rawStatus) continue;
|
|
3336
3739
|
const completedAt = finiteNumber(rawStep.completedAt);
|
|
3337
3740
|
const status = rawStatus === "running" && completedAt !== null ? "completed" : rawStatus;
|
|
3338
|
-
const rawProgress =
|
|
3741
|
+
const rawProgress = isRecord6(rawStep.progress) ? rawStep.progress : null;
|
|
3339
3742
|
stepsById[stepId] = {
|
|
3340
3743
|
stepId,
|
|
3341
3744
|
label: optionalString(rawStep.label),
|
|
@@ -3351,10 +3754,10 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
3351
3754
|
progress: rawProgress ? normalizeStepProgress(rawProgress) : null
|
|
3352
3755
|
};
|
|
3353
3756
|
}
|
|
3354
|
-
const rawDatasets =
|
|
3757
|
+
const rawDatasets = isRecord6(value.datasetsById) ? value.datasetsById : {};
|
|
3355
3758
|
const datasetsById = {};
|
|
3356
3759
|
for (const [datasetId, rawDataset] of Object.entries(rawDatasets)) {
|
|
3357
|
-
if (!datasetId.trim() || !
|
|
3760
|
+
if (!datasetId.trim() || !isRecord6(rawDataset)) continue;
|
|
3358
3761
|
const phase = rawDataset.phase === "available" || rawDataset.phase === "failed" ? rawDataset.phase : "registered";
|
|
3359
3762
|
const datasetBornFrom = normalizeDatasetBornFrom(rawDataset.bornFrom);
|
|
3360
3763
|
datasetsById[datasetId] = {
|
|
@@ -3377,7 +3780,7 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
3377
3780
|
updatedAt: finiteNumber(rawDataset.updatedAt) ?? 0
|
|
3378
3781
|
};
|
|
3379
3782
|
}
|
|
3380
|
-
const rawActivities =
|
|
3783
|
+
const rawActivities = isRecord6(value.activitiesById) ? value.activitiesById : {};
|
|
3381
3784
|
const activitiesById = {};
|
|
3382
3785
|
for (const [activityId, rawActivity] of Object.entries(rawActivities)) {
|
|
3383
3786
|
if (activityId.trim() && isPlayActivityObservation(rawActivity) && rawActivity.activityId === activityId) {
|
|
@@ -3567,18 +3970,18 @@ function normalizePlayRunLiveStatus(value) {
|
|
|
3567
3970
|
function isTerminalPlayRunLiveStatus(status) {
|
|
3568
3971
|
return isTerminalPlayRunLifecycleStatus(status);
|
|
3569
3972
|
}
|
|
3570
|
-
function
|
|
3973
|
+
function isRecord7(value) {
|
|
3571
3974
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3572
3975
|
}
|
|
3573
3976
|
function finiteNumber2(value) {
|
|
3574
3977
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
3575
3978
|
}
|
|
3576
3979
|
function extractTerminalRunLogTail(result) {
|
|
3577
|
-
if (!
|
|
3980
|
+
if (!isRecord7(result) || !isRecord7(result._metadata)) {
|
|
3578
3981
|
return null;
|
|
3579
3982
|
}
|
|
3580
3983
|
const runLogTail = result._metadata.runLogTail;
|
|
3581
|
-
if (!
|
|
3984
|
+
if (!isRecord7(runLogTail) || !Array.isArray(runLogTail.tail)) {
|
|
3582
3985
|
return null;
|
|
3583
3986
|
}
|
|
3584
3987
|
const logTail = runLogTail.tail.filter(
|
|
@@ -4238,80 +4641,6 @@ function isStopAllPlayRunsDryRunResult(result) {
|
|
|
4238
4641
|
return "dryRun" in result && result.dryRun === true;
|
|
4239
4642
|
}
|
|
4240
4643
|
|
|
4241
|
-
// ../integration-contracts/theirstack/execution-policy.ts
|
|
4242
|
-
var THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS = 135e3;
|
|
4243
|
-
var THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS = 6e4 + THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS + 15e3;
|
|
4244
|
-
var THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS = 21e4;
|
|
4245
|
-
var LONG_JOB_SEARCH_WINDOW_MS = 365 * 24 * 60 * 60 * 1e3;
|
|
4246
|
-
var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
4247
|
-
function parseDateOnly(value) {
|
|
4248
|
-
if (typeof value !== "string" || !DATE_ONLY_PATTERN.test(value)) {
|
|
4249
|
-
return null;
|
|
4250
|
-
}
|
|
4251
|
-
const timestamp = Date.parse(`${value}T00:00:00.000Z`);
|
|
4252
|
-
if (!Number.isFinite(timestamp)) {
|
|
4253
|
-
return null;
|
|
4254
|
-
}
|
|
4255
|
-
return new Date(timestamp).toISOString().slice(0, 10) === value ? timestamp : null;
|
|
4256
|
-
}
|
|
4257
|
-
function usesLongExplicitDateWindow(payload) {
|
|
4258
|
-
const postedAtGte = parseDateOnly(payload.posted_at_gte);
|
|
4259
|
-
const postedAtLte = parseDateOnly(payload.posted_at_lte);
|
|
4260
|
-
if (postedAtGte !== null && postedAtLte !== null) {
|
|
4261
|
-
return postedAtLte - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
4262
|
-
}
|
|
4263
|
-
if (postedAtGte !== null) {
|
|
4264
|
-
return Date.now() - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
4265
|
-
}
|
|
4266
|
-
return postedAtLte !== null && payload.posted_at_gte == null;
|
|
4267
|
-
}
|
|
4268
|
-
function parseMaxAgeDays(value) {
|
|
4269
|
-
if (typeof value === "number") {
|
|
4270
|
-
return Number.isFinite(value) ? value : null;
|
|
4271
|
-
}
|
|
4272
|
-
if (typeof value !== "string" || !/^-?\d+$/.test(value.trim())) {
|
|
4273
|
-
return null;
|
|
4274
|
-
}
|
|
4275
|
-
const parsed = Number(value.trim());
|
|
4276
|
-
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
4277
|
-
}
|
|
4278
|
-
function usesExtendedTheirstackJobSearchBudget(endpointId, payload) {
|
|
4279
|
-
if (endpointId !== "theirstack_job_search") {
|
|
4280
|
-
return false;
|
|
4281
|
-
}
|
|
4282
|
-
if (payload.include_total_results === true) {
|
|
4283
|
-
return true;
|
|
4284
|
-
}
|
|
4285
|
-
const maxAgeDays = parseMaxAgeDays(payload.posted_at_max_age_days);
|
|
4286
|
-
return maxAgeDays !== null && maxAgeDays >= 365 ? true : usesLongExplicitDateWindow(payload);
|
|
4287
|
-
}
|
|
4288
|
-
function resolveTheirstackClientTimeoutMs(endpointId, payload) {
|
|
4289
|
-
if (endpointId === "theirstack_company_search") {
|
|
4290
|
-
return THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS;
|
|
4291
|
-
}
|
|
4292
|
-
return usesExtendedTheirstackJobSearchBudget(endpointId, payload) ? THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS : null;
|
|
4293
|
-
}
|
|
4294
|
-
|
|
4295
|
-
// ../integration-contracts/waterfall/execution-policy.ts
|
|
4296
|
-
var WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS = 18e4;
|
|
4297
|
-
var WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
4298
|
-
"prospector",
|
|
4299
|
-
"deepline_native_prospector"
|
|
4300
|
-
]);
|
|
4301
|
-
function resolveWaterfallClientTimeoutMs(toolId) {
|
|
4302
|
-
return WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase()) ? WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS : null;
|
|
4303
|
-
}
|
|
4304
|
-
|
|
4305
|
-
// ../integration-contracts/bettercontact/execution-policy.ts
|
|
4306
|
-
var BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS = 12e4;
|
|
4307
|
-
var BETTERCONTACT_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
4308
|
-
"bettercontact_enrich",
|
|
4309
|
-
"bettercontact_bulk_enrich"
|
|
4310
|
-
]);
|
|
4311
|
-
function usesExtendedBetterContactLauncherBudget(toolId) {
|
|
4312
|
-
return BETTERCONTACT_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase());
|
|
4313
|
-
}
|
|
4314
|
-
|
|
4315
4644
|
// ../plays/artifact-types.ts
|
|
4316
4645
|
var PLAY_ARTIFACT_KINDS = {
|
|
4317
4646
|
cjsNode20: "cjs_node20"
|
|
@@ -4385,27 +4714,6 @@ function normalizePlayRuntimeEnvironment(value) {
|
|
|
4385
4714
|
return typeof value === "string" && PLAY_RUNTIME_ENVIRONMENTS.includes(value) ? value : null;
|
|
4386
4715
|
}
|
|
4387
4716
|
|
|
4388
|
-
// ../plays/tool-response-contract.ts
|
|
4389
|
-
var RAW_V2_TOOL_RESPONSE_CONTRACT = "raw-v2";
|
|
4390
|
-
function legacyRawFromToolResponseRawV2(rawV2, view, responseMeta) {
|
|
4391
|
-
const legacyRaw = view === "data" && rawV2 && typeof rawV2 === "object" && !Array.isArray(rawV2) ? rawV2.data : rawV2;
|
|
4392
|
-
const deeplineBilling = responseMeta?.deepline_billing;
|
|
4393
|
-
if (view === "rawV2" && deeplineBilling !== void 0 && legacyRaw && typeof legacyRaw === "object" && !Array.isArray(legacyRaw)) {
|
|
4394
|
-
return {
|
|
4395
|
-
...legacyRaw,
|
|
4396
|
-
deepline_billing: deeplineBilling
|
|
4397
|
-
};
|
|
4398
|
-
}
|
|
4399
|
-
return legacyRaw;
|
|
4400
|
-
}
|
|
4401
|
-
function providerMetaFromToolResponseRawV2(rawV2, view) {
|
|
4402
|
-
if (view !== "data" || !rawV2 || typeof rawV2 !== "object" || Array.isArray(rawV2)) {
|
|
4403
|
-
return void 0;
|
|
4404
|
-
}
|
|
4405
|
-
const meta = rawV2.meta;
|
|
4406
|
-
return meta && typeof meta === "object" && !Array.isArray(meta) ? meta : void 0;
|
|
4407
|
-
}
|
|
4408
|
-
|
|
4409
4717
|
// src/client.ts
|
|
4410
4718
|
var MAX_NOTIFICATION_GROUP_CREATE_TARGETS = 50;
|
|
4411
4719
|
function parseNotificationGroupTarget(value) {
|
|
@@ -4428,85 +4736,30 @@ function parseNotificationGroupTarget(value) {
|
|
|
4428
4736
|
}
|
|
4429
4737
|
const member = /^member:([UW][A-Z0-9]{8,})$/i.exec(slack);
|
|
4430
4738
|
if (member?.[1]) {
|
|
4431
|
-
return { kind: "slack", memberId: member[1].toUpperCase() };
|
|
4432
|
-
}
|
|
4433
|
-
if (slack.toLowerCase().startsWith("member:")) {
|
|
4434
|
-
throw new Error(
|
|
4435
|
-
"Slack member IDs must look like slack:member:U0123456789."
|
|
4436
|
-
);
|
|
4437
|
-
}
|
|
4438
|
-
if (!slack.replace(/^#/, "").trim()) {
|
|
4439
|
-
throw new Error("Use --to slack:#channel.");
|
|
4440
|
-
}
|
|
4441
|
-
return { kind: "slack", channel: slack };
|
|
4442
|
-
}
|
|
4443
|
-
function notificationObjectKey(kind) {
|
|
4444
|
-
return `${kind}.${globalThis.crypto.randomUUID()}`;
|
|
4445
|
-
}
|
|
4446
|
-
var TERMINAL_PLAY_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
4447
|
-
var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
|
|
4448
|
-
var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
|
|
4449
|
-
var EXECUTE_RESPONSE_INTENT_HEADER = "x-deepline-execute-response-intent";
|
|
4450
|
-
var MONITOR_NON_RETRYABLE_MUTATION_OPTIONS = {
|
|
4451
|
-
maxRetries: 0,
|
|
4452
|
-
exactUrlOnly: true
|
|
4453
|
-
};
|
|
4454
|
-
var RAW_V2_EXECUTE_RESPONSE_CONTRACT = RAW_V2_TOOL_RESPONSE_CONTRACT;
|
|
4455
|
-
var DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
4456
|
-
function validateExecutionIdempotencyKey(key) {
|
|
4457
|
-
if (typeof key !== "string" || key.length < 1 || key.length > 200 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
|
|
4458
|
-
throw new DeeplineError(
|
|
4459
|
-
"Execution idempotency keys must be 1\u2013200 ASCII letters, digits, dots, underscores, colons, or hyphens.",
|
|
4460
|
-
void 0,
|
|
4461
|
-
"IDEMPOTENCY_KEY_INVALID"
|
|
4462
|
-
);
|
|
4463
|
-
}
|
|
4464
|
-
}
|
|
4465
|
-
function isExecutionInProgressResponse(value) {
|
|
4466
|
-
return typeof value === "object" && value !== null && typeof value.executionRecovery === "object" && value.executionRecovery.state === "running";
|
|
4467
|
-
}
|
|
4468
|
-
function getExecutionRecoveryState(value) {
|
|
4469
|
-
if (typeof value !== "object" || value === null || typeof value.executionRecovery !== "object") {
|
|
4470
|
-
return null;
|
|
4471
|
-
}
|
|
4472
|
-
const state = value.executionRecovery.state;
|
|
4473
|
-
return state === "running" || state === "completed" || state === "outcome_unknown" ? state : null;
|
|
4474
|
-
}
|
|
4475
|
-
function isRecoverableExecutionAttemptError(error) {
|
|
4476
|
-
if (error instanceof ToolExecutionError) {
|
|
4477
|
-
return error.code === "EXECUTION_IN_PROGRESS" || error.origin === "deepline" && error.category === "network" && error.networkScope === "client_to_deepline";
|
|
4478
|
-
}
|
|
4479
|
-
return error instanceof DeeplineError && (error.code === "EXECUTION_IN_PROGRESS" || error.code?.startsWith("NETWORK_") === true && error.statusCode === void 0);
|
|
4480
|
-
}
|
|
4481
|
-
function isRecoverableExecutionLookupError(error) {
|
|
4482
|
-
if (isRecoverableExecutionAttemptError(error)) return true;
|
|
4483
|
-
return error instanceof DeeplineError && (error.statusCode === 429 || error.statusCode !== void 0 && error.statusCode >= 500);
|
|
4484
|
-
}
|
|
4485
|
-
function timeoutWithinRecoveryBudget(requestTimeoutMs, defaultRequestTimeoutMs, remainingMs) {
|
|
4486
|
-
return Math.min(requestTimeoutMs ?? defaultRequestTimeoutMs, remainingMs);
|
|
4487
|
-
}
|
|
4488
|
-
function executionRecoveryError(input) {
|
|
4489
|
-
return new ToolExecutionError(input.message, {
|
|
4490
|
-
toolId: input.toolId,
|
|
4491
|
-
provider: null,
|
|
4492
|
-
operation: input.toolId,
|
|
4493
|
-
code: input.code,
|
|
4494
|
-
origin: "deepline",
|
|
4495
|
-
category: input.code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown" : "conflict",
|
|
4496
|
-
retryable: input.code !== "EXECUTION_OUTCOME_UNKNOWN",
|
|
4497
|
-
statusCode: null,
|
|
4498
|
-
requestId: null,
|
|
4499
|
-
retryAfterMs: null,
|
|
4500
|
-
networkKind: null,
|
|
4501
|
-
networkScope: null,
|
|
4502
|
-
publicDetails: { idempotencyKey: input.idempotencyKey }
|
|
4503
|
-
});
|
|
4739
|
+
return { kind: "slack", memberId: member[1].toUpperCase() };
|
|
4740
|
+
}
|
|
4741
|
+
if (slack.toLowerCase().startsWith("member:")) {
|
|
4742
|
+
throw new Error(
|
|
4743
|
+
"Slack member IDs must look like slack:member:U0123456789."
|
|
4744
|
+
);
|
|
4745
|
+
}
|
|
4746
|
+
if (!slack.replace(/^#/, "").trim()) {
|
|
4747
|
+
throw new Error("Use --to slack:#channel.");
|
|
4748
|
+
}
|
|
4749
|
+
return { kind: "slack", channel: slack };
|
|
4750
|
+
}
|
|
4751
|
+
function notificationObjectKey(kind) {
|
|
4752
|
+
return `${kind}.${globalThis.crypto.randomUUID()}`;
|
|
4504
4753
|
}
|
|
4754
|
+
var TERMINAL_PLAY_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
4755
|
+
var MONITOR_NON_RETRYABLE_MUTATION_OPTIONS = {
|
|
4756
|
+
maxRetries: 0,
|
|
4757
|
+
exactUrlOnly: true
|
|
4758
|
+
};
|
|
4505
4759
|
var COMPILE_MANIFEST_RETRY_DELAYS_MS = [250, 1e3];
|
|
4506
4760
|
var REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY = 3;
|
|
4507
4761
|
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT = 3;
|
|
4508
4762
|
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES = 25e5;
|
|
4509
|
-
var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
4510
4763
|
function normalizePlayRunIntegrationMode(value) {
|
|
4511
4764
|
if (value === "live" || value === "eval_stub" || value === "fixture") {
|
|
4512
4765
|
return value;
|
|
@@ -4697,28 +4950,6 @@ function chunkRegisterPlayArtifacts(artifacts) {
|
|
|
4697
4950
|
}
|
|
4698
4951
|
return chunks;
|
|
4699
4952
|
}
|
|
4700
|
-
var APIFY_SYNC_DEFAULT_TIMEOUT_MS = 3e5;
|
|
4701
|
-
var APIFY_SYNC_RESPONSE_GRACE_MS = 9e4;
|
|
4702
|
-
function resolveToolExecuteTimeoutMs(toolId, input) {
|
|
4703
|
-
const normalized = toolId.trim().toLowerCase();
|
|
4704
|
-
if (normalized === "apify_run_actor_sync") {
|
|
4705
|
-
const requestedTimeoutMs = input.timeoutMs ?? APIFY_SYNC_DEFAULT_TIMEOUT_MS;
|
|
4706
|
-
if (typeof requestedTimeoutMs === "number" && Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0) {
|
|
4707
|
-
return Math.floor(requestedTimeoutMs) + APIFY_SYNC_RESPONSE_GRACE_MS;
|
|
4708
|
-
}
|
|
4709
|
-
}
|
|
4710
|
-
const theirstackTimeoutMs = resolveTheirstackClientTimeoutMs(
|
|
4711
|
-
normalized,
|
|
4712
|
-
input
|
|
4713
|
-
);
|
|
4714
|
-
if (theirstackTimeoutMs !== null) return theirstackTimeoutMs;
|
|
4715
|
-
const waterfallTimeoutMs = resolveWaterfallClientTimeoutMs(normalized);
|
|
4716
|
-
if (waterfallTimeoutMs !== null) return waterfallTimeoutMs;
|
|
4717
|
-
if (usesExtendedBetterContactLauncherBudget(normalized)) {
|
|
4718
|
-
return BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS;
|
|
4719
|
-
}
|
|
4720
|
-
return normalized === "deeplineagent" || normalized === "deeplineagent_deeplineagent" || normalized === "ai_inference" || normalized === "deeplineagent_ai_inference" || normalized === "ai_evaluate" || normalized === "deeplineagent_ai_evaluate" || normalized === "aiinference" ? DEEPLINEAGENT_EXECUTE_TIMEOUT_MS : void 0;
|
|
4721
|
-
}
|
|
4722
4953
|
var RUNS_FAILED_LOG_LIMIT = 20;
|
|
4723
4954
|
var RUN_LOGS_PAGE_LIMIT = 1e3;
|
|
4724
4955
|
var MONITOR_JOB_STATES = [
|
|
@@ -4753,53 +4984,9 @@ function requireTargetBillingIdempotencyKey(value) {
|
|
|
4753
4984
|
}
|
|
4754
4985
|
return normalized;
|
|
4755
4986
|
}
|
|
4756
|
-
function
|
|
4987
|
+
function isRecord8(value) {
|
|
4757
4988
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
4758
4989
|
}
|
|
4759
|
-
function materializeToolExecutionResponse(response) {
|
|
4760
|
-
const toolResponse = response.toolResponse;
|
|
4761
|
-
if (!toolResponse && isRecord7(response.result)) {
|
|
4762
|
-
const legacyResult = response.result;
|
|
4763
|
-
if (Object.prototype.hasOwnProperty.call(legacyResult, "data")) {
|
|
4764
|
-
const legacyMeta = isRecord7(legacyResult.meta) ? legacyResult.meta : void 0;
|
|
4765
|
-
return {
|
|
4766
|
-
...response,
|
|
4767
|
-
toolResponse: {
|
|
4768
|
-
raw: legacyResult.data,
|
|
4769
|
-
...legacyMeta ? { meta: legacyMeta } : {}
|
|
4770
|
-
}
|
|
4771
|
-
};
|
|
4772
|
-
}
|
|
4773
|
-
}
|
|
4774
|
-
if (!toolResponse || Object.prototype.hasOwnProperty.call(toolResponse, "raw")) {
|
|
4775
|
-
return response;
|
|
4776
|
-
}
|
|
4777
|
-
const rawV2 = toolResponse.rawV2;
|
|
4778
|
-
const view = toolResponse.view;
|
|
4779
|
-
const providerMeta = providerMetaFromToolResponseRawV2(
|
|
4780
|
-
rawV2,
|
|
4781
|
-
view ?? "rawV2"
|
|
4782
|
-
);
|
|
4783
|
-
const responseMeta = isRecord7(toolResponse.responseMeta) ? toolResponse.responseMeta : void 0;
|
|
4784
|
-
return {
|
|
4785
|
-
...response,
|
|
4786
|
-
toolResponse: {
|
|
4787
|
-
...toolResponse,
|
|
4788
|
-
raw: legacyRawFromToolResponseRawV2(
|
|
4789
|
-
rawV2,
|
|
4790
|
-
view ?? "rawV2",
|
|
4791
|
-
responseMeta
|
|
4792
|
-
),
|
|
4793
|
-
...toolResponse.meta || providerMeta || responseMeta ? {
|
|
4794
|
-
meta: {
|
|
4795
|
-
...toolResponse.meta ?? {},
|
|
4796
|
-
...providerMeta ?? {},
|
|
4797
|
-
...responseMeta ?? {}
|
|
4798
|
-
}
|
|
4799
|
-
} : {}
|
|
4800
|
-
}
|
|
4801
|
-
};
|
|
4802
|
-
}
|
|
4803
4990
|
function isPrebuiltPlayDescription(play) {
|
|
4804
4991
|
return play.origin === "prebuilt" || play.ownerType === "deepline";
|
|
4805
4992
|
}
|
|
@@ -4829,10 +5016,10 @@ function normalizePlayStatus(raw) {
|
|
|
4829
5016
|
return {
|
|
4830
5017
|
...raw,
|
|
4831
5018
|
runId,
|
|
4832
|
-
...
|
|
5019
|
+
...isRecord8(legacyOverview) ? {
|
|
4833
5020
|
overview: legacyOverview
|
|
4834
5021
|
} : {},
|
|
4835
|
-
...
|
|
5022
|
+
...isRecord8(runStatus) ? { runStatus } : {},
|
|
4836
5023
|
...runPackage ? {
|
|
4837
5024
|
package: runPackage,
|
|
4838
5025
|
outputs: runPackage.outputs
|
|
@@ -4971,7 +5158,7 @@ function updatePlayLiveStatusState(state, event) {
|
|
|
4971
5158
|
}
|
|
4972
5159
|
const runId = typeof payload.runId === "string" && payload.runId ? payload.runId : isPlayRunPackage(payload) ? payload.run.id : state.runId;
|
|
4973
5160
|
const status = normalizeLiveStatus(payload.status) ?? (isPlayRunPackage(payload) ? normalizeLiveStatus(payload.run.status) : null) ?? state.status;
|
|
4974
|
-
const progressPayload =
|
|
5161
|
+
const progressPayload = isRecord8(payload.progress) ? payload.progress : {};
|
|
4975
5162
|
if (event.type === "play.run.final_status" && state.logs.length === 0 && state.lastLogSeq === 0) {
|
|
4976
5163
|
const payloadLogs = readStringArray(payload.logs);
|
|
4977
5164
|
const progressLogs = readStringArray(progressPayload.logs);
|
|
@@ -5020,6 +5207,7 @@ function playRunResultFromStatus(status, startedAt, fallbackRunId) {
|
|
|
5020
5207
|
}
|
|
5021
5208
|
var DeeplineClient = class _DeeplineClient {
|
|
5022
5209
|
http;
|
|
5210
|
+
toolCalls;
|
|
5023
5211
|
config;
|
|
5024
5212
|
/** Canonical run lifecycle namespace backed by `/api/v2/runs`. */
|
|
5025
5213
|
runs;
|
|
@@ -5043,6 +5231,7 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5043
5231
|
constructor(options) {
|
|
5044
5232
|
this.config = resolveConfig(options);
|
|
5045
5233
|
this.http = new HttpClient(this.config);
|
|
5234
|
+
this.toolCalls = new ToolCalls(this.http, this.config.timeout);
|
|
5046
5235
|
this.runs = {
|
|
5047
5236
|
get: (runId, options2) => this.getRunStatus(runId, options2),
|
|
5048
5237
|
status: (runId) => this.getRunLifecycleStatus(runId),
|
|
@@ -5170,9 +5359,9 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5170
5359
|
return fields.length > 0 ? { fields } : schema;
|
|
5171
5360
|
}
|
|
5172
5361
|
schemaMetadata(schema, key) {
|
|
5173
|
-
if (!
|
|
5362
|
+
if (!isRecord8(schema)) return null;
|
|
5174
5363
|
const value = schema[key];
|
|
5175
|
-
return
|
|
5364
|
+
return isRecord8(value) ? value : null;
|
|
5176
5365
|
}
|
|
5177
5366
|
playRunCommand(play, options) {
|
|
5178
5367
|
const target = play.reference || play.name;
|
|
@@ -5227,7 +5416,7 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5227
5416
|
aliases,
|
|
5228
5417
|
inputSchema: options?.compact ? this.compactSchema(play.inputSchema) : play.inputSchema ?? null,
|
|
5229
5418
|
outputSchema: options?.compact ? this.compactSchema(play.outputSchema) : play.outputSchema ?? null,
|
|
5230
|
-
staticPipeline:
|
|
5419
|
+
staticPipeline: isRecord8(play.staticPipeline) ? play.staticPipeline : isRecord8(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord8(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
|
|
5231
5420
|
...csvInput ? { csvInput } : {},
|
|
5232
5421
|
...rowOutputSchema ? { rowOutputSchema } : {},
|
|
5233
5422
|
runCommand,
|
|
@@ -5447,183 +5636,11 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5447
5636
|
* Deepline execution envelope.
|
|
5448
5637
|
*/
|
|
5449
5638
|
async executeTool(toolId, input, options) {
|
|
5450
|
-
|
|
5451
|
-
const metadataSnapshot = options?.metadata ? JSON.parse(JSON.stringify(options.metadata)) : void 0;
|
|
5452
|
-
const idempotencyKey = options?.idempotencyKey ?? (options?.recover ? crypto.randomUUID() : void 0);
|
|
5453
|
-
if (idempotencyKey !== void 0) {
|
|
5454
|
-
validateExecutionIdempotencyKey(idempotencyKey);
|
|
5455
|
-
if (options?.recoveryTimeoutMs !== void 0 && (!Number.isFinite(options.recoveryTimeoutMs) || options.recoveryTimeoutMs < 0)) {
|
|
5456
|
-
throw new DeeplineError(
|
|
5457
|
-
"recoveryTimeoutMs must be a finite, non-negative number.",
|
|
5458
|
-
void 0,
|
|
5459
|
-
"IDEMPOTENCY_KEY_INVALID"
|
|
5460
|
-
);
|
|
5461
|
-
}
|
|
5462
|
-
await options?.onExecution?.({ idempotencyKey });
|
|
5463
|
-
const timeoutMs2 = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
|
|
5464
|
-
await this.lookupExecutionByKey(idempotencyKey, timeoutMs2);
|
|
5465
|
-
}
|
|
5466
|
-
const timeoutMs = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
|
|
5467
|
-
const isApifySync = toolId.trim().toLowerCase() === "apify_run_actor_sync";
|
|
5468
|
-
const headers = {
|
|
5469
|
-
[EXECUTE_RESPONSE_CONTRACT_HEADER]: RAW_V2_EXECUTE_RESPONSE_CONTRACT,
|
|
5470
|
-
...isApifySync ? { "X-Deepline-Apify-Sync-Response-Budget": "extended-v1" } : {},
|
|
5471
|
-
[TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
|
|
5472
|
-
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
5473
|
-
),
|
|
5474
|
-
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
5475
|
-
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw",
|
|
5476
|
-
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
|
|
5477
|
-
...options?.searchRef ? { "x-deepline-search-ref": options.searchRef } : {}
|
|
5478
|
-
};
|
|
5479
|
-
const request = (requestTimeoutMs) => this.http.post(
|
|
5480
|
-
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
5481
|
-
{
|
|
5482
|
-
payload: inputSnapshot,
|
|
5483
|
-
...metadataSnapshot ? { metadata: metadataSnapshot } : {}
|
|
5484
|
-
},
|
|
5485
|
-
headers,
|
|
5486
|
-
{
|
|
5487
|
-
timeout: requestTimeoutMs,
|
|
5488
|
-
maxRetries: idempotencyKey ? 0 : options?.maxRetries ?? 0,
|
|
5489
|
-
retryApiErrors: options?.retryApiErrors === true,
|
|
5490
|
-
exactUrlOnly: true,
|
|
5491
|
-
toolId,
|
|
5492
|
-
idempotencyKey
|
|
5493
|
-
}
|
|
5494
|
-
);
|
|
5495
|
-
let response;
|
|
5496
|
-
let recoveryDeadline = null;
|
|
5497
|
-
const recoveryTimeoutMs = options?.recoveryTimeoutMs ?? DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS;
|
|
5498
|
-
let retryDelayMs = 1e3;
|
|
5499
|
-
const recoveryTimeoutError = () => executionRecoveryError({
|
|
5500
|
-
toolId,
|
|
5501
|
-
idempotencyKey,
|
|
5502
|
-
code: "EXECUTION_RECOVERY_TIMEOUT",
|
|
5503
|
-
message: `Execution recovery for ${idempotencyKey} did not finish before the recovery timeout. Inspect client.executions.getByKey() and resume with the same idempotency key.`
|
|
5504
|
-
});
|
|
5505
|
-
const waitForRecoveryRetry = async (deadline) => {
|
|
5506
|
-
const remainingMs = deadline - Date.now();
|
|
5507
|
-
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
5508
|
-
await new Promise(
|
|
5509
|
-
(resolve2) => setTimeout(resolve2, Math.min(retryDelayMs, remainingMs))
|
|
5510
|
-
);
|
|
5511
|
-
retryDelayMs = Math.min(retryDelayMs * 2, 5e3);
|
|
5512
|
-
};
|
|
5513
|
-
const lookupDuringRecovery = async () => {
|
|
5514
|
-
while (true) {
|
|
5515
|
-
const remainingMs = recoveryDeadline - Date.now();
|
|
5516
|
-
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
5517
|
-
try {
|
|
5518
|
-
return await this.lookupExecutionByKey(
|
|
5519
|
-
idempotencyKey,
|
|
5520
|
-
timeoutWithinRecoveryBudget(
|
|
5521
|
-
timeoutMs,
|
|
5522
|
-
this.config.timeout,
|
|
5523
|
-
remainingMs
|
|
5524
|
-
)
|
|
5525
|
-
);
|
|
5526
|
-
} catch (error) {
|
|
5527
|
-
if (!isRecoverableExecutionLookupError(error)) throw error;
|
|
5528
|
-
await waitForRecoveryRetry(recoveryDeadline);
|
|
5529
|
-
}
|
|
5530
|
-
}
|
|
5531
|
-
};
|
|
5532
|
-
while (true) {
|
|
5533
|
-
const remainingMs = recoveryDeadline === null ? null : recoveryDeadline - Date.now();
|
|
5534
|
-
if (remainingMs !== null && remainingMs <= 0) {
|
|
5535
|
-
throw recoveryTimeoutError();
|
|
5536
|
-
}
|
|
5537
|
-
try {
|
|
5538
|
-
response = await request(
|
|
5539
|
-
remainingMs === null ? timeoutMs : timeoutWithinRecoveryBudget(
|
|
5540
|
-
timeoutMs,
|
|
5541
|
-
this.config.timeout,
|
|
5542
|
-
remainingMs
|
|
5543
|
-
)
|
|
5544
|
-
);
|
|
5545
|
-
if (getExecutionRecoveryState(response) === "outcome_unknown") {
|
|
5546
|
-
if (!idempotencyKey) break;
|
|
5547
|
-
throw executionRecoveryError({
|
|
5548
|
-
toolId,
|
|
5549
|
-
idempotencyKey,
|
|
5550
|
-
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
5551
|
-
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
5552
|
-
});
|
|
5553
|
-
}
|
|
5554
|
-
if (!idempotencyKey || !isExecutionInProgressResponse(response)) {
|
|
5555
|
-
break;
|
|
5556
|
-
}
|
|
5557
|
-
if (recoveryDeadline === null) {
|
|
5558
|
-
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
5559
|
-
}
|
|
5560
|
-
} catch (error) {
|
|
5561
|
-
if (idempotencyKey && error instanceof DeeplineError && error.code === "EXECUTION_OUTCOME_UNKNOWN") {
|
|
5562
|
-
throw executionRecoveryError({
|
|
5563
|
-
toolId,
|
|
5564
|
-
idempotencyKey,
|
|
5565
|
-
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
5566
|
-
message: error.message
|
|
5567
|
-
});
|
|
5568
|
-
}
|
|
5569
|
-
if (!idempotencyKey || !isRecoverableExecutionAttemptError(error)) {
|
|
5570
|
-
throw error;
|
|
5571
|
-
}
|
|
5572
|
-
if (recoveryDeadline === null) {
|
|
5573
|
-
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
5574
|
-
}
|
|
5575
|
-
}
|
|
5576
|
-
await waitForRecoveryRetry(recoveryDeadline);
|
|
5577
|
-
const recovered = await lookupDuringRecovery();
|
|
5578
|
-
if (getExecutionRecoveryState(recovered) === "outcome_unknown") {
|
|
5579
|
-
throw executionRecoveryError({
|
|
5580
|
-
toolId,
|
|
5581
|
-
idempotencyKey,
|
|
5582
|
-
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
5583
|
-
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
5584
|
-
});
|
|
5585
|
-
}
|
|
5586
|
-
}
|
|
5587
|
-
const materialized = materializeToolExecutionResponse(response);
|
|
5588
|
-
return idempotencyKey ? { ...materialized, idempotencyKey } : materialized;
|
|
5639
|
+
return this.toolCalls.call(toolId, input, options);
|
|
5589
5640
|
}
|
|
5590
5641
|
/** Read the durable state of a keyed tool execution. */
|
|
5591
5642
|
async getExecutionByKey(idempotencyKey) {
|
|
5592
|
-
|
|
5593
|
-
const result = await this.lookupExecutionByKey(idempotencyKey);
|
|
5594
|
-
if (!result) {
|
|
5595
|
-
throw new DeeplineError(
|
|
5596
|
-
`No execution exists for idempotency key ${idempotencyKey}.`,
|
|
5597
|
-
404,
|
|
5598
|
-
"EXECUTION_NOT_FOUND"
|
|
5599
|
-
);
|
|
5600
|
-
}
|
|
5601
|
-
return result;
|
|
5602
|
-
}
|
|
5603
|
-
async lookupExecutionByKey(idempotencyKey, timeoutMs) {
|
|
5604
|
-
validateExecutionIdempotencyKey(idempotencyKey);
|
|
5605
|
-
let supported = false;
|
|
5606
|
-
const result = await this.http.get(
|
|
5607
|
-
`/api/v2/executions/by-key/${encodeURIComponent(idempotencyKey)}`,
|
|
5608
|
-
{
|
|
5609
|
-
exactUrlOnly: true,
|
|
5610
|
-
maxRetries: 0,
|
|
5611
|
-
timeout: timeoutMs,
|
|
5612
|
-
idempotencyKey,
|
|
5613
|
-
allowNotFound: true,
|
|
5614
|
-
onResponse: (response) => {
|
|
5615
|
-
supported = response.headers.get("X-Deepline-Idempotency-Supported") === "true";
|
|
5616
|
-
}
|
|
5617
|
-
}
|
|
5618
|
-
);
|
|
5619
|
-
if (!supported) {
|
|
5620
|
-
throw new DeeplineError(
|
|
5621
|
-
"This Deepline server does not support recoverable tool executions; no tool was dispatched.",
|
|
5622
|
-
422,
|
|
5623
|
-
"IDEMPOTENCY_NOT_SUPPORTED"
|
|
5624
|
-
);
|
|
5625
|
-
}
|
|
5626
|
-
return result;
|
|
5643
|
+
return this.toolCalls.getByKey(idempotencyKey);
|
|
5627
5644
|
}
|
|
5628
5645
|
/** Public recovery namespace. */
|
|
5629
5646
|
get executions() {
|
|
@@ -6431,10 +6448,10 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
6431
6448
|
const responseRunStatus = isPlayRunPackage(response) ? response.runStatus : isPlayRunPackage(response.package) ? response.package.runStatus : response.runStatus;
|
|
6432
6449
|
const responseOverview = isPlayRunPackage(response) ? response.overview : isPlayRunPackage(response.package) ? response.package.overview : response.overview;
|
|
6433
6450
|
const status = normalizePlayStatus(response);
|
|
6434
|
-
if (
|
|
6451
|
+
if (isRecord8(responseRunStatus)) {
|
|
6435
6452
|
status.runStatus = responseRunStatus;
|
|
6436
6453
|
}
|
|
6437
|
-
if (
|
|
6454
|
+
if (isRecord8(responseOverview)) {
|
|
6438
6455
|
status.overview = responseOverview;
|
|
6439
6456
|
}
|
|
6440
6457
|
if (options?.failedLogs !== true || status.status !== "failed") {
|
|
@@ -9273,7 +9290,7 @@ var TARGET_FALLBACK_KEYS = {
|
|
|
9273
9290
|
status: { match: [/^email_status$/i, /^status$/i] },
|
|
9274
9291
|
email_status: { match: [/^email_status$/i, /^status$/i] }
|
|
9275
9292
|
};
|
|
9276
|
-
function
|
|
9293
|
+
function isRecord9(value) {
|
|
9277
9294
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
9278
9295
|
}
|
|
9279
9296
|
function toV2RawToolOutputPath(path) {
|
|
@@ -9333,7 +9350,7 @@ function valuesAtSegments(current, segments, path = []) {
|
|
|
9333
9350
|
if (!Array.isArray(current)) return [];
|
|
9334
9351
|
return valuesAtSegments(current[segment], rest, [...path, segment]);
|
|
9335
9352
|
}
|
|
9336
|
-
if (!
|
|
9353
|
+
if (!isRecord9(current)) return [];
|
|
9337
9354
|
const directMatches = valuesAtSegments(current[segment], rest, [
|
|
9338
9355
|
...path,
|
|
9339
9356
|
segment
|
|
@@ -9363,7 +9380,7 @@ function getValuesAtPath(root, path) {
|
|
|
9363
9380
|
return valuesAtSegments(root, parsePath(path)).map((entry) => entry.value);
|
|
9364
9381
|
}
|
|
9365
9382
|
function toResultEnvelope(value) {
|
|
9366
|
-
if (
|
|
9383
|
+
if (isRecord9(value) && "data" in value) {
|
|
9367
9384
|
const envelope = { data: value.data };
|
|
9368
9385
|
if ("meta" in value) envelope.meta = value.meta;
|
|
9369
9386
|
return envelope;
|
|
@@ -9416,7 +9433,7 @@ function getAtPath(root, path) {
|
|
|
9416
9433
|
current = current[segment];
|
|
9417
9434
|
continue;
|
|
9418
9435
|
}
|
|
9419
|
-
if (!
|
|
9436
|
+
if (!isRecord9(current)) return void 0;
|
|
9420
9437
|
current = current[segment];
|
|
9421
9438
|
}
|
|
9422
9439
|
return current;
|
|
@@ -9433,7 +9450,7 @@ function normalizeString(value) {
|
|
|
9433
9450
|
}
|
|
9434
9451
|
function normalizeRows(value) {
|
|
9435
9452
|
if (!Array.isArray(value)) return null;
|
|
9436
|
-
return value.map((entry) =>
|
|
9453
|
+
return value.map((entry) => isRecord9(entry) ? entry : { value: entry });
|
|
9437
9454
|
}
|
|
9438
9455
|
function findFirstTargetByPath(result, paths) {
|
|
9439
9456
|
for (const path of paths ?? []) {
|
|
@@ -9503,7 +9520,7 @@ function findFirstTargetByKey(result, target, depth = 0, path = []) {
|
|
|
9503
9520
|
}
|
|
9504
9521
|
return null;
|
|
9505
9522
|
}
|
|
9506
|
-
if (!
|
|
9523
|
+
if (!isRecord9(result)) return null;
|
|
9507
9524
|
const rule = TARGET_FALLBACK_KEYS[target] ?? {
|
|
9508
9525
|
match: [new RegExp(`^${target}$`, "i")]
|
|
9509
9526
|
};
|
|
@@ -9564,7 +9581,7 @@ function normalizeJobChangeStatus(value) {
|
|
|
9564
9581
|
function firstExperienceDate(value) {
|
|
9565
9582
|
if (!Array.isArray(value)) return null;
|
|
9566
9583
|
for (const entry of value) {
|
|
9567
|
-
if (!
|
|
9584
|
+
if (!isRecord9(entry)) continue;
|
|
9568
9585
|
const date = normalizeString(
|
|
9569
9586
|
entry.start_date ?? entry.started_at ?? entry.startDate
|
|
9570
9587
|
);
|
|
@@ -9573,10 +9590,10 @@ function firstExperienceDate(value) {
|
|
|
9573
9590
|
return null;
|
|
9574
9591
|
}
|
|
9575
9592
|
function normalizeJobChange(value) {
|
|
9576
|
-
const record3 =
|
|
9577
|
-
const nested =
|
|
9578
|
-
const output =
|
|
9579
|
-
const person =
|
|
9593
|
+
const record3 = isRecord9(value) ? value : {};
|
|
9594
|
+
const nested = isRecord9(record3.job_change) ? record3.job_change : record3;
|
|
9595
|
+
const output = isRecord9(nested.output) ? nested.output : nested;
|
|
9596
|
+
const person = isRecord9(output.person) ? output.person : {};
|
|
9580
9597
|
const status = normalizeJobChangeStatus(
|
|
9581
9598
|
output.status ?? output.job_change_status ?? output.job_changed ?? output.changed
|
|
9582
9599
|
);
|
|
@@ -9987,7 +10004,7 @@ function attachToolResultListDataset(result, input) {
|
|
|
9987
10004
|
root = replaceAtPath(root, candidate, serialized.preview);
|
|
9988
10005
|
break;
|
|
9989
10006
|
}
|
|
9990
|
-
if (
|
|
10007
|
+
if (isRecord9(root) && isRecord9(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
|
|
9991
10008
|
result.toolResponse.raw = root.toolResponse.raw;
|
|
9992
10009
|
result.toolOutput.raw = root.toolResponse.raw;
|
|
9993
10010
|
}
|
|
@@ -10005,7 +10022,7 @@ function replaceAtPath(root, path, replacement) {
|
|
|
10005
10022
|
copy[segment] = replace(copy[segment], index + 1);
|
|
10006
10023
|
return copy;
|
|
10007
10024
|
}
|
|
10008
|
-
if (!
|
|
10025
|
+
if (!isRecord9(current)) return current;
|
|
10009
10026
|
return {
|
|
10010
10027
|
...current,
|
|
10011
10028
|
[segment]: replace(current[segment], index + 1)
|
|
@@ -11975,11 +11992,11 @@ var Deepline = class {
|
|
|
11975
11992
|
return new DeeplineContext(options);
|
|
11976
11993
|
}
|
|
11977
11994
|
};
|
|
11978
|
-
function
|
|
11995
|
+
function isRecord10(value) {
|
|
11979
11996
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11980
11997
|
}
|
|
11981
11998
|
function stringArrayRecord(value) {
|
|
11982
|
-
if (!
|
|
11999
|
+
if (!isRecord10(value)) return {};
|
|
11983
12000
|
return Object.fromEntries(
|
|
11984
12001
|
Object.entries(value).map(([key, paths]) => [
|
|
11985
12002
|
key,
|
|
@@ -11991,7 +12008,7 @@ function stringArray(value) {
|
|
|
11991
12008
|
return Array.isArray(value) ? value.map(String) : [];
|
|
11992
12009
|
}
|
|
11993
12010
|
function emailStatusExtractorConfig(value) {
|
|
11994
|
-
if (!
|
|
12011
|
+
if (!isRecord10(value)) return void 0;
|
|
11995
12012
|
const readPaths = (key) => {
|
|
11996
12013
|
const paths = stringArray(value[key]).map((path) => path.trim()).filter(Boolean);
|
|
11997
12014
|
return paths.length > 0 ? paths : void 0;
|
|
@@ -12018,7 +12035,7 @@ function emailStatusExtractorConfig(value) {
|
|
|
12018
12035
|
const paths = readPaths(key);
|
|
12019
12036
|
if (paths) config[key] = paths;
|
|
12020
12037
|
}
|
|
12021
|
-
if (
|
|
12038
|
+
if (isRecord10(value.statusMap)) {
|
|
12022
12039
|
config.statusMap = value.statusMap;
|
|
12023
12040
|
}
|
|
12024
12041
|
if (Array.isArray(value.rules)) {
|
|
@@ -12027,10 +12044,10 @@ function emailStatusExtractorConfig(value) {
|
|
|
12027
12044
|
return config;
|
|
12028
12045
|
}
|
|
12029
12046
|
function extractorDescriptorRecord(value) {
|
|
12030
|
-
if (!
|
|
12047
|
+
if (!isRecord10(value)) return {};
|
|
12031
12048
|
return Object.fromEntries(
|
|
12032
12049
|
Object.entries(value).flatMap(([key, descriptor]) => {
|
|
12033
|
-
if (!
|
|
12050
|
+
if (!isRecord10(descriptor)) return [];
|
|
12034
12051
|
const paths = stringArray(descriptor.paths).map((path) => path.trim()).filter(Boolean);
|
|
12035
12052
|
if (paths.length === 0) return [];
|
|
12036
12053
|
const transforms = stringArray(descriptor.transforms).map((transform) => transform.trim()).filter(Boolean);
|
|
@@ -12052,7 +12069,7 @@ function extractorDescriptorRecord(value) {
|
|
|
12052
12069
|
}
|
|
12053
12070
|
function rowsFromUnknown(value) {
|
|
12054
12071
|
if (!Array.isArray(value)) return [];
|
|
12055
|
-
return value.map((row) =>
|
|
12072
|
+
return value.map((row) => isRecord10(row) ? row : { value: row });
|
|
12056
12073
|
}
|
|
12057
12074
|
function finiteNonNegativeInteger3(value) {
|
|
12058
12075
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
@@ -12074,8 +12091,8 @@ function stableHash(value) {
|
|
|
12074
12091
|
}
|
|
12075
12092
|
function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
12076
12093
|
if (!options || !isQueryResultDatasetTool(toolId)) return result;
|
|
12077
|
-
const raw =
|
|
12078
|
-
const dataset =
|
|
12094
|
+
const raw = isRecord10(result.toolResponse.raw) ? result.toolResponse.raw : null;
|
|
12095
|
+
const dataset = isRecord10(raw?.dataset) ? raw.dataset : null;
|
|
12079
12096
|
const totalRows = finiteNonNegativeInteger3(dataset?.total_rows);
|
|
12080
12097
|
const sql = typeof options.input.sql === "string" ? options.input.sql : typeof options.input.query === "string" ? options.input.query : typeof raw?.sql === "string" ? raw.sql : null;
|
|
12081
12098
|
if (!dataset || totalRows === null || !sql) {
|
|
@@ -12107,7 +12124,7 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
12107
12124
|
} : {}
|
|
12108
12125
|
}
|
|
12109
12126
|
});
|
|
12110
|
-
const pageRaw =
|
|
12127
|
+
const pageRaw = isRecord10(response.toolResponse?.raw) ? response.toolResponse.raw : null;
|
|
12111
12128
|
return rowsFromUnknown(pageRaw?.rows);
|
|
12112
12129
|
};
|
|
12113
12130
|
const collectRows = async (limit) => {
|
|
@@ -12164,8 +12181,8 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
12164
12181
|
const rawV2 = response.toolResponse?.rawV2;
|
|
12165
12182
|
const view = response.toolResponse?.view;
|
|
12166
12183
|
const meta = response.toolResponse?.meta;
|
|
12167
|
-
const metadata =
|
|
12168
|
-
const toolMetadata =
|
|
12184
|
+
const metadata = isRecord10(response._metadata) ? response._metadata.tool : null;
|
|
12185
|
+
const toolMetadata = isRecord10(metadata) ? metadata : {};
|
|
12169
12186
|
const result = attachSdkQueryResultDatasetResult(
|
|
12170
12187
|
fallbackToolId,
|
|
12171
12188
|
createToolExecuteResult({
|
|
@@ -12173,12 +12190,12 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
12173
12190
|
jobId: typeof response.job_id === "string" ? response.job_id : void 0,
|
|
12174
12191
|
result: {
|
|
12175
12192
|
data: raw,
|
|
12176
|
-
...
|
|
12193
|
+
...isRecord10(meta) ? { meta } : {}
|
|
12177
12194
|
},
|
|
12178
12195
|
response: {
|
|
12179
12196
|
...rawV2 !== void 0 ? { rawV2 } : {},
|
|
12180
12197
|
...view === "data" || view === "rawV2" ? { view } : {},
|
|
12181
|
-
...
|
|
12198
|
+
...isRecord10(meta) ? { meta } : {}
|
|
12182
12199
|
},
|
|
12183
12200
|
metadata: {
|
|
12184
12201
|
toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
|
|
@@ -12194,12 +12211,12 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
12194
12211
|
cached: false,
|
|
12195
12212
|
source: "live"
|
|
12196
12213
|
},
|
|
12197
|
-
meta:
|
|
12214
|
+
meta: isRecord10(response.meta) ? response.meta : void 0,
|
|
12198
12215
|
billing: response.billing
|
|
12199
12216
|
}),
|
|
12200
12217
|
options
|
|
12201
12218
|
);
|
|
12202
|
-
const executionRecovery =
|
|
12219
|
+
const executionRecovery = isRecord10(response.executionRecovery) ? response.executionRecovery : void 0;
|
|
12203
12220
|
if (typeof response.idempotencyKey === "string") {
|
|
12204
12221
|
result.idempotencyKey = response.idempotencyKey;
|
|
12205
12222
|
}
|