deepline 0.3.231 → 0.3.233
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/deployment/fly-machines.ts +2 -0
- 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/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +20 -1
- package/dist/cli/index.js +831 -800
- package/dist/cli/index.mjs +831 -795
- 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.mjs
CHANGED
|
@@ -718,6 +718,409 @@ function resolveConfig(options) {
|
|
|
718
718
|
};
|
|
719
719
|
}
|
|
720
720
|
|
|
721
|
+
// ../integration-contracts/theirstack/execution-policy.ts
|
|
722
|
+
var THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS = 135e3;
|
|
723
|
+
var THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS = 6e4 + THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS + 15e3;
|
|
724
|
+
var THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS = 21e4;
|
|
725
|
+
var LONG_JOB_SEARCH_WINDOW_MS = 365 * 24 * 60 * 60 * 1e3;
|
|
726
|
+
var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
727
|
+
function parseDateOnly(value) {
|
|
728
|
+
if (typeof value !== "string" || !DATE_ONLY_PATTERN.test(value)) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
const timestamp = Date.parse(`${value}T00:00:00.000Z`);
|
|
732
|
+
if (!Number.isFinite(timestamp)) {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
return new Date(timestamp).toISOString().slice(0, 10) === value ? timestamp : null;
|
|
736
|
+
}
|
|
737
|
+
function usesLongExplicitDateWindow(payload) {
|
|
738
|
+
const postedAtGte = parseDateOnly(payload.posted_at_gte);
|
|
739
|
+
const postedAtLte = parseDateOnly(payload.posted_at_lte);
|
|
740
|
+
if (postedAtGte !== null && postedAtLte !== null) {
|
|
741
|
+
return postedAtLte - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
742
|
+
}
|
|
743
|
+
if (postedAtGte !== null) {
|
|
744
|
+
return Date.now() - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
745
|
+
}
|
|
746
|
+
return postedAtLte !== null && payload.posted_at_gte == null;
|
|
747
|
+
}
|
|
748
|
+
function parseMaxAgeDays(value) {
|
|
749
|
+
if (typeof value === "number") {
|
|
750
|
+
return Number.isFinite(value) ? value : null;
|
|
751
|
+
}
|
|
752
|
+
if (typeof value !== "string" || !/^-?\d+$/.test(value.trim())) {
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
const parsed = Number(value.trim());
|
|
756
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
757
|
+
}
|
|
758
|
+
function usesExtendedTheirstackJobSearchBudget(endpointId, payload) {
|
|
759
|
+
if (endpointId !== "theirstack_job_search") {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
if (payload.include_total_results === true) {
|
|
763
|
+
return true;
|
|
764
|
+
}
|
|
765
|
+
const maxAgeDays = parseMaxAgeDays(payload.posted_at_max_age_days);
|
|
766
|
+
return maxAgeDays !== null && maxAgeDays >= 365 ? true : usesLongExplicitDateWindow(payload);
|
|
767
|
+
}
|
|
768
|
+
function resolveTheirstackClientTimeoutMs(endpointId, payload) {
|
|
769
|
+
if (endpointId === "theirstack_company_search") {
|
|
770
|
+
return THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS;
|
|
771
|
+
}
|
|
772
|
+
return usesExtendedTheirstackJobSearchBudget(endpointId, payload) ? THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS : null;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// ../integration-contracts/waterfall/execution-policy.ts
|
|
776
|
+
var WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS = 18e4;
|
|
777
|
+
var WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
778
|
+
"prospector",
|
|
779
|
+
"deepline_native_prospector"
|
|
780
|
+
]);
|
|
781
|
+
function resolveWaterfallClientTimeoutMs(toolId) {
|
|
782
|
+
return WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase()) ? WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS : null;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// ../integration-contracts/bettercontact/execution-policy.ts
|
|
786
|
+
var BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS = 12e4;
|
|
787
|
+
var BETTERCONTACT_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
788
|
+
"bettercontact_enrich",
|
|
789
|
+
"bettercontact_bulk_enrich"
|
|
790
|
+
]);
|
|
791
|
+
function usesExtendedBetterContactLauncherBudget(toolId) {
|
|
792
|
+
return BETTERCONTACT_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase());
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// ../plays/tool-response-contract.ts
|
|
796
|
+
var RAW_V2_TOOL_RESPONSE_CONTRACT = "raw-v2";
|
|
797
|
+
function legacyRawFromToolResponseRawV2(rawV2, view, responseMeta) {
|
|
798
|
+
const legacyRaw = view === "data" && rawV2 && typeof rawV2 === "object" && !Array.isArray(rawV2) ? rawV2.data : rawV2;
|
|
799
|
+
const deeplineBilling = responseMeta?.deepline_billing;
|
|
800
|
+
if (view === "rawV2" && deeplineBilling !== void 0 && legacyRaw && typeof legacyRaw === "object" && !Array.isArray(legacyRaw)) {
|
|
801
|
+
return {
|
|
802
|
+
...legacyRaw,
|
|
803
|
+
deepline_billing: deeplineBilling
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
return legacyRaw;
|
|
807
|
+
}
|
|
808
|
+
function providerMetaFromToolResponseRawV2(rawV2, view) {
|
|
809
|
+
if (view !== "data" || !rawV2 || typeof rawV2 !== "object" || Array.isArray(rawV2)) {
|
|
810
|
+
return void 0;
|
|
811
|
+
}
|
|
812
|
+
const meta = rawV2.meta;
|
|
813
|
+
return meta && typeof meta === "object" && !Array.isArray(meta) ? meta : void 0;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/tool-calls.ts
|
|
817
|
+
var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
|
|
818
|
+
var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
|
|
819
|
+
var EXECUTE_RESPONSE_INTENT_HEADER = "x-deepline-execute-response-intent";
|
|
820
|
+
var RAW_V2_EXECUTE_RESPONSE_CONTRACT = RAW_V2_TOOL_RESPONSE_CONTRACT;
|
|
821
|
+
var DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
822
|
+
function validateExecutionIdempotencyKey(key) {
|
|
823
|
+
if (typeof key !== "string" || key.length < 1 || key.length > 200 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
|
|
824
|
+
throw new DeeplineError(
|
|
825
|
+
"Execution idempotency keys must be 1\u2013200 ASCII letters, digits, dots, underscores, colons, or hyphens.",
|
|
826
|
+
void 0,
|
|
827
|
+
"IDEMPOTENCY_KEY_INVALID"
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function getExecutionRecoveryState(value) {
|
|
832
|
+
if (!isRecord2(value) || !isRecord2(value.executionRecovery)) return null;
|
|
833
|
+
const state = value.executionRecovery.state;
|
|
834
|
+
return state === "running" || state === "completed" || state === "outcome_unknown" ? state : null;
|
|
835
|
+
}
|
|
836
|
+
function isRecoverableExecutionAttemptError(error) {
|
|
837
|
+
if (error instanceof ToolExecutionError) {
|
|
838
|
+
return error.code === "EXECUTION_IN_PROGRESS" || error.origin === "deepline" && error.category === "network" && error.networkScope === "client_to_deepline";
|
|
839
|
+
}
|
|
840
|
+
return error instanceof DeeplineError && (error.code === "EXECUTION_IN_PROGRESS" || error.code?.startsWith("NETWORK_") === true && error.statusCode === void 0);
|
|
841
|
+
}
|
|
842
|
+
function isRecoverableExecutionLookupError(error) {
|
|
843
|
+
if (isRecoverableExecutionAttemptError(error)) return true;
|
|
844
|
+
return error instanceof DeeplineError && (error.statusCode === 429 || error.statusCode !== void 0 && error.statusCode >= 500);
|
|
845
|
+
}
|
|
846
|
+
function timeoutWithinRecoveryBudget(requestTimeoutMs, defaultRequestTimeoutMs, remainingMs) {
|
|
847
|
+
return Math.min(requestTimeoutMs ?? defaultRequestTimeoutMs, remainingMs);
|
|
848
|
+
}
|
|
849
|
+
function executionRecoveryError(input) {
|
|
850
|
+
return new ToolExecutionError(input.message, {
|
|
851
|
+
toolId: input.toolId,
|
|
852
|
+
provider: null,
|
|
853
|
+
operation: input.toolId,
|
|
854
|
+
code: input.code,
|
|
855
|
+
origin: "deepline",
|
|
856
|
+
category: input.code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown" : "conflict",
|
|
857
|
+
retryable: input.code !== "EXECUTION_OUTCOME_UNKNOWN",
|
|
858
|
+
statusCode: null,
|
|
859
|
+
requestId: null,
|
|
860
|
+
retryAfterMs: null,
|
|
861
|
+
networkKind: null,
|
|
862
|
+
networkScope: null,
|
|
863
|
+
publicDetails: { idempotencyKey: input.idempotencyKey }
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
867
|
+
var APIFY_SYNC_DEFAULT_TIMEOUT_MS = 3e5;
|
|
868
|
+
var APIFY_SYNC_RESPONSE_GRACE_MS = 9e4;
|
|
869
|
+
function resolveToolExecuteTimeoutMs(toolId, input) {
|
|
870
|
+
const normalized = toolId.trim().toLowerCase();
|
|
871
|
+
if (normalized === "apify_run_actor_sync") {
|
|
872
|
+
const requestedTimeoutMs = input.timeoutMs ?? APIFY_SYNC_DEFAULT_TIMEOUT_MS;
|
|
873
|
+
if (typeof requestedTimeoutMs === "number" && Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0) {
|
|
874
|
+
return Math.floor(requestedTimeoutMs) + APIFY_SYNC_RESPONSE_GRACE_MS;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const theirstackTimeoutMs = resolveTheirstackClientTimeoutMs(
|
|
878
|
+
normalized,
|
|
879
|
+
input
|
|
880
|
+
);
|
|
881
|
+
if (theirstackTimeoutMs !== null) return theirstackTimeoutMs;
|
|
882
|
+
const waterfallTimeoutMs = resolveWaterfallClientTimeoutMs(normalized);
|
|
883
|
+
if (waterfallTimeoutMs !== null) return waterfallTimeoutMs;
|
|
884
|
+
if (usesExtendedBetterContactLauncherBudget(normalized)) {
|
|
885
|
+
return BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS;
|
|
886
|
+
}
|
|
887
|
+
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;
|
|
888
|
+
}
|
|
889
|
+
function isRecord2(value) {
|
|
890
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
891
|
+
}
|
|
892
|
+
function materializeToolExecutionResponse(response) {
|
|
893
|
+
const toolResponse = response.toolResponse;
|
|
894
|
+
if (!toolResponse && isRecord2(response.result)) {
|
|
895
|
+
const legacyResult = response.result;
|
|
896
|
+
if (Object.prototype.hasOwnProperty.call(legacyResult, "data")) {
|
|
897
|
+
const legacyMeta = isRecord2(legacyResult.meta) ? legacyResult.meta : void 0;
|
|
898
|
+
return {
|
|
899
|
+
...response,
|
|
900
|
+
toolResponse: {
|
|
901
|
+
raw: legacyResult.data,
|
|
902
|
+
...legacyMeta ? { meta: legacyMeta } : {}
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
if (!toolResponse || Object.prototype.hasOwnProperty.call(toolResponse, "raw")) {
|
|
908
|
+
return response;
|
|
909
|
+
}
|
|
910
|
+
const rawV2 = toolResponse.rawV2;
|
|
911
|
+
const view = toolResponse.view;
|
|
912
|
+
const providerMeta = providerMetaFromToolResponseRawV2(
|
|
913
|
+
rawV2,
|
|
914
|
+
view ?? "rawV2"
|
|
915
|
+
);
|
|
916
|
+
const responseMeta = isRecord2(toolResponse.responseMeta) ? toolResponse.responseMeta : void 0;
|
|
917
|
+
return {
|
|
918
|
+
...response,
|
|
919
|
+
toolResponse: {
|
|
920
|
+
...toolResponse,
|
|
921
|
+
raw: legacyRawFromToolResponseRawV2(
|
|
922
|
+
rawV2,
|
|
923
|
+
view ?? "rawV2",
|
|
924
|
+
responseMeta
|
|
925
|
+
),
|
|
926
|
+
...toolResponse.meta || providerMeta || responseMeta ? {
|
|
927
|
+
meta: {
|
|
928
|
+
...toolResponse.meta ?? {},
|
|
929
|
+
...providerMeta ?? {},
|
|
930
|
+
...responseMeta ?? {}
|
|
931
|
+
}
|
|
932
|
+
} : {}
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
var ToolCalls = class {
|
|
937
|
+
constructor(http, defaultRequestTimeoutMs) {
|
|
938
|
+
this.http = http;
|
|
939
|
+
this.defaultRequestTimeoutMs = defaultRequestTimeoutMs;
|
|
940
|
+
}
|
|
941
|
+
async call(toolId, input, options) {
|
|
942
|
+
const inputSnapshot = JSON.parse(JSON.stringify(input));
|
|
943
|
+
const metadataSnapshot = options?.metadata ? JSON.parse(JSON.stringify(options.metadata)) : void 0;
|
|
944
|
+
const idempotencyKey = options?.idempotencyKey ?? (options?.recover ? crypto.randomUUID() : void 0);
|
|
945
|
+
if (idempotencyKey !== void 0) {
|
|
946
|
+
validateExecutionIdempotencyKey(idempotencyKey);
|
|
947
|
+
if (options?.recoveryTimeoutMs !== void 0 && (!Number.isFinite(options.recoveryTimeoutMs) || options.recoveryTimeoutMs < 0)) {
|
|
948
|
+
throw new DeeplineError(
|
|
949
|
+
"recoveryTimeoutMs must be a finite, non-negative number.",
|
|
950
|
+
void 0,
|
|
951
|
+
"IDEMPOTENCY_KEY_INVALID"
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
await options?.onExecution?.({ idempotencyKey });
|
|
955
|
+
}
|
|
956
|
+
const timeoutMs = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
|
|
957
|
+
if (idempotencyKey !== void 0) {
|
|
958
|
+
await this.lookupExecutionByKey(idempotencyKey, timeoutMs);
|
|
959
|
+
}
|
|
960
|
+
const isApifySync = toolId.trim().toLowerCase() === "apify_run_actor_sync";
|
|
961
|
+
const headers = {
|
|
962
|
+
[EXECUTE_RESPONSE_CONTRACT_HEADER]: RAW_V2_EXECUTE_RESPONSE_CONTRACT,
|
|
963
|
+
...isApifySync ? { "X-Deepline-Apify-Sync-Response-Budget": "extended-v1" } : {},
|
|
964
|
+
[TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
|
|
965
|
+
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
966
|
+
),
|
|
967
|
+
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
968
|
+
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw",
|
|
969
|
+
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
|
|
970
|
+
...options?.searchRef ? { "x-deepline-search-ref": options.searchRef } : {}
|
|
971
|
+
};
|
|
972
|
+
const request = (requestTimeoutMs) => this.http.post(
|
|
973
|
+
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
974
|
+
{
|
|
975
|
+
payload: inputSnapshot,
|
|
976
|
+
...metadataSnapshot ? { metadata: metadataSnapshot } : {}
|
|
977
|
+
},
|
|
978
|
+
headers,
|
|
979
|
+
{
|
|
980
|
+
timeout: requestTimeoutMs,
|
|
981
|
+
maxRetries: idempotencyKey ? 0 : options?.maxRetries ?? 0,
|
|
982
|
+
retryApiErrors: options?.retryApiErrors === true,
|
|
983
|
+
exactUrlOnly: true,
|
|
984
|
+
toolId,
|
|
985
|
+
idempotencyKey
|
|
986
|
+
}
|
|
987
|
+
);
|
|
988
|
+
let response;
|
|
989
|
+
let recoveryDeadline = null;
|
|
990
|
+
const recoveryTimeoutMs = options?.recoveryTimeoutMs ?? DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS;
|
|
991
|
+
let retryDelayMs = 1e3;
|
|
992
|
+
const recoveryTimeoutError = () => executionRecoveryError({
|
|
993
|
+
toolId,
|
|
994
|
+
idempotencyKey,
|
|
995
|
+
code: "EXECUTION_RECOVERY_TIMEOUT",
|
|
996
|
+
message: `Execution recovery for ${idempotencyKey} did not finish before the recovery timeout. Inspect client.executions.getByKey() and resume with the same idempotency key.`
|
|
997
|
+
});
|
|
998
|
+
const waitForRecoveryRetry = async (deadline) => {
|
|
999
|
+
const remainingMs = deadline - Date.now();
|
|
1000
|
+
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
1001
|
+
await new Promise(
|
|
1002
|
+
(resolve2) => setTimeout(resolve2, Math.min(retryDelayMs, remainingMs))
|
|
1003
|
+
);
|
|
1004
|
+
retryDelayMs = Math.min(retryDelayMs * 2, 5e3);
|
|
1005
|
+
};
|
|
1006
|
+
const lookupDuringRecovery = async () => {
|
|
1007
|
+
while (true) {
|
|
1008
|
+
const remainingMs = recoveryDeadline - Date.now();
|
|
1009
|
+
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
1010
|
+
try {
|
|
1011
|
+
return await this.lookupExecutionByKey(
|
|
1012
|
+
idempotencyKey,
|
|
1013
|
+
timeoutWithinRecoveryBudget(
|
|
1014
|
+
timeoutMs,
|
|
1015
|
+
this.defaultRequestTimeoutMs,
|
|
1016
|
+
remainingMs
|
|
1017
|
+
)
|
|
1018
|
+
);
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
if (!isRecoverableExecutionLookupError(error)) throw error;
|
|
1021
|
+
await waitForRecoveryRetry(recoveryDeadline);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
while (true) {
|
|
1026
|
+
const remainingMs = recoveryDeadline === null ? null : recoveryDeadline - Date.now();
|
|
1027
|
+
if (remainingMs !== null && remainingMs <= 0) {
|
|
1028
|
+
throw recoveryTimeoutError();
|
|
1029
|
+
}
|
|
1030
|
+
try {
|
|
1031
|
+
response = await request(
|
|
1032
|
+
remainingMs === null ? timeoutMs : timeoutWithinRecoveryBudget(
|
|
1033
|
+
timeoutMs,
|
|
1034
|
+
this.defaultRequestTimeoutMs,
|
|
1035
|
+
remainingMs
|
|
1036
|
+
)
|
|
1037
|
+
);
|
|
1038
|
+
const recoveryState = getExecutionRecoveryState(response);
|
|
1039
|
+
if (recoveryState === "outcome_unknown") {
|
|
1040
|
+
if (!idempotencyKey) break;
|
|
1041
|
+
throw executionRecoveryError({
|
|
1042
|
+
toolId,
|
|
1043
|
+
idempotencyKey,
|
|
1044
|
+
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
1045
|
+
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
if (!idempotencyKey || recoveryState !== "running") {
|
|
1049
|
+
break;
|
|
1050
|
+
}
|
|
1051
|
+
if (recoveryDeadline === null) {
|
|
1052
|
+
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
1053
|
+
}
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
if (idempotencyKey && error instanceof DeeplineError && error.code === "EXECUTION_OUTCOME_UNKNOWN") {
|
|
1056
|
+
throw executionRecoveryError({
|
|
1057
|
+
toolId,
|
|
1058
|
+
idempotencyKey,
|
|
1059
|
+
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
1060
|
+
message: error.message
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
if (!idempotencyKey || !isRecoverableExecutionAttemptError(error)) {
|
|
1064
|
+
throw error;
|
|
1065
|
+
}
|
|
1066
|
+
if (recoveryDeadline === null) {
|
|
1067
|
+
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
await waitForRecoveryRetry(recoveryDeadline);
|
|
1071
|
+
const recovered = await lookupDuringRecovery();
|
|
1072
|
+
if (getExecutionRecoveryState(recovered) === "outcome_unknown") {
|
|
1073
|
+
throw executionRecoveryError({
|
|
1074
|
+
toolId,
|
|
1075
|
+
idempotencyKey,
|
|
1076
|
+
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
1077
|
+
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const materialized = materializeToolExecutionResponse(response);
|
|
1082
|
+
return idempotencyKey ? { ...materialized, idempotencyKey } : materialized;
|
|
1083
|
+
}
|
|
1084
|
+
/** Read the durable state of a keyed tool execution. */
|
|
1085
|
+
async getByKey(idempotencyKey) {
|
|
1086
|
+
validateExecutionIdempotencyKey(idempotencyKey);
|
|
1087
|
+
const result = await this.lookupExecutionByKey(idempotencyKey);
|
|
1088
|
+
if (!result) {
|
|
1089
|
+
throw new DeeplineError(
|
|
1090
|
+
`No execution exists for idempotency key ${idempotencyKey}.`,
|
|
1091
|
+
404,
|
|
1092
|
+
"EXECUTION_NOT_FOUND"
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
return result;
|
|
1096
|
+
}
|
|
1097
|
+
async lookupExecutionByKey(idempotencyKey, timeoutMs) {
|
|
1098
|
+
validateExecutionIdempotencyKey(idempotencyKey);
|
|
1099
|
+
let supported = false;
|
|
1100
|
+
const result = await this.http.get(
|
|
1101
|
+
`/api/v2/executions/by-key/${encodeURIComponent(idempotencyKey)}`,
|
|
1102
|
+
{
|
|
1103
|
+
exactUrlOnly: true,
|
|
1104
|
+
maxRetries: 0,
|
|
1105
|
+
timeout: timeoutMs,
|
|
1106
|
+
idempotencyKey,
|
|
1107
|
+
allowNotFound: true,
|
|
1108
|
+
onResponse: (response) => {
|
|
1109
|
+
supported = response.headers.get("X-Deepline-Idempotency-Supported") === "true";
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
);
|
|
1113
|
+
if (!supported) {
|
|
1114
|
+
throw new DeeplineError(
|
|
1115
|
+
"This Deepline server does not support recoverable tool executions; no tool was dispatched.",
|
|
1116
|
+
422,
|
|
1117
|
+
"IDEMPOTENCY_NOT_SUPPORTED"
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
return result;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
|
|
721
1124
|
// ../plays/artifact-contract-version.ts
|
|
722
1125
|
var CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION = 2;
|
|
723
1126
|
|
|
@@ -768,7 +1171,7 @@ var SDK_RELEASE = {
|
|
|
768
1171
|
// getters keep their established compatibility behavior.
|
|
769
1172
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
770
1173
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
771
|
-
version: "0.3.
|
|
1174
|
+
version: "0.3.233",
|
|
772
1175
|
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.",
|
|
773
1176
|
packageCapabilities: {
|
|
774
1177
|
updatePreferences: 1
|
|
@@ -1415,7 +1818,7 @@ function providerLabelFromToolId(toolId) {
|
|
|
1415
1818
|
const provider = normalized.split(/[_:./-]+/)[0];
|
|
1416
1819
|
return provider || normalized || "provider";
|
|
1417
1820
|
}
|
|
1418
|
-
function
|
|
1821
|
+
function isRecord3(value) {
|
|
1419
1822
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1420
1823
|
}
|
|
1421
1824
|
var HttpClient = class {
|
|
@@ -1567,7 +1970,7 @@ var HttpClient = class {
|
|
|
1567
1970
|
const parsed = parseResponseBody(body);
|
|
1568
1971
|
const structuredToolError = options?.toolId && !response.ok ? deserializeToolExecutionFailure(
|
|
1569
1972
|
apiErrorMessage(parsed, response.status),
|
|
1570
|
-
|
|
1973
|
+
isRecord3(parsed) ? parsed.tool_error : null,
|
|
1571
1974
|
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
1572
1975
|
) : null;
|
|
1573
1976
|
if (structuredToolError) {
|
|
@@ -2613,11 +3016,11 @@ function buildPlayDocflowNodeErrorPreview(error, redactor = createSecretRedactio
|
|
|
2613
3016
|
return "Non-Error value thrown (message unavailable)";
|
|
2614
3017
|
}
|
|
2615
3018
|
}
|
|
2616
|
-
function
|
|
3019
|
+
function isRecord4(value) {
|
|
2617
3020
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
2618
3021
|
}
|
|
2619
3022
|
function normalizePreview(value, depth) {
|
|
2620
|
-
if (!
|
|
3023
|
+
if (!isRecord4(value) || typeof value.kind !== "string") return null;
|
|
2621
3024
|
if (value.kind === "null") return { kind: "null" };
|
|
2622
3025
|
if (value.kind === "scalar") {
|
|
2623
3026
|
if (typeof value.value === "string" || typeof value.value === "boolean" || typeof value.value === "number" && Number.isFinite(value.value)) {
|
|
@@ -2682,7 +3085,7 @@ function normalizePreview(value, depth) {
|
|
|
2682
3085
|
...value.truncated === true || totalItems > items.length ? { truncated: true } : {}
|
|
2683
3086
|
};
|
|
2684
3087
|
}
|
|
2685
|
-
if (value.kind === "object" &&
|
|
3088
|
+
if (value.kind === "object" && isRecord4(value.fields)) {
|
|
2686
3089
|
const fields = {};
|
|
2687
3090
|
for (const [key, field] of Object.entries(value.fields).slice(
|
|
2688
3091
|
0,
|
|
@@ -2702,10 +3105,10 @@ function normalizePreview(value, depth) {
|
|
|
2702
3105
|
return null;
|
|
2703
3106
|
}
|
|
2704
3107
|
function normalizePlayDocflowNodeIoState(value) {
|
|
2705
|
-
if (!
|
|
3108
|
+
if (!isRecord4(value)) return void 0;
|
|
2706
3109
|
const attempt = typeof value.attempt === "number" && Number.isFinite(value.attempt) ? Math.max(0, Math.floor(value.attempt)) : 0;
|
|
2707
3110
|
const normalizeMap = (raw) => {
|
|
2708
|
-
if (!
|
|
3111
|
+
if (!isRecord4(raw)) return void 0;
|
|
2709
3112
|
const output = {};
|
|
2710
3113
|
for (const [path, preview] of Object.entries(raw).slice(
|
|
2711
3114
|
0,
|
|
@@ -2742,11 +3145,11 @@ function normalizePlayDocflowNodeIoState(value) {
|
|
|
2742
3145
|
}
|
|
2743
3146
|
|
|
2744
3147
|
// ../play-runtime/activity-observation.ts
|
|
2745
|
-
function
|
|
3148
|
+
function isRecord5(value) {
|
|
2746
3149
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
2747
3150
|
}
|
|
2748
3151
|
function isPlayActivityObservation(value) {
|
|
2749
|
-
if (!
|
|
3152
|
+
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)) {
|
|
2750
3153
|
return false;
|
|
2751
3154
|
}
|
|
2752
3155
|
const targetKinds = /* @__PURE__ */ new Set([
|
|
@@ -3046,7 +3449,7 @@ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
3046
3449
|
"terminated",
|
|
3047
3450
|
"timed_out"
|
|
3048
3451
|
]);
|
|
3049
|
-
function
|
|
3452
|
+
function isRecord6(value) {
|
|
3050
3453
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3051
3454
|
}
|
|
3052
3455
|
function finiteNumber(value) {
|
|
@@ -3061,7 +3464,7 @@ function isWorkCounterSegmentId(value) {
|
|
|
3061
3464
|
);
|
|
3062
3465
|
}
|
|
3063
3466
|
function normalizePlayRunLedgerTerminalWorkCounterSegment(value) {
|
|
3064
|
-
if (!
|
|
3467
|
+
if (!isRecord6(value)) return void 0;
|
|
3065
3468
|
if (!nonnegativeSafeInteger(value.attempt) || !nonnegativeSafeInteger(value.invocationSeq) || value.invocationSeq === 0 || !isWorkCounterSegmentId(value.segmentId)) {
|
|
3066
3469
|
return void 0;
|
|
3067
3470
|
}
|
|
@@ -3085,7 +3488,7 @@ function hasConfirmedPlayRunLedgerWorkCounters(snapshot) {
|
|
|
3085
3488
|
);
|
|
3086
3489
|
}
|
|
3087
3490
|
function normalizeWorkCounters(value) {
|
|
3088
|
-
if (!
|
|
3491
|
+
if (!isRecord6(value)) return void 0;
|
|
3089
3492
|
for (const field of [
|
|
3090
3493
|
"attempt",
|
|
3091
3494
|
"invocationSeq",
|
|
@@ -3175,8 +3578,8 @@ function summarizeRunRowOutcomes(snapshot) {
|
|
|
3175
3578
|
const stepTotal = finiteNumber(progress.total);
|
|
3176
3579
|
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);
|
|
3177
3580
|
}
|
|
3178
|
-
const resultSummary =
|
|
3179
|
-
const resultRowOutcomes =
|
|
3581
|
+
const resultSummary = isRecord6(snapshot.resultSummary) ? snapshot.resultSummary : null;
|
|
3582
|
+
const resultRowOutcomes = isRecord6(resultSummary?.rowOutcomes) ? resultSummary.rowOutcomes : null;
|
|
3180
3583
|
const terminalCompletedRows = finiteNumber(resultRowOutcomes?.completedRows);
|
|
3181
3584
|
const terminalFailedRows = finiteNumber(resultRowOutcomes?.failedRows);
|
|
3182
3585
|
const terminalTotalRows = finiteNumber(resultRowOutcomes?.totalRows);
|
|
@@ -3225,21 +3628,21 @@ function createEmptyPlayRunLedgerSnapshot(input) {
|
|
|
3225
3628
|
};
|
|
3226
3629
|
}
|
|
3227
3630
|
function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
3228
|
-
if (!
|
|
3631
|
+
if (!isRecord6(value)) {
|
|
3229
3632
|
return createEmptyPlayRunLedgerSnapshot(fallback);
|
|
3230
3633
|
}
|
|
3231
3634
|
const orderedStepIds = Array.isArray(value.orderedStepIds) ? value.orderedStepIds.filter(
|
|
3232
3635
|
(entry) => typeof entry === "string" && Boolean(entry.trim())
|
|
3233
3636
|
) : [];
|
|
3234
|
-
const rawSteps =
|
|
3637
|
+
const rawSteps = isRecord6(value.stepsById) ? value.stepsById : {};
|
|
3235
3638
|
const stepsById = {};
|
|
3236
3639
|
for (const [stepId, rawStep] of Object.entries(rawSteps)) {
|
|
3237
|
-
if (!stepId.trim() || !
|
|
3640
|
+
if (!stepId.trim() || !isRecord6(rawStep)) continue;
|
|
3238
3641
|
const rawStatus = normalizeStepStatus(rawStep.status);
|
|
3239
3642
|
if (!rawStatus) continue;
|
|
3240
3643
|
const completedAt = finiteNumber(rawStep.completedAt);
|
|
3241
3644
|
const status = rawStatus === "running" && completedAt !== null ? "completed" : rawStatus;
|
|
3242
|
-
const rawProgress =
|
|
3645
|
+
const rawProgress = isRecord6(rawStep.progress) ? rawStep.progress : null;
|
|
3243
3646
|
stepsById[stepId] = {
|
|
3244
3647
|
stepId,
|
|
3245
3648
|
label: optionalString(rawStep.label),
|
|
@@ -3255,10 +3658,10 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
3255
3658
|
progress: rawProgress ? normalizeStepProgress(rawProgress) : null
|
|
3256
3659
|
};
|
|
3257
3660
|
}
|
|
3258
|
-
const rawDatasets =
|
|
3661
|
+
const rawDatasets = isRecord6(value.datasetsById) ? value.datasetsById : {};
|
|
3259
3662
|
const datasetsById = {};
|
|
3260
3663
|
for (const [datasetId, rawDataset] of Object.entries(rawDatasets)) {
|
|
3261
|
-
if (!datasetId.trim() || !
|
|
3664
|
+
if (!datasetId.trim() || !isRecord6(rawDataset)) continue;
|
|
3262
3665
|
const phase = rawDataset.phase === "available" || rawDataset.phase === "failed" ? rawDataset.phase : "registered";
|
|
3263
3666
|
const datasetBornFrom = normalizeDatasetBornFrom(rawDataset.bornFrom);
|
|
3264
3667
|
datasetsById[datasetId] = {
|
|
@@ -3281,7 +3684,7 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
3281
3684
|
updatedAt: finiteNumber(rawDataset.updatedAt) ?? 0
|
|
3282
3685
|
};
|
|
3283
3686
|
}
|
|
3284
|
-
const rawActivities =
|
|
3687
|
+
const rawActivities = isRecord6(value.activitiesById) ? value.activitiesById : {};
|
|
3285
3688
|
const activitiesById = {};
|
|
3286
3689
|
for (const [activityId, rawActivity] of Object.entries(rawActivities)) {
|
|
3287
3690
|
if (activityId.trim() && isPlayActivityObservation(rawActivity) && rawActivity.activityId === activityId) {
|
|
@@ -3471,18 +3874,18 @@ function normalizePlayRunLiveStatus(value) {
|
|
|
3471
3874
|
function isTerminalPlayRunLiveStatus(status) {
|
|
3472
3875
|
return isTerminalPlayRunLifecycleStatus(status);
|
|
3473
3876
|
}
|
|
3474
|
-
function
|
|
3877
|
+
function isRecord7(value) {
|
|
3475
3878
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3476
3879
|
}
|
|
3477
3880
|
function finiteNumber2(value) {
|
|
3478
3881
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
3479
3882
|
}
|
|
3480
3883
|
function extractTerminalRunLogTail(result) {
|
|
3481
|
-
if (!
|
|
3884
|
+
if (!isRecord7(result) || !isRecord7(result._metadata)) {
|
|
3482
3885
|
return null;
|
|
3483
3886
|
}
|
|
3484
3887
|
const runLogTail = result._metadata.runLogTail;
|
|
3485
|
-
if (!
|
|
3888
|
+
if (!isRecord7(runLogTail) || !Array.isArray(runLogTail.tail)) {
|
|
3486
3889
|
return null;
|
|
3487
3890
|
}
|
|
3488
3891
|
const logTail = runLogTail.tail.filter(
|
|
@@ -4142,80 +4545,6 @@ function isStopAllPlayRunsDryRunResult(result) {
|
|
|
4142
4545
|
return "dryRun" in result && result.dryRun === true;
|
|
4143
4546
|
}
|
|
4144
4547
|
|
|
4145
|
-
// ../integration-contracts/theirstack/execution-policy.ts
|
|
4146
|
-
var THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS = 135e3;
|
|
4147
|
-
var THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS = 6e4 + THEIRSTACK_SLOW_JOB_SEARCH_PROVIDER_TIMEOUT_MS + 15e3;
|
|
4148
|
-
var THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS = 21e4;
|
|
4149
|
-
var LONG_JOB_SEARCH_WINDOW_MS = 365 * 24 * 60 * 60 * 1e3;
|
|
4150
|
-
var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
4151
|
-
function parseDateOnly(value) {
|
|
4152
|
-
if (typeof value !== "string" || !DATE_ONLY_PATTERN.test(value)) {
|
|
4153
|
-
return null;
|
|
4154
|
-
}
|
|
4155
|
-
const timestamp = Date.parse(`${value}T00:00:00.000Z`);
|
|
4156
|
-
if (!Number.isFinite(timestamp)) {
|
|
4157
|
-
return null;
|
|
4158
|
-
}
|
|
4159
|
-
return new Date(timestamp).toISOString().slice(0, 10) === value ? timestamp : null;
|
|
4160
|
-
}
|
|
4161
|
-
function usesLongExplicitDateWindow(payload) {
|
|
4162
|
-
const postedAtGte = parseDateOnly(payload.posted_at_gte);
|
|
4163
|
-
const postedAtLte = parseDateOnly(payload.posted_at_lte);
|
|
4164
|
-
if (postedAtGte !== null && postedAtLte !== null) {
|
|
4165
|
-
return postedAtLte - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
4166
|
-
}
|
|
4167
|
-
if (postedAtGte !== null) {
|
|
4168
|
-
return Date.now() - postedAtGte >= LONG_JOB_SEARCH_WINDOW_MS;
|
|
4169
|
-
}
|
|
4170
|
-
return postedAtLte !== null && payload.posted_at_gte == null;
|
|
4171
|
-
}
|
|
4172
|
-
function parseMaxAgeDays(value) {
|
|
4173
|
-
if (typeof value === "number") {
|
|
4174
|
-
return Number.isFinite(value) ? value : null;
|
|
4175
|
-
}
|
|
4176
|
-
if (typeof value !== "string" || !/^-?\d+$/.test(value.trim())) {
|
|
4177
|
-
return null;
|
|
4178
|
-
}
|
|
4179
|
-
const parsed = Number(value.trim());
|
|
4180
|
-
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
4181
|
-
}
|
|
4182
|
-
function usesExtendedTheirstackJobSearchBudget(endpointId, payload) {
|
|
4183
|
-
if (endpointId !== "theirstack_job_search") {
|
|
4184
|
-
return false;
|
|
4185
|
-
}
|
|
4186
|
-
if (payload.include_total_results === true) {
|
|
4187
|
-
return true;
|
|
4188
|
-
}
|
|
4189
|
-
const maxAgeDays = parseMaxAgeDays(payload.posted_at_max_age_days);
|
|
4190
|
-
return maxAgeDays !== null && maxAgeDays >= 365 ? true : usesLongExplicitDateWindow(payload);
|
|
4191
|
-
}
|
|
4192
|
-
function resolveTheirstackClientTimeoutMs(endpointId, payload) {
|
|
4193
|
-
if (endpointId === "theirstack_company_search") {
|
|
4194
|
-
return THEIRSTACK_COMPANY_SEARCH_CLIENT_TIMEOUT_MS;
|
|
4195
|
-
}
|
|
4196
|
-
return usesExtendedTheirstackJobSearchBudget(endpointId, payload) ? THEIRSTACK_SLOW_JOB_SEARCH_CLIENT_TIMEOUT_MS : null;
|
|
4197
|
-
}
|
|
4198
|
-
|
|
4199
|
-
// ../integration-contracts/waterfall/execution-policy.ts
|
|
4200
|
-
var WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS = 18e4;
|
|
4201
|
-
var WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
4202
|
-
"prospector",
|
|
4203
|
-
"deepline_native_prospector"
|
|
4204
|
-
]);
|
|
4205
|
-
function resolveWaterfallClientTimeoutMs(toolId) {
|
|
4206
|
-
return WATERFALL_PROSPECTOR_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase()) ? WATERFALL_PROSPECTOR_CLIENT_TIMEOUT_MS : null;
|
|
4207
|
-
}
|
|
4208
|
-
|
|
4209
|
-
// ../integration-contracts/bettercontact/execution-policy.ts
|
|
4210
|
-
var BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS = 12e4;
|
|
4211
|
-
var BETTERCONTACT_LAUNCHER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
4212
|
-
"bettercontact_enrich",
|
|
4213
|
-
"bettercontact_bulk_enrich"
|
|
4214
|
-
]);
|
|
4215
|
-
function usesExtendedBetterContactLauncherBudget(toolId) {
|
|
4216
|
-
return BETTERCONTACT_LAUNCHER_TOOL_IDS.has(toolId.trim().toLowerCase());
|
|
4217
|
-
}
|
|
4218
|
-
|
|
4219
4548
|
// ../plays/artifact-types.ts
|
|
4220
4549
|
var PLAY_ARTIFACT_KINDS = {
|
|
4221
4550
|
cjsNode20: "cjs_node20"
|
|
@@ -4289,27 +4618,6 @@ function normalizePlayRuntimeEnvironment(value) {
|
|
|
4289
4618
|
return typeof value === "string" && PLAY_RUNTIME_ENVIRONMENTS.includes(value) ? value : null;
|
|
4290
4619
|
}
|
|
4291
4620
|
|
|
4292
|
-
// ../plays/tool-response-contract.ts
|
|
4293
|
-
var RAW_V2_TOOL_RESPONSE_CONTRACT = "raw-v2";
|
|
4294
|
-
function legacyRawFromToolResponseRawV2(rawV2, view, responseMeta) {
|
|
4295
|
-
const legacyRaw = view === "data" && rawV2 && typeof rawV2 === "object" && !Array.isArray(rawV2) ? rawV2.data : rawV2;
|
|
4296
|
-
const deeplineBilling = responseMeta?.deepline_billing;
|
|
4297
|
-
if (view === "rawV2" && deeplineBilling !== void 0 && legacyRaw && typeof legacyRaw === "object" && !Array.isArray(legacyRaw)) {
|
|
4298
|
-
return {
|
|
4299
|
-
...legacyRaw,
|
|
4300
|
-
deepline_billing: deeplineBilling
|
|
4301
|
-
};
|
|
4302
|
-
}
|
|
4303
|
-
return legacyRaw;
|
|
4304
|
-
}
|
|
4305
|
-
function providerMetaFromToolResponseRawV2(rawV2, view) {
|
|
4306
|
-
if (view !== "data" || !rawV2 || typeof rawV2 !== "object" || Array.isArray(rawV2)) {
|
|
4307
|
-
return void 0;
|
|
4308
|
-
}
|
|
4309
|
-
const meta = rawV2.meta;
|
|
4310
|
-
return meta && typeof meta === "object" && !Array.isArray(meta) ? meta : void 0;
|
|
4311
|
-
}
|
|
4312
|
-
|
|
4313
4621
|
// src/client.ts
|
|
4314
4622
|
var MAX_NOTIFICATION_GROUP_CREATE_TARGETS = 50;
|
|
4315
4623
|
function parseNotificationGroupTarget(value) {
|
|
@@ -4332,85 +4640,30 @@ function parseNotificationGroupTarget(value) {
|
|
|
4332
4640
|
}
|
|
4333
4641
|
const member = /^member:([UW][A-Z0-9]{8,})$/i.exec(slack);
|
|
4334
4642
|
if (member?.[1]) {
|
|
4335
|
-
return { kind: "slack", memberId: member[1].toUpperCase() };
|
|
4336
|
-
}
|
|
4337
|
-
if (slack.toLowerCase().startsWith("member:")) {
|
|
4338
|
-
throw new Error(
|
|
4339
|
-
"Slack member IDs must look like slack:member:U0123456789."
|
|
4340
|
-
);
|
|
4341
|
-
}
|
|
4342
|
-
if (!slack.replace(/^#/, "").trim()) {
|
|
4343
|
-
throw new Error("Use --to slack:#channel.");
|
|
4344
|
-
}
|
|
4345
|
-
return { kind: "slack", channel: slack };
|
|
4346
|
-
}
|
|
4347
|
-
function notificationObjectKey(kind) {
|
|
4348
|
-
return `${kind}.${globalThis.crypto.randomUUID()}`;
|
|
4349
|
-
}
|
|
4350
|
-
var TERMINAL_PLAY_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
4351
|
-
var INCLUDE_TOOL_METADATA_HEADER = "x-deepline-include-tool-metadata";
|
|
4352
|
-
var EXECUTE_RESPONSE_CONTRACT_HEADER = "x-deepline-execute-response-contract";
|
|
4353
|
-
var EXECUTE_RESPONSE_INTENT_HEADER = "x-deepline-execute-response-intent";
|
|
4354
|
-
var MONITOR_NON_RETRYABLE_MUTATION_OPTIONS = {
|
|
4355
|
-
maxRetries: 0,
|
|
4356
|
-
exactUrlOnly: true
|
|
4357
|
-
};
|
|
4358
|
-
var RAW_V2_EXECUTE_RESPONSE_CONTRACT = RAW_V2_TOOL_RESPONSE_CONTRACT;
|
|
4359
|
-
var DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
4360
|
-
function validateExecutionIdempotencyKey(key) {
|
|
4361
|
-
if (typeof key !== "string" || key.length < 1 || key.length > 200 || !/^[A-Za-z0-9._:-]+$/.test(key)) {
|
|
4362
|
-
throw new DeeplineError(
|
|
4363
|
-
"Execution idempotency keys must be 1\u2013200 ASCII letters, digits, dots, underscores, colons, or hyphens.",
|
|
4364
|
-
void 0,
|
|
4365
|
-
"IDEMPOTENCY_KEY_INVALID"
|
|
4366
|
-
);
|
|
4367
|
-
}
|
|
4368
|
-
}
|
|
4369
|
-
function isExecutionInProgressResponse(value) {
|
|
4370
|
-
return typeof value === "object" && value !== null && typeof value.executionRecovery === "object" && value.executionRecovery.state === "running";
|
|
4371
|
-
}
|
|
4372
|
-
function getExecutionRecoveryState(value) {
|
|
4373
|
-
if (typeof value !== "object" || value === null || typeof value.executionRecovery !== "object") {
|
|
4374
|
-
return null;
|
|
4375
|
-
}
|
|
4376
|
-
const state = value.executionRecovery.state;
|
|
4377
|
-
return state === "running" || state === "completed" || state === "outcome_unknown" ? state : null;
|
|
4378
|
-
}
|
|
4379
|
-
function isRecoverableExecutionAttemptError(error) {
|
|
4380
|
-
if (error instanceof ToolExecutionError) {
|
|
4381
|
-
return error.code === "EXECUTION_IN_PROGRESS" || error.origin === "deepline" && error.category === "network" && error.networkScope === "client_to_deepline";
|
|
4382
|
-
}
|
|
4383
|
-
return error instanceof DeeplineError && (error.code === "EXECUTION_IN_PROGRESS" || error.code?.startsWith("NETWORK_") === true && error.statusCode === void 0);
|
|
4384
|
-
}
|
|
4385
|
-
function isRecoverableExecutionLookupError(error) {
|
|
4386
|
-
if (isRecoverableExecutionAttemptError(error)) return true;
|
|
4387
|
-
return error instanceof DeeplineError && (error.statusCode === 429 || error.statusCode !== void 0 && error.statusCode >= 500);
|
|
4388
|
-
}
|
|
4389
|
-
function timeoutWithinRecoveryBudget(requestTimeoutMs, defaultRequestTimeoutMs, remainingMs) {
|
|
4390
|
-
return Math.min(requestTimeoutMs ?? defaultRequestTimeoutMs, remainingMs);
|
|
4391
|
-
}
|
|
4392
|
-
function executionRecoveryError(input) {
|
|
4393
|
-
return new ToolExecutionError(input.message, {
|
|
4394
|
-
toolId: input.toolId,
|
|
4395
|
-
provider: null,
|
|
4396
|
-
operation: input.toolId,
|
|
4397
|
-
code: input.code,
|
|
4398
|
-
origin: "deepline",
|
|
4399
|
-
category: input.code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown" : "conflict",
|
|
4400
|
-
retryable: input.code !== "EXECUTION_OUTCOME_UNKNOWN",
|
|
4401
|
-
statusCode: null,
|
|
4402
|
-
requestId: null,
|
|
4403
|
-
retryAfterMs: null,
|
|
4404
|
-
networkKind: null,
|
|
4405
|
-
networkScope: null,
|
|
4406
|
-
publicDetails: { idempotencyKey: input.idempotencyKey }
|
|
4407
|
-
});
|
|
4643
|
+
return { kind: "slack", memberId: member[1].toUpperCase() };
|
|
4644
|
+
}
|
|
4645
|
+
if (slack.toLowerCase().startsWith("member:")) {
|
|
4646
|
+
throw new Error(
|
|
4647
|
+
"Slack member IDs must look like slack:member:U0123456789."
|
|
4648
|
+
);
|
|
4649
|
+
}
|
|
4650
|
+
if (!slack.replace(/^#/, "").trim()) {
|
|
4651
|
+
throw new Error("Use --to slack:#channel.");
|
|
4652
|
+
}
|
|
4653
|
+
return { kind: "slack", channel: slack };
|
|
4654
|
+
}
|
|
4655
|
+
function notificationObjectKey(kind) {
|
|
4656
|
+
return `${kind}.${globalThis.crypto.randomUUID()}`;
|
|
4408
4657
|
}
|
|
4658
|
+
var TERMINAL_PLAY_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
4659
|
+
var MONITOR_NON_RETRYABLE_MUTATION_OPTIONS = {
|
|
4660
|
+
maxRetries: 0,
|
|
4661
|
+
exactUrlOnly: true
|
|
4662
|
+
};
|
|
4409
4663
|
var COMPILE_MANIFEST_RETRY_DELAYS_MS = [250, 1e3];
|
|
4410
4664
|
var REGISTER_PLAY_ARTIFACTS_COMPILE_CONCURRENCY = 3;
|
|
4411
4665
|
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_COUNT = 3;
|
|
4412
4666
|
var REGISTER_PLAY_ARTIFACTS_MAX_BATCH_BYTES = 25e5;
|
|
4413
|
-
var DEEPLINEAGENT_EXECUTE_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
4414
4667
|
function normalizePlayRunIntegrationMode(value) {
|
|
4415
4668
|
if (value === "live" || value === "eval_stub" || value === "fixture") {
|
|
4416
4669
|
return value;
|
|
@@ -4601,28 +4854,6 @@ function chunkRegisterPlayArtifacts(artifacts) {
|
|
|
4601
4854
|
}
|
|
4602
4855
|
return chunks;
|
|
4603
4856
|
}
|
|
4604
|
-
var APIFY_SYNC_DEFAULT_TIMEOUT_MS = 3e5;
|
|
4605
|
-
var APIFY_SYNC_RESPONSE_GRACE_MS = 9e4;
|
|
4606
|
-
function resolveToolExecuteTimeoutMs(toolId, input) {
|
|
4607
|
-
const normalized = toolId.trim().toLowerCase();
|
|
4608
|
-
if (normalized === "apify_run_actor_sync") {
|
|
4609
|
-
const requestedTimeoutMs = input.timeoutMs ?? APIFY_SYNC_DEFAULT_TIMEOUT_MS;
|
|
4610
|
-
if (typeof requestedTimeoutMs === "number" && Number.isFinite(requestedTimeoutMs) && requestedTimeoutMs > 0) {
|
|
4611
|
-
return Math.floor(requestedTimeoutMs) + APIFY_SYNC_RESPONSE_GRACE_MS;
|
|
4612
|
-
}
|
|
4613
|
-
}
|
|
4614
|
-
const theirstackTimeoutMs = resolveTheirstackClientTimeoutMs(
|
|
4615
|
-
normalized,
|
|
4616
|
-
input
|
|
4617
|
-
);
|
|
4618
|
-
if (theirstackTimeoutMs !== null) return theirstackTimeoutMs;
|
|
4619
|
-
const waterfallTimeoutMs = resolveWaterfallClientTimeoutMs(normalized);
|
|
4620
|
-
if (waterfallTimeoutMs !== null) return waterfallTimeoutMs;
|
|
4621
|
-
if (usesExtendedBetterContactLauncherBudget(normalized)) {
|
|
4622
|
-
return BETTERCONTACT_LAUNCHER_CLIENT_TIMEOUT_MS;
|
|
4623
|
-
}
|
|
4624
|
-
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;
|
|
4625
|
-
}
|
|
4626
4857
|
var RUNS_FAILED_LOG_LIMIT = 20;
|
|
4627
4858
|
var RUN_LOGS_PAGE_LIMIT = 1e3;
|
|
4628
4859
|
var MONITOR_JOB_STATES = [
|
|
@@ -4657,53 +4888,9 @@ function requireTargetBillingIdempotencyKey(value) {
|
|
|
4657
4888
|
}
|
|
4658
4889
|
return normalized;
|
|
4659
4890
|
}
|
|
4660
|
-
function
|
|
4891
|
+
function isRecord8(value) {
|
|
4661
4892
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
4662
4893
|
}
|
|
4663
|
-
function materializeToolExecutionResponse(response) {
|
|
4664
|
-
const toolResponse = response.toolResponse;
|
|
4665
|
-
if (!toolResponse && isRecord7(response.result)) {
|
|
4666
|
-
const legacyResult = response.result;
|
|
4667
|
-
if (Object.prototype.hasOwnProperty.call(legacyResult, "data")) {
|
|
4668
|
-
const legacyMeta = isRecord7(legacyResult.meta) ? legacyResult.meta : void 0;
|
|
4669
|
-
return {
|
|
4670
|
-
...response,
|
|
4671
|
-
toolResponse: {
|
|
4672
|
-
raw: legacyResult.data,
|
|
4673
|
-
...legacyMeta ? { meta: legacyMeta } : {}
|
|
4674
|
-
}
|
|
4675
|
-
};
|
|
4676
|
-
}
|
|
4677
|
-
}
|
|
4678
|
-
if (!toolResponse || Object.prototype.hasOwnProperty.call(toolResponse, "raw")) {
|
|
4679
|
-
return response;
|
|
4680
|
-
}
|
|
4681
|
-
const rawV2 = toolResponse.rawV2;
|
|
4682
|
-
const view = toolResponse.view;
|
|
4683
|
-
const providerMeta = providerMetaFromToolResponseRawV2(
|
|
4684
|
-
rawV2,
|
|
4685
|
-
view ?? "rawV2"
|
|
4686
|
-
);
|
|
4687
|
-
const responseMeta = isRecord7(toolResponse.responseMeta) ? toolResponse.responseMeta : void 0;
|
|
4688
|
-
return {
|
|
4689
|
-
...response,
|
|
4690
|
-
toolResponse: {
|
|
4691
|
-
...toolResponse,
|
|
4692
|
-
raw: legacyRawFromToolResponseRawV2(
|
|
4693
|
-
rawV2,
|
|
4694
|
-
view ?? "rawV2",
|
|
4695
|
-
responseMeta
|
|
4696
|
-
),
|
|
4697
|
-
...toolResponse.meta || providerMeta || responseMeta ? {
|
|
4698
|
-
meta: {
|
|
4699
|
-
...toolResponse.meta ?? {},
|
|
4700
|
-
...providerMeta ?? {},
|
|
4701
|
-
...responseMeta ?? {}
|
|
4702
|
-
}
|
|
4703
|
-
} : {}
|
|
4704
|
-
}
|
|
4705
|
-
};
|
|
4706
|
-
}
|
|
4707
4894
|
function isPrebuiltPlayDescription(play) {
|
|
4708
4895
|
return play.origin === "prebuilt" || play.ownerType === "deepline";
|
|
4709
4896
|
}
|
|
@@ -4733,10 +4920,10 @@ function normalizePlayStatus(raw) {
|
|
|
4733
4920
|
return {
|
|
4734
4921
|
...raw,
|
|
4735
4922
|
runId,
|
|
4736
|
-
...
|
|
4923
|
+
...isRecord8(legacyOverview) ? {
|
|
4737
4924
|
overview: legacyOverview
|
|
4738
4925
|
} : {},
|
|
4739
|
-
...
|
|
4926
|
+
...isRecord8(runStatus) ? { runStatus } : {},
|
|
4740
4927
|
...runPackage ? {
|
|
4741
4928
|
package: runPackage,
|
|
4742
4929
|
outputs: runPackage.outputs
|
|
@@ -4875,7 +5062,7 @@ function updatePlayLiveStatusState(state, event) {
|
|
|
4875
5062
|
}
|
|
4876
5063
|
const runId = typeof payload.runId === "string" && payload.runId ? payload.runId : isPlayRunPackage(payload) ? payload.run.id : state.runId;
|
|
4877
5064
|
const status = normalizeLiveStatus(payload.status) ?? (isPlayRunPackage(payload) ? normalizeLiveStatus(payload.run.status) : null) ?? state.status;
|
|
4878
|
-
const progressPayload =
|
|
5065
|
+
const progressPayload = isRecord8(payload.progress) ? payload.progress : {};
|
|
4879
5066
|
if (event.type === "play.run.final_status" && state.logs.length === 0 && state.lastLogSeq === 0) {
|
|
4880
5067
|
const payloadLogs = readStringArray(payload.logs);
|
|
4881
5068
|
const progressLogs = readStringArray(progressPayload.logs);
|
|
@@ -4924,6 +5111,7 @@ function playRunResultFromStatus(status, startedAt, fallbackRunId) {
|
|
|
4924
5111
|
}
|
|
4925
5112
|
var DeeplineClient = class _DeeplineClient {
|
|
4926
5113
|
http;
|
|
5114
|
+
toolCalls;
|
|
4927
5115
|
config;
|
|
4928
5116
|
/** Canonical run lifecycle namespace backed by `/api/v2/runs`. */
|
|
4929
5117
|
runs;
|
|
@@ -4947,6 +5135,7 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
4947
5135
|
constructor(options) {
|
|
4948
5136
|
this.config = resolveConfig(options);
|
|
4949
5137
|
this.http = new HttpClient(this.config);
|
|
5138
|
+
this.toolCalls = new ToolCalls(this.http, this.config.timeout);
|
|
4950
5139
|
this.runs = {
|
|
4951
5140
|
get: (runId, options2) => this.getRunStatus(runId, options2),
|
|
4952
5141
|
status: (runId) => this.getRunLifecycleStatus(runId),
|
|
@@ -5074,9 +5263,9 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5074
5263
|
return fields.length > 0 ? { fields } : schema;
|
|
5075
5264
|
}
|
|
5076
5265
|
schemaMetadata(schema, key) {
|
|
5077
|
-
if (!
|
|
5266
|
+
if (!isRecord8(schema)) return null;
|
|
5078
5267
|
const value = schema[key];
|
|
5079
|
-
return
|
|
5268
|
+
return isRecord8(value) ? value : null;
|
|
5080
5269
|
}
|
|
5081
5270
|
playRunCommand(play, options) {
|
|
5082
5271
|
const target = play.reference || play.name;
|
|
@@ -5131,7 +5320,7 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5131
5320
|
aliases,
|
|
5132
5321
|
inputSchema: options?.compact ? this.compactSchema(play.inputSchema) : play.inputSchema ?? null,
|
|
5133
5322
|
outputSchema: options?.compact ? this.compactSchema(play.outputSchema) : play.outputSchema ?? null,
|
|
5134
|
-
staticPipeline:
|
|
5323
|
+
staticPipeline: isRecord8(play.staticPipeline) ? play.staticPipeline : isRecord8(play.currentRevision?.staticPipeline) ? play.currentRevision.staticPipeline : isRecord8(play.liveRevision?.staticPipeline) ? play.liveRevision.staticPipeline : null,
|
|
5135
5324
|
...csvInput ? { csvInput } : {},
|
|
5136
5325
|
...rowOutputSchema ? { rowOutputSchema } : {},
|
|
5137
5326
|
runCommand,
|
|
@@ -5351,183 +5540,11 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
5351
5540
|
* Deepline execution envelope.
|
|
5352
5541
|
*/
|
|
5353
5542
|
async executeTool(toolId, input, options) {
|
|
5354
|
-
|
|
5355
|
-
const metadataSnapshot = options?.metadata ? JSON.parse(JSON.stringify(options.metadata)) : void 0;
|
|
5356
|
-
const idempotencyKey = options?.idempotencyKey ?? (options?.recover ? crypto.randomUUID() : void 0);
|
|
5357
|
-
if (idempotencyKey !== void 0) {
|
|
5358
|
-
validateExecutionIdempotencyKey(idempotencyKey);
|
|
5359
|
-
if (options?.recoveryTimeoutMs !== void 0 && (!Number.isFinite(options.recoveryTimeoutMs) || options.recoveryTimeoutMs < 0)) {
|
|
5360
|
-
throw new DeeplineError(
|
|
5361
|
-
"recoveryTimeoutMs must be a finite, non-negative number.",
|
|
5362
|
-
void 0,
|
|
5363
|
-
"IDEMPOTENCY_KEY_INVALID"
|
|
5364
|
-
);
|
|
5365
|
-
}
|
|
5366
|
-
await options?.onExecution?.({ idempotencyKey });
|
|
5367
|
-
const timeoutMs2 = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
|
|
5368
|
-
await this.lookupExecutionByKey(idempotencyKey, timeoutMs2);
|
|
5369
|
-
}
|
|
5370
|
-
const timeoutMs = options?.timeout ?? resolveToolExecuteTimeoutMs(toolId, inputSnapshot);
|
|
5371
|
-
const isApifySync = toolId.trim().toLowerCase() === "apify_run_actor_sync";
|
|
5372
|
-
const headers = {
|
|
5373
|
-
[EXECUTE_RESPONSE_CONTRACT_HEADER]: RAW_V2_EXECUTE_RESPONSE_CONTRACT,
|
|
5374
|
-
...isApifySync ? { "X-Deepline-Apify-Sync-Response-Budget": "extended-v1" } : {},
|
|
5375
|
-
[TOOL_EXECUTION_ERROR_SCHEMA_HEADER]: String(
|
|
5376
|
-
TOOL_EXECUTION_ERROR_SCHEMA_VERSION
|
|
5377
|
-
),
|
|
5378
|
-
...options?.includeToolMetadata ? { [INCLUDE_TOOL_METADATA_HEADER]: "true" } : {},
|
|
5379
|
-
[EXECUTE_RESPONSE_INTENT_HEADER]: options?.responseIntent ?? "raw",
|
|
5380
|
-
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {},
|
|
5381
|
-
...options?.searchRef ? { "x-deepline-search-ref": options.searchRef } : {}
|
|
5382
|
-
};
|
|
5383
|
-
const request = (requestTimeoutMs) => this.http.post(
|
|
5384
|
-
`/api/v2/integrations/${encodeURIComponent(toolId)}/execute`,
|
|
5385
|
-
{
|
|
5386
|
-
payload: inputSnapshot,
|
|
5387
|
-
...metadataSnapshot ? { metadata: metadataSnapshot } : {}
|
|
5388
|
-
},
|
|
5389
|
-
headers,
|
|
5390
|
-
{
|
|
5391
|
-
timeout: requestTimeoutMs,
|
|
5392
|
-
maxRetries: idempotencyKey ? 0 : options?.maxRetries ?? 0,
|
|
5393
|
-
retryApiErrors: options?.retryApiErrors === true,
|
|
5394
|
-
exactUrlOnly: true,
|
|
5395
|
-
toolId,
|
|
5396
|
-
idempotencyKey
|
|
5397
|
-
}
|
|
5398
|
-
);
|
|
5399
|
-
let response;
|
|
5400
|
-
let recoveryDeadline = null;
|
|
5401
|
-
const recoveryTimeoutMs = options?.recoveryTimeoutMs ?? DEFAULT_EXECUTION_RECOVERY_TIMEOUT_MS;
|
|
5402
|
-
let retryDelayMs = 1e3;
|
|
5403
|
-
const recoveryTimeoutError = () => executionRecoveryError({
|
|
5404
|
-
toolId,
|
|
5405
|
-
idempotencyKey,
|
|
5406
|
-
code: "EXECUTION_RECOVERY_TIMEOUT",
|
|
5407
|
-
message: `Execution recovery for ${idempotencyKey} did not finish before the recovery timeout. Inspect client.executions.getByKey() and resume with the same idempotency key.`
|
|
5408
|
-
});
|
|
5409
|
-
const waitForRecoveryRetry = async (deadline) => {
|
|
5410
|
-
const remainingMs = deadline - Date.now();
|
|
5411
|
-
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
5412
|
-
await new Promise(
|
|
5413
|
-
(resolve2) => setTimeout(resolve2, Math.min(retryDelayMs, remainingMs))
|
|
5414
|
-
);
|
|
5415
|
-
retryDelayMs = Math.min(retryDelayMs * 2, 5e3);
|
|
5416
|
-
};
|
|
5417
|
-
const lookupDuringRecovery = async () => {
|
|
5418
|
-
while (true) {
|
|
5419
|
-
const remainingMs = recoveryDeadline - Date.now();
|
|
5420
|
-
if (remainingMs <= 0) throw recoveryTimeoutError();
|
|
5421
|
-
try {
|
|
5422
|
-
return await this.lookupExecutionByKey(
|
|
5423
|
-
idempotencyKey,
|
|
5424
|
-
timeoutWithinRecoveryBudget(
|
|
5425
|
-
timeoutMs,
|
|
5426
|
-
this.config.timeout,
|
|
5427
|
-
remainingMs
|
|
5428
|
-
)
|
|
5429
|
-
);
|
|
5430
|
-
} catch (error) {
|
|
5431
|
-
if (!isRecoverableExecutionLookupError(error)) throw error;
|
|
5432
|
-
await waitForRecoveryRetry(recoveryDeadline);
|
|
5433
|
-
}
|
|
5434
|
-
}
|
|
5435
|
-
};
|
|
5436
|
-
while (true) {
|
|
5437
|
-
const remainingMs = recoveryDeadline === null ? null : recoveryDeadline - Date.now();
|
|
5438
|
-
if (remainingMs !== null && remainingMs <= 0) {
|
|
5439
|
-
throw recoveryTimeoutError();
|
|
5440
|
-
}
|
|
5441
|
-
try {
|
|
5442
|
-
response = await request(
|
|
5443
|
-
remainingMs === null ? timeoutMs : timeoutWithinRecoveryBudget(
|
|
5444
|
-
timeoutMs,
|
|
5445
|
-
this.config.timeout,
|
|
5446
|
-
remainingMs
|
|
5447
|
-
)
|
|
5448
|
-
);
|
|
5449
|
-
if (getExecutionRecoveryState(response) === "outcome_unknown") {
|
|
5450
|
-
if (!idempotencyKey) break;
|
|
5451
|
-
throw executionRecoveryError({
|
|
5452
|
-
toolId,
|
|
5453
|
-
idempotencyKey,
|
|
5454
|
-
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
5455
|
-
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
5456
|
-
});
|
|
5457
|
-
}
|
|
5458
|
-
if (!idempotencyKey || !isExecutionInProgressResponse(response)) {
|
|
5459
|
-
break;
|
|
5460
|
-
}
|
|
5461
|
-
if (recoveryDeadline === null) {
|
|
5462
|
-
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
5463
|
-
}
|
|
5464
|
-
} catch (error) {
|
|
5465
|
-
if (idempotencyKey && error instanceof DeeplineError && error.code === "EXECUTION_OUTCOME_UNKNOWN") {
|
|
5466
|
-
throw executionRecoveryError({
|
|
5467
|
-
toolId,
|
|
5468
|
-
idempotencyKey,
|
|
5469
|
-
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
5470
|
-
message: error.message
|
|
5471
|
-
});
|
|
5472
|
-
}
|
|
5473
|
-
if (!idempotencyKey || !isRecoverableExecutionAttemptError(error)) {
|
|
5474
|
-
throw error;
|
|
5475
|
-
}
|
|
5476
|
-
if (recoveryDeadline === null) {
|
|
5477
|
-
recoveryDeadline = Date.now() + recoveryTimeoutMs;
|
|
5478
|
-
}
|
|
5479
|
-
}
|
|
5480
|
-
await waitForRecoveryRetry(recoveryDeadline);
|
|
5481
|
-
const recovered = await lookupDuringRecovery();
|
|
5482
|
-
if (getExecutionRecoveryState(recovered) === "outcome_unknown") {
|
|
5483
|
-
throw executionRecoveryError({
|
|
5484
|
-
toolId,
|
|
5485
|
-
idempotencyKey,
|
|
5486
|
-
code: "EXECUTION_OUTCOME_UNKNOWN",
|
|
5487
|
-
message: `The outcome of execution ${idempotencyKey} is unknown. Do not retry with a new key; inspect client.executions.getByKey().`
|
|
5488
|
-
});
|
|
5489
|
-
}
|
|
5490
|
-
}
|
|
5491
|
-
const materialized = materializeToolExecutionResponse(response);
|
|
5492
|
-
return idempotencyKey ? { ...materialized, idempotencyKey } : materialized;
|
|
5543
|
+
return this.toolCalls.call(toolId, input, options);
|
|
5493
5544
|
}
|
|
5494
5545
|
/** Read the durable state of a keyed tool execution. */
|
|
5495
5546
|
async getExecutionByKey(idempotencyKey) {
|
|
5496
|
-
|
|
5497
|
-
const result = await this.lookupExecutionByKey(idempotencyKey);
|
|
5498
|
-
if (!result) {
|
|
5499
|
-
throw new DeeplineError(
|
|
5500
|
-
`No execution exists for idempotency key ${idempotencyKey}.`,
|
|
5501
|
-
404,
|
|
5502
|
-
"EXECUTION_NOT_FOUND"
|
|
5503
|
-
);
|
|
5504
|
-
}
|
|
5505
|
-
return result;
|
|
5506
|
-
}
|
|
5507
|
-
async lookupExecutionByKey(idempotencyKey, timeoutMs) {
|
|
5508
|
-
validateExecutionIdempotencyKey(idempotencyKey);
|
|
5509
|
-
let supported = false;
|
|
5510
|
-
const result = await this.http.get(
|
|
5511
|
-
`/api/v2/executions/by-key/${encodeURIComponent(idempotencyKey)}`,
|
|
5512
|
-
{
|
|
5513
|
-
exactUrlOnly: true,
|
|
5514
|
-
maxRetries: 0,
|
|
5515
|
-
timeout: timeoutMs,
|
|
5516
|
-
idempotencyKey,
|
|
5517
|
-
allowNotFound: true,
|
|
5518
|
-
onResponse: (response) => {
|
|
5519
|
-
supported = response.headers.get("X-Deepline-Idempotency-Supported") === "true";
|
|
5520
|
-
}
|
|
5521
|
-
}
|
|
5522
|
-
);
|
|
5523
|
-
if (!supported) {
|
|
5524
|
-
throw new DeeplineError(
|
|
5525
|
-
"This Deepline server does not support recoverable tool executions; no tool was dispatched.",
|
|
5526
|
-
422,
|
|
5527
|
-
"IDEMPOTENCY_NOT_SUPPORTED"
|
|
5528
|
-
);
|
|
5529
|
-
}
|
|
5530
|
-
return result;
|
|
5547
|
+
return this.toolCalls.getByKey(idempotencyKey);
|
|
5531
5548
|
}
|
|
5532
5549
|
/** Public recovery namespace. */
|
|
5533
5550
|
get executions() {
|
|
@@ -6335,10 +6352,10 @@ var DeeplineClient = class _DeeplineClient {
|
|
|
6335
6352
|
const responseRunStatus = isPlayRunPackage(response) ? response.runStatus : isPlayRunPackage(response.package) ? response.package.runStatus : response.runStatus;
|
|
6336
6353
|
const responseOverview = isPlayRunPackage(response) ? response.overview : isPlayRunPackage(response.package) ? response.package.overview : response.overview;
|
|
6337
6354
|
const status = normalizePlayStatus(response);
|
|
6338
|
-
if (
|
|
6355
|
+
if (isRecord8(responseRunStatus)) {
|
|
6339
6356
|
status.runStatus = responseRunStatus;
|
|
6340
6357
|
}
|
|
6341
|
-
if (
|
|
6358
|
+
if (isRecord8(responseOverview)) {
|
|
6342
6359
|
status.overview = responseOverview;
|
|
6343
6360
|
}
|
|
6344
6361
|
if (options?.failedLogs !== true || status.status !== "failed") {
|
|
@@ -9177,7 +9194,7 @@ var TARGET_FALLBACK_KEYS = {
|
|
|
9177
9194
|
status: { match: [/^email_status$/i, /^status$/i] },
|
|
9178
9195
|
email_status: { match: [/^email_status$/i, /^status$/i] }
|
|
9179
9196
|
};
|
|
9180
|
-
function
|
|
9197
|
+
function isRecord9(value) {
|
|
9181
9198
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
9182
9199
|
}
|
|
9183
9200
|
function toV2RawToolOutputPath(path) {
|
|
@@ -9237,7 +9254,7 @@ function valuesAtSegments(current, segments, path = []) {
|
|
|
9237
9254
|
if (!Array.isArray(current)) return [];
|
|
9238
9255
|
return valuesAtSegments(current[segment], rest, [...path, segment]);
|
|
9239
9256
|
}
|
|
9240
|
-
if (!
|
|
9257
|
+
if (!isRecord9(current)) return [];
|
|
9241
9258
|
const directMatches = valuesAtSegments(current[segment], rest, [
|
|
9242
9259
|
...path,
|
|
9243
9260
|
segment
|
|
@@ -9267,7 +9284,7 @@ function getValuesAtPath(root, path) {
|
|
|
9267
9284
|
return valuesAtSegments(root, parsePath(path)).map((entry) => entry.value);
|
|
9268
9285
|
}
|
|
9269
9286
|
function toResultEnvelope(value) {
|
|
9270
|
-
if (
|
|
9287
|
+
if (isRecord9(value) && "data" in value) {
|
|
9271
9288
|
const envelope = { data: value.data };
|
|
9272
9289
|
if ("meta" in value) envelope.meta = value.meta;
|
|
9273
9290
|
return envelope;
|
|
@@ -9320,7 +9337,7 @@ function getAtPath(root, path) {
|
|
|
9320
9337
|
current = current[segment];
|
|
9321
9338
|
continue;
|
|
9322
9339
|
}
|
|
9323
|
-
if (!
|
|
9340
|
+
if (!isRecord9(current)) return void 0;
|
|
9324
9341
|
current = current[segment];
|
|
9325
9342
|
}
|
|
9326
9343
|
return current;
|
|
@@ -9337,7 +9354,7 @@ function normalizeString(value) {
|
|
|
9337
9354
|
}
|
|
9338
9355
|
function normalizeRows(value) {
|
|
9339
9356
|
if (!Array.isArray(value)) return null;
|
|
9340
|
-
return value.map((entry) =>
|
|
9357
|
+
return value.map((entry) => isRecord9(entry) ? entry : { value: entry });
|
|
9341
9358
|
}
|
|
9342
9359
|
function findFirstTargetByPath(result, paths) {
|
|
9343
9360
|
for (const path of paths ?? []) {
|
|
@@ -9407,7 +9424,7 @@ function findFirstTargetByKey(result, target, depth = 0, path = []) {
|
|
|
9407
9424
|
}
|
|
9408
9425
|
return null;
|
|
9409
9426
|
}
|
|
9410
|
-
if (!
|
|
9427
|
+
if (!isRecord9(result)) return null;
|
|
9411
9428
|
const rule = TARGET_FALLBACK_KEYS[target] ?? {
|
|
9412
9429
|
match: [new RegExp(`^${target}$`, "i")]
|
|
9413
9430
|
};
|
|
@@ -9468,7 +9485,7 @@ function normalizeJobChangeStatus(value) {
|
|
|
9468
9485
|
function firstExperienceDate(value) {
|
|
9469
9486
|
if (!Array.isArray(value)) return null;
|
|
9470
9487
|
for (const entry of value) {
|
|
9471
|
-
if (!
|
|
9488
|
+
if (!isRecord9(entry)) continue;
|
|
9472
9489
|
const date = normalizeString(
|
|
9473
9490
|
entry.start_date ?? entry.started_at ?? entry.startDate
|
|
9474
9491
|
);
|
|
@@ -9477,10 +9494,10 @@ function firstExperienceDate(value) {
|
|
|
9477
9494
|
return null;
|
|
9478
9495
|
}
|
|
9479
9496
|
function normalizeJobChange(value) {
|
|
9480
|
-
const record3 =
|
|
9481
|
-
const nested =
|
|
9482
|
-
const output =
|
|
9483
|
-
const person =
|
|
9497
|
+
const record3 = isRecord9(value) ? value : {};
|
|
9498
|
+
const nested = isRecord9(record3.job_change) ? record3.job_change : record3;
|
|
9499
|
+
const output = isRecord9(nested.output) ? nested.output : nested;
|
|
9500
|
+
const person = isRecord9(output.person) ? output.person : {};
|
|
9484
9501
|
const status = normalizeJobChangeStatus(
|
|
9485
9502
|
output.status ?? output.job_change_status ?? output.job_changed ?? output.changed
|
|
9486
9503
|
);
|
|
@@ -9891,7 +9908,7 @@ function attachToolResultListDataset(result, input) {
|
|
|
9891
9908
|
root = replaceAtPath(root, candidate, serialized.preview);
|
|
9892
9909
|
break;
|
|
9893
9910
|
}
|
|
9894
|
-
if (
|
|
9911
|
+
if (isRecord9(root) && isRecord9(root.toolResponse) && Object.prototype.hasOwnProperty.call(root.toolResponse, "raw")) {
|
|
9895
9912
|
result.toolResponse.raw = root.toolResponse.raw;
|
|
9896
9913
|
result.toolOutput.raw = root.toolResponse.raw;
|
|
9897
9914
|
}
|
|
@@ -9909,7 +9926,7 @@ function replaceAtPath(root, path, replacement) {
|
|
|
9909
9926
|
copy[segment] = replace(copy[segment], index + 1);
|
|
9910
9927
|
return copy;
|
|
9911
9928
|
}
|
|
9912
|
-
if (!
|
|
9929
|
+
if (!isRecord9(current)) return current;
|
|
9913
9930
|
return {
|
|
9914
9931
|
...current,
|
|
9915
9932
|
[segment]: replace(current[segment], index + 1)
|
|
@@ -11879,11 +11896,11 @@ var Deepline = class {
|
|
|
11879
11896
|
return new DeeplineContext(options);
|
|
11880
11897
|
}
|
|
11881
11898
|
};
|
|
11882
|
-
function
|
|
11899
|
+
function isRecord10(value) {
|
|
11883
11900
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11884
11901
|
}
|
|
11885
11902
|
function stringArrayRecord(value) {
|
|
11886
|
-
if (!
|
|
11903
|
+
if (!isRecord10(value)) return {};
|
|
11887
11904
|
return Object.fromEntries(
|
|
11888
11905
|
Object.entries(value).map(([key, paths]) => [
|
|
11889
11906
|
key,
|
|
@@ -11895,7 +11912,7 @@ function stringArray(value) {
|
|
|
11895
11912
|
return Array.isArray(value) ? value.map(String) : [];
|
|
11896
11913
|
}
|
|
11897
11914
|
function emailStatusExtractorConfig(value) {
|
|
11898
|
-
if (!
|
|
11915
|
+
if (!isRecord10(value)) return void 0;
|
|
11899
11916
|
const readPaths = (key) => {
|
|
11900
11917
|
const paths = stringArray(value[key]).map((path) => path.trim()).filter(Boolean);
|
|
11901
11918
|
return paths.length > 0 ? paths : void 0;
|
|
@@ -11922,7 +11939,7 @@ function emailStatusExtractorConfig(value) {
|
|
|
11922
11939
|
const paths = readPaths(key);
|
|
11923
11940
|
if (paths) config[key] = paths;
|
|
11924
11941
|
}
|
|
11925
|
-
if (
|
|
11942
|
+
if (isRecord10(value.statusMap)) {
|
|
11926
11943
|
config.statusMap = value.statusMap;
|
|
11927
11944
|
}
|
|
11928
11945
|
if (Array.isArray(value.rules)) {
|
|
@@ -11931,10 +11948,10 @@ function emailStatusExtractorConfig(value) {
|
|
|
11931
11948
|
return config;
|
|
11932
11949
|
}
|
|
11933
11950
|
function extractorDescriptorRecord(value) {
|
|
11934
|
-
if (!
|
|
11951
|
+
if (!isRecord10(value)) return {};
|
|
11935
11952
|
return Object.fromEntries(
|
|
11936
11953
|
Object.entries(value).flatMap(([key, descriptor]) => {
|
|
11937
|
-
if (!
|
|
11954
|
+
if (!isRecord10(descriptor)) return [];
|
|
11938
11955
|
const paths = stringArray(descriptor.paths).map((path) => path.trim()).filter(Boolean);
|
|
11939
11956
|
if (paths.length === 0) return [];
|
|
11940
11957
|
const transforms = stringArray(descriptor.transforms).map((transform) => transform.trim()).filter(Boolean);
|
|
@@ -11956,7 +11973,7 @@ function extractorDescriptorRecord(value) {
|
|
|
11956
11973
|
}
|
|
11957
11974
|
function rowsFromUnknown(value) {
|
|
11958
11975
|
if (!Array.isArray(value)) return [];
|
|
11959
|
-
return value.map((row) =>
|
|
11976
|
+
return value.map((row) => isRecord10(row) ? row : { value: row });
|
|
11960
11977
|
}
|
|
11961
11978
|
function finiteNonNegativeInteger3(value) {
|
|
11962
11979
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
@@ -11978,8 +11995,8 @@ function stableHash(value) {
|
|
|
11978
11995
|
}
|
|
11979
11996
|
function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
11980
11997
|
if (!options || !isQueryResultDatasetTool(toolId)) return result;
|
|
11981
|
-
const raw =
|
|
11982
|
-
const dataset =
|
|
11998
|
+
const raw = isRecord10(result.toolResponse.raw) ? result.toolResponse.raw : null;
|
|
11999
|
+
const dataset = isRecord10(raw?.dataset) ? raw.dataset : null;
|
|
11983
12000
|
const totalRows = finiteNonNegativeInteger3(dataset?.total_rows);
|
|
11984
12001
|
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;
|
|
11985
12002
|
if (!dataset || totalRows === null || !sql) {
|
|
@@ -12011,7 +12028,7 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
12011
12028
|
} : {}
|
|
12012
12029
|
}
|
|
12013
12030
|
});
|
|
12014
|
-
const pageRaw =
|
|
12031
|
+
const pageRaw = isRecord10(response.toolResponse?.raw) ? response.toolResponse.raw : null;
|
|
12015
12032
|
return rowsFromUnknown(pageRaw?.rows);
|
|
12016
12033
|
};
|
|
12017
12034
|
const collectRows = async (limit) => {
|
|
@@ -12068,8 +12085,8 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
12068
12085
|
const rawV2 = response.toolResponse?.rawV2;
|
|
12069
12086
|
const view = response.toolResponse?.view;
|
|
12070
12087
|
const meta = response.toolResponse?.meta;
|
|
12071
|
-
const metadata =
|
|
12072
|
-
const toolMetadata =
|
|
12088
|
+
const metadata = isRecord10(response._metadata) ? response._metadata.tool : null;
|
|
12089
|
+
const toolMetadata = isRecord10(metadata) ? metadata : {};
|
|
12073
12090
|
const result = attachSdkQueryResultDatasetResult(
|
|
12074
12091
|
fallbackToolId,
|
|
12075
12092
|
createToolExecuteResult({
|
|
@@ -12077,12 +12094,12 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
12077
12094
|
jobId: typeof response.job_id === "string" ? response.job_id : void 0,
|
|
12078
12095
|
result: {
|
|
12079
12096
|
data: raw,
|
|
12080
|
-
...
|
|
12097
|
+
...isRecord10(meta) ? { meta } : {}
|
|
12081
12098
|
},
|
|
12082
12099
|
response: {
|
|
12083
12100
|
...rawV2 !== void 0 ? { rawV2 } : {},
|
|
12084
12101
|
...view === "data" || view === "rawV2" ? { view } : {},
|
|
12085
|
-
...
|
|
12102
|
+
...isRecord10(meta) ? { meta } : {}
|
|
12086
12103
|
},
|
|
12087
12104
|
metadata: {
|
|
12088
12105
|
toolId: typeof toolMetadata.toolId === "string" ? toolMetadata.toolId : fallbackToolId,
|
|
@@ -12098,12 +12115,12 @@ function toolExecutionEnvelopeToResult(fallbackToolId, response, options) {
|
|
|
12098
12115
|
cached: false,
|
|
12099
12116
|
source: "live"
|
|
12100
12117
|
},
|
|
12101
|
-
meta:
|
|
12118
|
+
meta: isRecord10(response.meta) ? response.meta : void 0,
|
|
12102
12119
|
billing: response.billing
|
|
12103
12120
|
}),
|
|
12104
12121
|
options
|
|
12105
12122
|
);
|
|
12106
|
-
const executionRecovery =
|
|
12123
|
+
const executionRecovery = isRecord10(response.executionRecovery) ? response.executionRecovery : void 0;
|
|
12107
12124
|
if (typeof response.idempotencyKey === "string") {
|
|
12108
12125
|
result.idempotencyKey = response.idempotencyKey;
|
|
12109
12126
|
}
|