@braze/sanity-plugin-ai-translation 0.2.71 → 0.2.72
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/index.d.ts +23 -0
- package/dist/index.js +32 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -476,6 +476,7 @@ declare type TelemetryEvent =
|
|
|
476
476
|
| TranslationBatchStartedEvent
|
|
477
477
|
| TranslationBatchCompletedEvent
|
|
478
478
|
| TranslationJobCompletedEvent
|
|
479
|
+
| TranslationJobFailedEvent
|
|
479
480
|
| OpenAIApiCallEvent;
|
|
480
481
|
|
|
481
482
|
/**
|
|
@@ -678,6 +679,28 @@ declare interface TranslationJobCompletedEvent extends TelemetryEventBase {
|
|
|
678
679
|
};
|
|
679
680
|
}
|
|
680
681
|
|
|
682
|
+
/**
|
|
683
|
+
* Event emitted when an individual translation job fails.
|
|
684
|
+
* This is emitted alongside the detailed error bundle (via onError) to enable
|
|
685
|
+
* easy error rate calculations by comparing job_completed vs job_failed counts.
|
|
686
|
+
* @public
|
|
687
|
+
*/
|
|
688
|
+
declare interface TranslationJobFailedEvent extends TelemetryEventBase {
|
|
689
|
+
name: "translation.job_failed";
|
|
690
|
+
data: {
|
|
691
|
+
documentId: string;
|
|
692
|
+
documentType: string;
|
|
693
|
+
sourceLanguage: string;
|
|
694
|
+
targetLanguage: string;
|
|
695
|
+
translationMode: TranslationMode;
|
|
696
|
+
durationMs: number;
|
|
697
|
+
/** Categorized error type for filtering/grouping */
|
|
698
|
+
errorType: TranslationErrorType;
|
|
699
|
+
/** Error message (kept short for metrics; full details in error bundle) */
|
|
700
|
+
errorMessage: string;
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
681
704
|
declare type TranslationMode = "sanity-only" | "openai-only";
|
|
682
705
|
|
|
683
706
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2892,7 +2892,8 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2892
2892
|
telemetryConfig
|
|
2893
2893
|
}), newDocument = translationResult?.document;
|
|
2894
2894
|
if (!newDocument) {
|
|
2895
|
-
|
|
2895
|
+
const failureError = new Error("Translation returned null");
|
|
2896
|
+
devLog.error("Translation failed: no document returned", failureError, logContext), setJobStatus(
|
|
2896
2897
|
dispatch,
|
|
2897
2898
|
sourceDocument._id,
|
|
2898
2899
|
targetLanguage,
|
|
@@ -2901,7 +2902,20 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2901
2902
|
errorMessage: "Translation failed"
|
|
2902
2903
|
},
|
|
2903
2904
|
mainSourceDocumentId
|
|
2904
|
-
),
|
|
2905
|
+
), emitTelemetryEvent(telemetryConfig, {
|
|
2906
|
+
name: "translation.job_failed",
|
|
2907
|
+
timestamp: createTimestamp(),
|
|
2908
|
+
data: {
|
|
2909
|
+
documentId: sourceDocument._id,
|
|
2910
|
+
documentType: sourceDocument._type,
|
|
2911
|
+
sourceLanguage,
|
|
2912
|
+
targetLanguage,
|
|
2913
|
+
translationMode,
|
|
2914
|
+
durationMs: Date.now() - jobStartTime,
|
|
2915
|
+
errorType: classifyError(failureError),
|
|
2916
|
+
errorMessage: "Translation failed"
|
|
2917
|
+
}
|
|
2918
|
+
}), devLog.timeEnd("translateDocument"), devLog.groupEnd();
|
|
2905
2919
|
return;
|
|
2906
2920
|
}
|
|
2907
2921
|
return setJobStatus(
|
|
@@ -2950,8 +2964,8 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2950
2964
|
}
|
|
2951
2965
|
}), devLog.timeEnd("translateDocument"), devLog.groupEnd(), newDocument._id;
|
|
2952
2966
|
} catch (error) {
|
|
2953
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2954
|
-
devLog.error("Translation failed",
|
|
2967
|
+
const errorMessage = error instanceof Error ? error.message : String(error), errorObj = error instanceof Error ? error : new Error(String(error));
|
|
2968
|
+
devLog.error("Translation failed", errorObj, logContext), setJobStatus(
|
|
2955
2969
|
dispatch,
|
|
2956
2970
|
sourceDocument._id,
|
|
2957
2971
|
targetLanguage,
|
|
@@ -2960,7 +2974,20 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
2960
2974
|
errorMessage
|
|
2961
2975
|
},
|
|
2962
2976
|
mainSourceDocumentId
|
|
2963
|
-
),
|
|
2977
|
+
), emitTelemetryEvent(telemetryConfig, {
|
|
2978
|
+
name: "translation.job_failed",
|
|
2979
|
+
timestamp: createTimestamp(),
|
|
2980
|
+
data: {
|
|
2981
|
+
documentId: sourceDocument._id,
|
|
2982
|
+
documentType: sourceDocument._type,
|
|
2983
|
+
sourceLanguage,
|
|
2984
|
+
targetLanguage,
|
|
2985
|
+
translationMode,
|
|
2986
|
+
durationMs: Date.now() - jobStartTime,
|
|
2987
|
+
errorType: classifyError(errorObj),
|
|
2988
|
+
errorMessage
|
|
2989
|
+
}
|
|
2990
|
+
}), devLog.timeEnd("translateDocument"), devLog.groupEnd();
|
|
2964
2991
|
return;
|
|
2965
2992
|
}
|
|
2966
2993
|
}, translationSemaphore = new Semaphore(2), translateDocumentSet = async ({
|