@braze/sanity-plugin-ai-translation 0.3.1 → 0.3.2

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 CHANGED
@@ -248,9 +248,16 @@ aiTranslationPlugin({
248
248
  The plugin exposes a server-only entry at `@braze/sanity-plugin-ai-translation/server` for running the OpenAI call outside the browser (for example in a Sanity function). It does not load React or Studio, it is not part of the Studio bundle, and it does not read the API key from the environment, so the caller passes it in.
249
249
 
250
250
  ```typescript
251
- import { requestOpenAICompletion } from "@braze/sanity-plugin-ai-translation/server";
251
+ import {
252
+ isOpenAIModel,
253
+ OPENAI_MODELS,
254
+ requestOpenAICompletion,
255
+ } from "@braze/sanity-plugin-ai-translation/server";
252
256
 
253
257
  // payload: { model, messages, reasoningEffort?, temperature? } assembled in Studio
258
+ if (!isOpenAIModel(payload.model)) {
259
+ throw new Error(`model must be one of ${OPENAI_MODELS.join(", ")}`);
260
+ }
254
261
  const { content, tokensUsed } = await requestOpenAICompletion(payload, {
255
262
  apiKey: process.env.OPENAI_API_KEY!,
256
263
  });
@@ -262,7 +269,7 @@ The first argument is the client-supplied request and is validated at runtime. T
262
269
  - Only `role` and `content` are sent for each message. Any other fields in the payload are dropped.
263
270
  - Logs never include prompt or document text, even with plugin logging turned on. They include only the model, message roles, and content lengths.
264
271
 
265
- Serialization, prompt assembly, structure validation, and the Content Release write stay in Studio. The entry does not allowlist models. Do that in the caller before invoking it.
272
+ Serialization, prompt assembly, structure validation, and the Content Release write stay in Studio. The entry does not allowlist models on its own. Do that in the caller before invoking it, with `isOpenAIModel` (or `OPENAI_MODELS`): it is the same list the `openai.model` plugin option accepts, so Studio and the function never disagree about which models are allowed.
266
273
 
267
274
  ---
268
275
 
package/dist/index.d.ts CHANGED
@@ -265,6 +265,26 @@ export declare type InferOriginalType<T> =
265
265
  export declare type InferTranslatableType<T> =
266
266
  T extends FieldTransform<unknown, infer R> ? R : never;
267
267
 
268
+ /**
269
+ * OpenAI models the plugin supports.
270
+ *
271
+ * This is the single source of truth: Studio's `PluginConfig['openai']['model']` is derived from
272
+ * it, and the translation function allowlists against it before calling `requestOpenAICompletion`,
273
+ * so the two can never drift apart.
274
+ *
275
+ * @public
276
+ */
277
+ declare const OPENAI_MODELS: readonly [
278
+ "gpt-5.1",
279
+ "gpt-5",
280
+ "gpt-5-mini",
281
+ "gpt-5-nano",
282
+ "gpt-5-pro",
283
+ "gpt-4o",
284
+ "gpt-4-turbo",
285
+ "gpt-4",
286
+ ];
287
+
268
288
  /**
269
289
  * Event emitted when an OpenAI API call is made
270
290
  * @public
@@ -284,6 +304,13 @@ declare interface OpenAIApiCallEvent extends TelemetryEventBase {
284
304
  };
285
305
  }
286
306
 
307
+ /**
308
+ * An OpenAI model id from {@link OPENAI_MODELS}
309
+ *
310
+ * @public
311
+ */
312
+ export declare type OpenAIModel = (typeof OPENAI_MODELS)[number];
313
+
287
314
  /**
288
315
  *
289
316
  * Configuration for the Sanity AI Translation plugin.
@@ -313,15 +340,11 @@ export declare interface PluginConfig {
313
340
  * @defaultValue 'ai-translation'
314
341
  */
315
342
  functionName?: string;
316
- model?:
317
- | "gpt-5.1"
318
- | "gpt-5"
319
- | "gpt-5-mini"
320
- | "gpt-5-nano"
321
- | "gpt-5-pro"
322
- | "gpt-4o"
323
- | "gpt-4-turbo"
324
- | "gpt-4";
343
+ /**
344
+ * OpenAI model id. Must be one of `OPENAI_MODELS` from the server entry.
345
+ * @defaultValue 'gpt-5'
346
+ */
347
+ model?: OpenAIModel;
325
348
  reasoningEffort?: "low" | "medium" | "high";
326
349
  enabled?: boolean;
327
350
  defaultMode?: TranslationMode;