@braze/sanity-plugin-ai-translation 0.2.5 → 0.2.7
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/README.md +394 -191
- package/dist/index.d.ts +255 -0
- package/dist/index.js +1726 -200
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -269,6 +269,26 @@ export declare type InferOriginalType<T> =
|
|
|
269
269
|
export declare type InferTranslatableType<T> =
|
|
270
270
|
T extends FieldTransform<unknown, infer R> ? R : never;
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Event emitted when an OpenAI API call is made
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
declare interface OpenAIApiCallEvent extends TelemetryEventBase {
|
|
277
|
+
name: "openai.api_call";
|
|
278
|
+
data: {
|
|
279
|
+
model: string;
|
|
280
|
+
tokensUsed: {
|
|
281
|
+
prompt: number;
|
|
282
|
+
completion: number;
|
|
283
|
+
reasoning: number;
|
|
284
|
+
total: number;
|
|
285
|
+
cached: number;
|
|
286
|
+
};
|
|
287
|
+
cost: number;
|
|
288
|
+
durationMs: number;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
272
292
|
/**
|
|
273
293
|
*
|
|
274
294
|
* Configuration for the Sanity AI Translation plugin.
|
|
@@ -312,6 +332,19 @@ export declare interface PluginConfig {
|
|
|
312
332
|
* ```
|
|
313
333
|
*/
|
|
314
334
|
excludeFields?: string[];
|
|
335
|
+
/**
|
|
336
|
+
* Optional telemetry configuration for monitoring translation operations.
|
|
337
|
+
* Provides callbacks for lightweight events and detailed error bundles.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* telemetry: {
|
|
342
|
+
* onEvent: (event) => datadogRum.addAction(event.name, event.data),
|
|
343
|
+
* onError: (bundle) => datadogLogs.logger.error('Translation failed', bundle)
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
telemetry?: TelemetryConfig;
|
|
315
348
|
}
|
|
316
349
|
|
|
317
350
|
/**
|
|
@@ -374,6 +407,8 @@ export declare const PREDEFINED_EXCLUSIONS: {
|
|
|
374
407
|
];
|
|
375
408
|
};
|
|
376
409
|
|
|
410
|
+
declare type ReleaseSelectionMode = "new" | "existing";
|
|
411
|
+
|
|
377
412
|
/**
|
|
378
413
|
* Restores previously excluded fields to a translated document
|
|
379
414
|
* @param translatedDocument - The translated document
|
|
@@ -402,6 +437,56 @@ export declare const richTextTransform: FieldTransform<
|
|
|
402
437
|
TranslatableRichText
|
|
403
438
|
>;
|
|
404
439
|
|
|
440
|
+
/**
|
|
441
|
+
* Configuration for telemetry/monitoring integration.
|
|
442
|
+
* Both callbacks are optional - configure based on your monitoring needs.
|
|
443
|
+
* @public
|
|
444
|
+
*
|
|
445
|
+
* @example Basic Datadog RUM integration
|
|
446
|
+
* ```typescript
|
|
447
|
+
* telemetry: {
|
|
448
|
+
* onEvent: (event) => datadogRum.addAction(event.name, event.data),
|
|
449
|
+
* onError: (bundle) => datadogRum.addError(new Error(bundle.error.message), {
|
|
450
|
+
* documentId: bundle.documentId,
|
|
451
|
+
* errorType: bundle.error.type,
|
|
452
|
+
* })
|
|
453
|
+
* }
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
declare interface TelemetryConfig {
|
|
457
|
+
/**
|
|
458
|
+
* Lightweight event callback - called for all translation events.
|
|
459
|
+
* Keep payloads small (IDs, counts, durations, costs).
|
|
460
|
+
* @param event - The telemetry event with name and data
|
|
461
|
+
*/
|
|
462
|
+
onEvent?: (event: TelemetryEvent) => void;
|
|
463
|
+
/**
|
|
464
|
+
* Error callback with full debug bundle - only called on failures.
|
|
465
|
+
* Consumer decides how to handle (send to Datadog, store locally, truncate, etc.)
|
|
466
|
+
* @param bundle - Full debug context for troubleshooting
|
|
467
|
+
*/
|
|
468
|
+
onError?: (bundle: TranslationErrorBundle) => void;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Union of all telemetry event types
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
475
|
+
declare type TelemetryEvent =
|
|
476
|
+
| TranslationBatchStartedEvent
|
|
477
|
+
| TranslationBatchCompletedEvent
|
|
478
|
+
| TranslationJobCompletedEvent
|
|
479
|
+
| OpenAIApiCallEvent;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Base interface for all telemetry events
|
|
483
|
+
* @public
|
|
484
|
+
*/
|
|
485
|
+
declare interface TelemetryEventBase {
|
|
486
|
+
name: string;
|
|
487
|
+
timestamp: string;
|
|
488
|
+
}
|
|
489
|
+
|
|
405
490
|
/**
|
|
406
491
|
* Context passed to transform functions.
|
|
407
492
|
* @public
|
|
@@ -446,6 +531,122 @@ declare interface TranslatableVTTCaptions {
|
|
|
446
531
|
_originalMetadata: VTTCaptionMetadata[];
|
|
447
532
|
}
|
|
448
533
|
|
|
534
|
+
/**
|
|
535
|
+
* Special type to track transformed Wistia captions.
|
|
536
|
+
* This combines metadata separation for token efficiency with compact text format for translation.
|
|
537
|
+
*/
|
|
538
|
+
declare interface TranslatableWistiaCaptions {
|
|
539
|
+
_type: "translatable.wistia.captions";
|
|
540
|
+
translationText: string;
|
|
541
|
+
_originalMetadata: WistiaCaptionsMetadata;
|
|
542
|
+
_srtCues: Array<{
|
|
543
|
+
index: number;
|
|
544
|
+
startTime: string;
|
|
545
|
+
endTime: string;
|
|
546
|
+
}>;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Event emitted when a translation batch completes
|
|
551
|
+
* @public
|
|
552
|
+
*/
|
|
553
|
+
declare interface TranslationBatchCompletedEvent extends TelemetryEventBase {
|
|
554
|
+
name: "translation.batch_completed";
|
|
555
|
+
data: {
|
|
556
|
+
documentId: string;
|
|
557
|
+
documentType: string;
|
|
558
|
+
sourceLanguage: string;
|
|
559
|
+
targetLanguages: string[];
|
|
560
|
+
translationMode: TranslationMode;
|
|
561
|
+
succeeded: number;
|
|
562
|
+
failed: number;
|
|
563
|
+
skipped: number;
|
|
564
|
+
durationMs: number;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Event emitted when a translation batch starts
|
|
570
|
+
* @public
|
|
571
|
+
*/
|
|
572
|
+
declare interface TranslationBatchStartedEvent extends TelemetryEventBase {
|
|
573
|
+
name: "translation.batch_started";
|
|
574
|
+
data: {
|
|
575
|
+
documentId: string;
|
|
576
|
+
documentType: string;
|
|
577
|
+
sourceLanguage: string;
|
|
578
|
+
targetLanguages: string[];
|
|
579
|
+
translationMode: TranslationMode;
|
|
580
|
+
referenceCount: number;
|
|
581
|
+
releaseMode: ReleaseSelectionMode;
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Debug bundle containing full context for troubleshooting translation failures.
|
|
587
|
+
* This is only emitted when a translation fails.
|
|
588
|
+
* @public
|
|
589
|
+
*/
|
|
590
|
+
declare interface TranslationErrorBundle {
|
|
591
|
+
/** Document ID being translated */
|
|
592
|
+
documentId: string;
|
|
593
|
+
/** Document schema type */
|
|
594
|
+
documentType: string;
|
|
595
|
+
/** Target language for translation */
|
|
596
|
+
targetLanguage: string;
|
|
597
|
+
/** Source language of the document */
|
|
598
|
+
sourceLanguage: string;
|
|
599
|
+
/** Translation mode used */
|
|
600
|
+
translationMode: TranslationMode;
|
|
601
|
+
/** Error details */
|
|
602
|
+
error: {
|
|
603
|
+
/** Error message */
|
|
604
|
+
message: string;
|
|
605
|
+
/** Error stack trace if available */
|
|
606
|
+
stack?: string;
|
|
607
|
+
/** Categorized error type for filtering/alerting */
|
|
608
|
+
type: TranslationErrorType;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Debug data for troubleshooting.
|
|
612
|
+
* Can be large - consumer decides how to handle (truncate, store locally, etc.)
|
|
613
|
+
*/
|
|
614
|
+
debug: {
|
|
615
|
+
/** Full source document */
|
|
616
|
+
originalDocument: SanityDocument;
|
|
617
|
+
/** XML-serialized document sent to OpenAI (if OpenAI mode) */
|
|
618
|
+
serializedDocument?: string;
|
|
619
|
+
/** Raw API response from OpenAI (if OpenAI mode) */
|
|
620
|
+
openaiResponse?: string;
|
|
621
|
+
/** Translation prompts used */
|
|
622
|
+
translationPrompts?: {
|
|
623
|
+
globalPrompt?: string;
|
|
624
|
+
localePrompt?: string;
|
|
625
|
+
protectedPhrases?: string[];
|
|
626
|
+
glossaryTerms?: any[];
|
|
627
|
+
};
|
|
628
|
+
/** Validation errors if structure validation failed */
|
|
629
|
+
validationErrors?: any[];
|
|
630
|
+
};
|
|
631
|
+
/** ISO timestamp when error occurred */
|
|
632
|
+
timestamp: string;
|
|
633
|
+
/** Duration of the translation attempt in milliseconds */
|
|
634
|
+
durationMs: number;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Error types for categorizing translation failures
|
|
639
|
+
* @public
|
|
640
|
+
*/
|
|
641
|
+
declare type TranslationErrorType =
|
|
642
|
+
| "serialization"
|
|
643
|
+
| "deserialization"
|
|
644
|
+
| "openai_api"
|
|
645
|
+
| "validation"
|
|
646
|
+
| "sanity_agent"
|
|
647
|
+
| "network"
|
|
648
|
+
| "unknown";
|
|
649
|
+
|
|
449
650
|
/**
|
|
450
651
|
* Schema for translation history
|
|
451
652
|
*
|
|
@@ -459,6 +660,24 @@ export declare const translationHistorySchema: {
|
|
|
459
660
|
WidenValidation &
|
|
460
661
|
WidenInitialValue;
|
|
461
662
|
|
|
663
|
+
/**
|
|
664
|
+
* Event emitted when an individual translation job completes successfully
|
|
665
|
+
* @public
|
|
666
|
+
*/
|
|
667
|
+
declare interface TranslationJobCompletedEvent extends TelemetryEventBase {
|
|
668
|
+
name: "translation.job_completed";
|
|
669
|
+
data: {
|
|
670
|
+
documentId: string;
|
|
671
|
+
documentType: string;
|
|
672
|
+
sourceLanguage: string;
|
|
673
|
+
targetLanguage: string;
|
|
674
|
+
translationMode: TranslationMode;
|
|
675
|
+
durationMs: number;
|
|
676
|
+
tokensUsed?: number;
|
|
677
|
+
estimatedCost?: number;
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
462
681
|
declare type TranslationMode = "sanity-only" | "openai-only";
|
|
463
682
|
|
|
464
683
|
/**
|
|
@@ -497,4 +716,40 @@ export declare const vttCaptionTransform: FieldTransform<
|
|
|
497
716
|
TranslatableVTTCaptions
|
|
498
717
|
>;
|
|
499
718
|
|
|
719
|
+
/**
|
|
720
|
+
* Represents a Wistia captions object with SRT content and metadata.
|
|
721
|
+
*/
|
|
722
|
+
declare interface WistiaCaptions {
|
|
723
|
+
captionContent?: string;
|
|
724
|
+
captionFileName?: string;
|
|
725
|
+
isoLanguage?: string;
|
|
726
|
+
captionUploadStatus?: string;
|
|
727
|
+
captionUploadMessage?: string;
|
|
728
|
+
[key: string]: string | undefined;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Wistia captions metadata without captionContent, used for preservation during translation.
|
|
733
|
+
*/
|
|
734
|
+
declare interface WistiaCaptionsMetadata {
|
|
735
|
+
captionFileName?: string;
|
|
736
|
+
isoLanguage?: string;
|
|
737
|
+
captionUploadStatus?: string;
|
|
738
|
+
captionUploadMessage?: string;
|
|
739
|
+
_originalIndex: number;
|
|
740
|
+
[key: string]: string | number | undefined;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Transform for handling Wistia captions in documents using SRT format.
|
|
745
|
+
* This stores metadata separately for token efficiency while formatting
|
|
746
|
+
* text content in a compact indexed format for better translation results.
|
|
747
|
+
*
|
|
748
|
+
* @public
|
|
749
|
+
*/
|
|
750
|
+
export declare const wistiaCaptionTransform: FieldTransform<
|
|
751
|
+
WistiaCaptions,
|
|
752
|
+
TranslatableWistiaCaptions
|
|
753
|
+
>;
|
|
754
|
+
|
|
500
755
|
export {};
|