diff --git a/sdk/contentsafety/ai-content-safety-rest/api-extractor.json b/sdk/contentsafety/ai-content-safety-rest/api-extractor.json index c3efb349c43a..13a4abc8baf1 100644 --- a/sdk/contentsafety/ai-content-safety-rest/api-extractor.json +++ b/sdk/contentsafety/ai-content-safety-rest/api-extractor.json @@ -1,18 +1,31 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", "mainEntryPointFilePath": "./types/src/index.d.ts", - "docModel": { "enabled": true }, - "apiReport": { "enabled": true, "reportFolder": "./review" }, + "docModel": { + "enabled": true + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, "dtsRollup": { "enabled": true, "untrimmedFilePath": "", "publicTrimmedFilePath": "./types/ai-content-safety.d.ts" }, "messages": { - "tsdocMessageReporting": { "default": { "logLevel": "none" } }, + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, "extractorMessageReporting": { - "ae-missing-release-tag": { "logLevel": "none" }, - "ae-unresolved-link": { "logLevel": "none" } + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } } } -} +} \ No newline at end of file diff --git a/sdk/contentsafety/ai-content-safety-rest/package.json b/sdk/contentsafety/ai-content-safety-rest/package.json index 24a904b8c133..cd33454b006c 100644 --- a/sdk/contentsafety/ai-content-safety-rest/package.json +++ b/sdk/contentsafety/ai-content-safety-rest/package.json @@ -128,4 +128,4 @@ "disableDocsMs": true, "apiRefLink": "https://docs.microsoft.com/javascript/api/@azure-rest/ai-content-safety?view=azure-node-preview" } -} +} \ No newline at end of file diff --git a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md index 557b396ff4ed..004ea7a949c0 100644 --- a/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md +++ b/sdk/contentsafety/ai-content-safety-rest/review/ai-content-safety.api.md @@ -98,17 +98,13 @@ export interface AnalyzeImageDefaultResponse extends HttpResponse { // @public export interface AnalyzeImageOptions { - categories?: string[]; + categories?: ImageCategory[]; image: ImageData_2; - outputType?: string; + outputType?: AnalyzeImageOutputType; } // @public -export interface AnalyzeImageOptionsOutput { - categories?: string[]; - image: ImageDataOutput; - outputType?: string; -} +export type AnalyzeImageOutputType = string; // @public (undocumented) export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters; @@ -154,20 +150,14 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse { // @public export interface AnalyzeTextOptions { blocklistNames?: string[]; - categories?: string[]; + categories?: TextCategory[]; haltOnBlocklistHit?: boolean; - outputType?: string; + outputType?: AnalyzeTextOutputType; text: string; } // @public -export interface AnalyzeTextOptionsOutput { - blocklistNames?: string[]; - categories?: string[]; - haltOnBlocklistHit?: boolean; - outputType?: string; - text: string; -} +export type AnalyzeTextOutputType = string; // @public (undocumented) export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; @@ -184,7 +174,12 @@ export type ContentSafetyClient = Client & { }; // @public -function createClient(endpoint: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): ContentSafetyClient; +export interface ContentSafetyClientOptions extends ClientOptions { + apiVersion?: string; +} + +// @public +function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, { apiVersion, ...options }?: ContentSafetyClientOptions): ContentSafetyClient; export default createClient; // @public @@ -255,6 +250,57 @@ export interface DeleteTextBlocklistDefaultResponse extends HttpResponse { // @public (undocumented) export type DeleteTextBlocklistParameters = RequestParameters; +// @public (undocumented) +export interface DetectTextProtectedMaterial { + post(options: DetectTextProtectedMaterialParameters): StreamableMethod; +} + +// @public +export interface DetectTextProtectedMaterial200Response extends HttpResponse { + // (undocumented) + body: DetectTextProtectedMaterialResultOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialBodyParam { + body: DetectTextProtectedMaterialOptions; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialDefaultHeaders { + "x-ms-error-code"?: string; +} + +// @public (undocumented) +export interface DetectTextProtectedMaterialDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponse; + // (undocumented) + headers: RawHttpHeaders & DetectTextProtectedMaterialDefaultHeaders; + // (undocumented) + status: string; +} + +// @public +export interface DetectTextProtectedMaterialOptions { + text: string; +} + +// @public (undocumented) +export type DetectTextProtectedMaterialParameters = DetectTextProtectedMaterialBodyParam & RequestParameters; + +// @public +export interface DetectTextProtectedMaterialResultOutput { + protectedMaterialAnalysis: TextProtectedMaterialAnalysisResultOutput; +} + +// @public +export interface DocumentInjectionAnalysisResultOutput { + attackDetected: boolean; +} + // @public export type GetArrayType = T extends Array ? TData : never; @@ -330,10 +376,16 @@ export type GetTextBlocklistParameters = RequestParameters; // @public export interface ImageCategoriesAnalysisOutput { - category: string; + category: ImageCategoryOutput; severity?: number; } +// @public +export type ImageCategory = string; + +// @public +export type ImageCategoryOutput = string; + // @public interface ImageData_2 { blobUrl?: string; @@ -341,17 +393,17 @@ interface ImageData_2 { } export { ImageData_2 as ImageData } -// @public -export interface ImageDataOutput { - blobUrl?: string; - content?: string; -} +// @public (undocumented) +export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse; // @public (undocumented) export function isUnexpected(response: AnalyzeText200Response | AnalyzeTextDefaultResponse): response is AnalyzeTextDefaultResponse; // @public (undocumented) -export function isUnexpected(response: AnalyzeImage200Response | AnalyzeImageDefaultResponse): response is AnalyzeImageDefaultResponse; +export function isUnexpected(response: ShieldPrompt200Response | ShieldPromptDefaultResponse): response is ShieldPromptDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: DetectTextProtectedMaterial200Response | DetectTextProtectedMaterialDefaultResponse): response is DetectTextProtectedMaterialDefaultResponse; // @public (undocumented) export function isUnexpected(response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse): response is GetTextBlocklistDefaultResponse; @@ -514,8 +566,10 @@ export interface RemoveTextBlocklistItemsOptions { // @public (undocumented) export interface Routes { - (path: "/text:analyze"): AnalyzeText; (path: "/image:analyze"): AnalyzeImage; + (path: "/text:analyze"): AnalyzeText; + (path: "/text:shieldPrompt"): ShieldPrompt; + (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; (path: "/text/blocklists"): ListTextBlocklists; (path: "/text/blocklists/{blocklistName}:addOrUpdateBlocklistItems", blocklistName: string): AddOrUpdateBlocklistItems; @@ -524,6 +578,54 @@ export interface Routes { (path: "/text/blocklists/{blocklistName}/blocklistItems", blocklistName: string): ListTextBlocklistItems; } +// @public (undocumented) +export interface ShieldPrompt { + post(options: ShieldPromptParameters): StreamableMethod; +} + +// @public +export interface ShieldPrompt200Response extends HttpResponse { + // (undocumented) + body: ShieldPromptResultOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ShieldPromptBodyParam { + body: ShieldPromptOptions; +} + +// @public (undocumented) +export interface ShieldPromptDefaultHeaders { + "x-ms-error-code"?: string; +} + +// @public (undocumented) +export interface ShieldPromptDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponse; + // (undocumented) + headers: RawHttpHeaders & ShieldPromptDefaultHeaders; + // (undocumented) + status: string; +} + +// @public +export interface ShieldPromptOptions { + documents?: string[]; + userPrompt?: string; +} + +// @public (undocumented) +export type ShieldPromptParameters = ShieldPromptBodyParam & RequestParameters; + +// @public +export interface ShieldPromptResultOutput { + documentsAnalysis?: Array; + userPromptAnalysis?: UserPromptInjectionAnalysisResultOutput; +} + // @public export interface TextBlocklist { blocklistName: string; @@ -533,6 +635,7 @@ export interface TextBlocklist { // @public export interface TextBlocklistItem { description?: string; + isRegex?: boolean; text: string; } @@ -540,6 +643,7 @@ export interface TextBlocklistItem { export interface TextBlocklistItemOutput { readonly blocklistItemId: string; description?: string; + isRegex?: boolean; text: string; } @@ -561,10 +665,26 @@ export type TextBlocklistResourceMergeAndPatch = Partial; // @public export interface TextCategoriesAnalysisOutput { - category: string; + category: TextCategoryOutput; severity?: number; } +// @public +export type TextCategory = string; + +// @public +export type TextCategoryOutput = string; + +// @public +export interface TextProtectedMaterialAnalysisResultOutput { + detected: boolean; +} + +// @public +export interface UserPromptInjectionAnalysisResultOutput { + attackDetected: boolean; +} + // (No @packageDocumentation comment for this package) ``` diff --git a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts index e1d5978a3897..95259523be47 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/clientDefinitions.ts @@ -2,8 +2,10 @@ // Licensed under the MIT license. import { - AnalyzeTextParameters, AnalyzeImageParameters, + AnalyzeTextParameters, + ShieldPromptParameters, + DetectTextProtectedMaterialParameters, GetTextBlocklistParameters, CreateOrUpdateTextBlocklistParameters, DeleteTextBlocklistParameters, @@ -12,12 +14,16 @@ import { RemoveBlocklistItemsParameters, GetTextBlocklistItemParameters, ListTextBlocklistItemsParameters, -} from "./parameters"; +} from "./parameters.js"; import { - AnalyzeText200Response, - AnalyzeTextDefaultResponse, AnalyzeImage200Response, AnalyzeImageDefaultResponse, + AnalyzeText200Response, + AnalyzeTextDefaultResponse, + ShieldPrompt200Response, + ShieldPromptDefaultResponse, + DetectTextProtectedMaterial200Response, + DetectTextProtectedMaterialDefaultResponse, GetTextBlocklist200Response, GetTextBlocklistDefaultResponse, CreateOrUpdateTextBlocklist200Response, @@ -35,9 +41,16 @@ import { GetTextBlocklistItemDefaultResponse, ListTextBlocklistItems200Response, ListTextBlocklistItemsDefaultResponse, -} from "./responses"; +} from "./responses.js"; import { Client, StreamableMethod } from "@azure-rest/core-client"; +export interface AnalyzeImage { + /** A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence. */ + post( + options: AnalyzeImageParameters, + ): StreamableMethod; +} + export interface AnalyzeText { /** A synchronous API for the analysis of potentially harmful text content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence. */ post( @@ -45,18 +58,30 @@ export interface AnalyzeText { ): StreamableMethod; } -export interface AnalyzeImage { - /** A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence. */ +export interface ShieldPrompt { + /** A synchronous API for shielding prompt from direct and indirect injection attacks. */ post( - options: AnalyzeImageParameters, - ): StreamableMethod; + options: ShieldPromptParameters, + ): StreamableMethod; +} + +export interface DetectTextProtectedMaterial { + /** A synchronous API for detecting protected material in the given text. */ + post( + options: DetectTextProtectedMaterialParameters, + ): StreamableMethod< + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse + >; } export interface GetTextBlocklist { /** Returns text blocklist details. */ get( options?: GetTextBlocklistParameters, - ): StreamableMethod; + ): StreamableMethod< + GetTextBlocklist200Response | GetTextBlocklistDefaultResponse + >; /** Updates a text blocklist. If the blocklistName does not exist, a new blocklist will be created. */ patch( options: CreateOrUpdateTextBlocklistParameters, @@ -68,14 +93,18 @@ export interface GetTextBlocklist { /** Deletes a text blocklist. */ delete( options?: DeleteTextBlocklistParameters, - ): StreamableMethod; + ): StreamableMethod< + DeleteTextBlocklist204Response | DeleteTextBlocklistDefaultResponse + >; } export interface ListTextBlocklists { /** Get all text blocklists details. */ get( options?: ListTextBlocklistsParameters, - ): StreamableMethod; + ): StreamableMethod< + ListTextBlocklists200Response | ListTextBlocklistsDefaultResponse + >; } export interface AddOrUpdateBlocklistItems { @@ -83,7 +112,8 @@ export interface AddOrUpdateBlocklistItems { post( options: AddOrUpdateBlocklistItemsParameters, ): StreamableMethod< - AddOrUpdateBlocklistItems200Response | AddOrUpdateBlocklistItemsDefaultResponse + | AddOrUpdateBlocklistItems200Response + | AddOrUpdateBlocklistItemsDefaultResponse >; } @@ -91,30 +121,43 @@ export interface RemoveBlocklistItems { /** Remove blocklistItems from a text blocklist. You can remove at most 100 BlocklistItems in one request. */ post( options: RemoveBlocklistItemsParameters, - ): StreamableMethod; + ): StreamableMethod< + RemoveBlocklistItems204Response | RemoveBlocklistItemsDefaultResponse + >; } export interface GetTextBlocklistItem { /** Get blocklistItem by blocklistName and blocklistItemId from a text blocklist. */ get( options?: GetTextBlocklistItemParameters, - ): StreamableMethod; + ): StreamableMethod< + GetTextBlocklistItem200Response | GetTextBlocklistItemDefaultResponse + >; } export interface ListTextBlocklistItems { /** Get all blocklistItems in a text blocklist. */ get( options?: ListTextBlocklistItemsParameters, - ): StreamableMethod; + ): StreamableMethod< + ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse + >; } export interface Routes { - /** Resource for '/text:analyze' has methods for the following verbs: post */ - (path: "/text:analyze"): AnalyzeText; /** Resource for '/image:analyze' has methods for the following verbs: post */ (path: "/image:analyze"): AnalyzeImage; + /** Resource for '/text:analyze' has methods for the following verbs: post */ + (path: "/text:analyze"): AnalyzeText; + /** Resource for '/text:shieldPrompt' has methods for the following verbs: post */ + (path: "/text:shieldPrompt"): ShieldPrompt; + /** Resource for '/text:detectProtectedMaterial' has methods for the following verbs: post */ + (path: "/text:detectProtectedMaterial"): DetectTextProtectedMaterial; /** Resource for '/text/blocklists/\{blocklistName\}' has methods for the following verbs: get, patch, delete */ - (path: "/text/blocklists/{blocklistName}", blocklistName: string): GetTextBlocklist; + ( + path: "/text/blocklists/{blocklistName}", + blocklistName: string, + ): GetTextBlocklist; /** Resource for '/text/blocklists' has methods for the following verbs: get */ (path: "/text/blocklists"): ListTextBlocklists; /** Resource for '/text/blocklists/\{blocklistName\}:addOrUpdateBlocklistItems' has methods for the following verbs: post */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts index fd46e945ce08..2c638af7f2cc 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/contentSafetyClient.ts @@ -2,25 +2,31 @@ // Licensed under the MIT license. import { getClient, ClientOptions } from "@azure-rest/core-client"; -import { logger } from "./logger"; +import { logger } from "./logger.js"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; -import { ContentSafetyClient } from "./clientDefinitions"; +import { ContentSafetyClient } from "./clientDefinitions.js"; + +/** The optional parameters for the client */ +export interface ContentSafetyClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} /** * Initialize a new instance of `ContentSafetyClient` - * @param endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: + * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: * https://.cognitiveservices.azure.com). * @param credentials - uniquely identify client credential * @param options - the parameter for all optional parameters */ export default function createClient( - endpoint: string, + endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + { apiVersion = "2024-09-01", ...options }: ContentSafetyClientOptions = {}, ): ContentSafetyClient { - const baseUrl = options.baseUrl ?? `${endpoint}/contentsafety`; - options.apiVersion = options.apiVersion ?? "2023-10-01"; - const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.1`; + const endpointUrl = + options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`; + const userAgentInfo = `azsdk-js-ai-content-safety-rest/1.0.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` @@ -34,12 +40,35 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, credentials: { - scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"], - apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", + scopes: options.credentials?.scopes ?? [ + "https://cognitiveservices.azure.com/.default", + ], + apiKeyHeaderName: + options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; + const client = getClient( + endpointUrl, + credentials, + options, + ) as ContentSafetyClient; - const client = getClient(baseUrl, credentials, options) as ContentSafetyClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); return client; } diff --git a/sdk/contentsafety/ai-content-safety-rest/src/index.ts b/sdk/contentsafety/ai-content-safety-rest/src/index.ts index 566927563535..611b1a6c4c6c 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/index.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/index.ts @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import ContentSafetyClient from "./contentSafetyClient"; +import ContentSafetyClient from "./contentSafetyClient.js"; -export * from "./contentSafetyClient"; -export * from "./parameters"; -export * from "./responses"; -export * from "./clientDefinitions"; -export * from "./isUnexpected"; -export * from "./models"; -export * from "./outputModels"; -export * from "./paginateHelper"; +export * from "./contentSafetyClient.js"; +export * from "./parameters.js"; +export * from "./responses.js"; +export * from "./clientDefinitions.js"; +export * from "./isUnexpected.js"; +export * from "./models.js"; +export * from "./outputModels.js"; +export * from "./paginateHelper.js"; export default ContentSafetyClient; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts index 87938cf526c2..79ae8e222205 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/isUnexpected.ts @@ -2,10 +2,14 @@ // Licensed under the MIT license. import { - AnalyzeText200Response, - AnalyzeTextDefaultResponse, AnalyzeImage200Response, AnalyzeImageDefaultResponse, + AnalyzeText200Response, + AnalyzeTextDefaultResponse, + ShieldPrompt200Response, + ShieldPromptDefaultResponse, + DetectTextProtectedMaterial200Response, + DetectTextProtectedMaterialDefaultResponse, GetTextBlocklist200Response, GetTextBlocklistDefaultResponse, CreateOrUpdateTextBlocklist200Response, @@ -23,27 +27,39 @@ import { GetTextBlocklistItemDefaultResponse, ListTextBlocklistItems200Response, ListTextBlocklistItemsDefaultResponse, -} from "./responses"; +} from "./responses.js"; const responseMap: Record = { - "POST /text:analyze": ["200"], "POST /image:analyze": ["200"], + "POST /text:analyze": ["200"], + "POST /text:shieldPrompt": ["200"], + "POST /text:detectProtectedMaterial": ["200"], "GET /text/blocklists/{blocklistName}": ["200"], "PATCH /text/blocklists/{blocklistName}": ["200", "201"], "DELETE /text/blocklists/{blocklistName}": ["204"], "GET /text/blocklists": ["200"], "POST /text/blocklists/{blocklistName}:addOrUpdateBlocklistItems": ["200"], "POST /text/blocklists/{blocklistName}:removeBlocklistItems": ["204"], - "GET /text/blocklists/{blocklistName}/blocklistItems/{blocklistItemId}": ["200"], + "GET /text/blocklists/{blocklistName}/blocklistItems/{blocklistItemId}": [ + "200", + ], "GET /text/blocklists/{blocklistName}/blocklistItems": ["200"], }; +export function isUnexpected( + response: AnalyzeImage200Response | AnalyzeImageDefaultResponse, +): response is AnalyzeImageDefaultResponse; export function isUnexpected( response: AnalyzeText200Response | AnalyzeTextDefaultResponse, ): response is AnalyzeTextDefaultResponse; export function isUnexpected( - response: AnalyzeImage200Response | AnalyzeImageDefaultResponse, -): response is AnalyzeImageDefaultResponse; + response: ShieldPrompt200Response | ShieldPromptDefaultResponse, +): response is ShieldPromptDefaultResponse; +export function isUnexpected( + response: + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse, +): response is DetectTextProtectedMaterialDefaultResponse; export function isUnexpected( response: GetTextBlocklist200Response | GetTextBlocklistDefaultResponse, ): response is GetTextBlocklistDefaultResponse; @@ -60,23 +76,35 @@ export function isUnexpected( response: ListTextBlocklists200Response | ListTextBlocklistsDefaultResponse, ): response is ListTextBlocklistsDefaultResponse; export function isUnexpected( - response: AddOrUpdateBlocklistItems200Response | AddOrUpdateBlocklistItemsDefaultResponse, + response: + | AddOrUpdateBlocklistItems200Response + | AddOrUpdateBlocklistItemsDefaultResponse, ): response is AddOrUpdateBlocklistItemsDefaultResponse; export function isUnexpected( - response: RemoveBlocklistItems204Response | RemoveBlocklistItemsDefaultResponse, + response: + | RemoveBlocklistItems204Response + | RemoveBlocklistItemsDefaultResponse, ): response is RemoveBlocklistItemsDefaultResponse; export function isUnexpected( - response: GetTextBlocklistItem200Response | GetTextBlocklistItemDefaultResponse, + response: + | GetTextBlocklistItem200Response + | GetTextBlocklistItemDefaultResponse, ): response is GetTextBlocklistItemDefaultResponse; export function isUnexpected( - response: ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse, + response: + | ListTextBlocklistItems200Response + | ListTextBlocklistItemsDefaultResponse, ): response is ListTextBlocklistItemsDefaultResponse; export function isUnexpected( response: - | AnalyzeText200Response - | AnalyzeTextDefaultResponse | AnalyzeImage200Response | AnalyzeImageDefaultResponse + | AnalyzeText200Response + | AnalyzeTextDefaultResponse + | ShieldPrompt200Response + | ShieldPromptDefaultResponse + | DetectTextProtectedMaterial200Response + | DetectTextProtectedMaterialDefaultResponse | GetTextBlocklist200Response | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklist200Response @@ -95,8 +123,10 @@ export function isUnexpected( | ListTextBlocklistItems200Response | ListTextBlocklistItemsDefaultResponse, ): response is - | AnalyzeTextDefaultResponse | AnalyzeImageDefaultResponse + | AnalyzeTextDefaultResponse + | ShieldPromptDefaultResponse + | DetectTextProtectedMaterialDefaultResponse | GetTextBlocklistDefaultResponse | CreateOrUpdateTextBlocklistDefaultResponse | DeleteTextBlocklistDefaultResponse @@ -137,17 +167,24 @@ function getParametrizedPathSuccess(method: string, path: string): string[] { // track if we have found a match to return the values found. let found = true; - for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) { - if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) { + for ( + let i = candidateParts.length - 1, j = pathParts.length - 1; + i >= 1 && j >= 1; + i--, j-- + ) { + if ( + candidateParts[i]?.startsWith("{") && + candidateParts[i]?.indexOf("}") !== -1 + ) { const start = candidateParts[i]!.indexOf("}") + 1, end = candidateParts[i]?.length; // If the current part of the candidate is a "template" part // Try to use the suffix of pattern to match the path // {guid} ==> $ // {guid}:export ==> :export$ - const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test( - pathParts[j] || "", - ); + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}`, + ).test(pathParts[j] || ""); if (!isMatched) { found = false; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/models.ts b/sdk/contentsafety/ai-content-safety-rest/src/models.ts index f3368faf30b4..3eac39d39403 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/models.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/models.ts @@ -1,36 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/** The text analysis request. */ -export interface AnalyzeTextOptions { - /** The text needs to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request. */ - text: string; - /** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */ - categories?: string[]; - /** The names of blocklists. */ - blocklistNames?: string[]; - /** When set to true, further analyses of harmful content will not be performed in cases where blocklists are hit. When set to false, all analyses of harmful content will be performed, whether or not blocklists are hit. */ - haltOnBlocklistHit?: boolean; - /** - * This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels". - * - * Possible values: FourSeverityLevels, EightSeverityLevels - */ - outputType?: string; -} - /** The image analysis request. */ export interface AnalyzeImageOptions { - /** The image needs to be analyzed. */ + /** The image to be analyzed. */ image: ImageData; /** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */ - categories?: string[]; + categories?: ImageCategory[]; /** * This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". * - * Possible values: FourSeverityLevels + * Possible values: "FourSeverityLevels" */ - outputType?: string; + outputType?: AnalyzeImageOutputType; } /** The image can be either base64 encoded bytes or a blob URL. You can choose only one of these options. If both are provided, the request will be refused. The maximum image size is 2048 x 2048 pixels and should not exceed 4 MB, while the minimum image size is 50 x 50 pixels. */ @@ -41,6 +23,38 @@ export interface ImageData { blobUrl?: string; } +/** The text analysis request. */ +export interface AnalyzeTextOptions { + /** The text to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request. */ + text: string; + /** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */ + categories?: TextCategory[]; + /** The names of blocklists. */ + blocklistNames?: string[]; + /** When set to true, further analyses of harmful content will not be performed in cases where blocklists are hit. When set to false, all analyses of harmful content will be performed, whether or not blocklists are hit. */ + haltOnBlocklistHit?: boolean; + /** + * This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels". + * + * Possible values: "FourSeverityLevels", "EightSeverityLevels" + */ + outputType?: AnalyzeTextOutputType; +} + +/** The request of analyzing potential direct or indirect injection attacks. */ +export interface ShieldPromptOptions { + /** The user prompt to be analyzed, which may contain direct injection attacks. */ + userPrompt?: string; + /** The documents to be analyzed, which may contain direct or indirect injection attacks. */ + documents?: string[]; +} + +/** The request of detecting potential protected material present in the given text. */ +export interface DetectTextProtectedMaterialOptions { + /** The text to be analyzed, which may contain protected material. The characters will be counted in Unicode code points. */ + text: string; +} + /** Text Blocklist. */ export interface TextBlocklist { /** Text blocklist name. */ @@ -59,8 +73,10 @@ export interface AddOrUpdateTextBlocklistItemsOptions { export interface TextBlocklistItem { /** BlocklistItem description. */ description?: string; - /** BlocklistItem content. */ + /** BlocklistItem content. The length is counted using Unicode code point. */ text: string; + /** An optional properties indicating whether this item is to be matched as a regular expression. */ + isRegex?: boolean; } /** The request to remove blocklistItems from a text blocklist. */ @@ -68,3 +84,12 @@ export interface RemoveTextBlocklistItemsOptions { /** Array of blocklistItemIds to remove. */ blocklistItemIds: string[]; } + +/** Alias for ImageCategory */ +export type ImageCategory = string; +/** Alias for AnalyzeImageOutputType */ +export type AnalyzeImageOutputType = string; +/** Alias for TextCategory */ +export type TextCategory = string; +/** Alias for AnalyzeTextOutputType */ +export type AnalyzeTextOutputType = string; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts index ac215a7b18fa..2ea466667730 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/outputModels.ts @@ -3,22 +3,22 @@ import { Paged } from "@azure/core-paging"; -/** The text analysis request. */ -export interface AnalyzeTextOptionsOutput { - /** The text needs to be analyzed. We support a maximum of 10k Unicode characters (Unicode code points) in the text of one request. */ - text: string; - /** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */ - categories?: string[]; - /** The names of blocklists. */ - blocklistNames?: string[]; - /** When set to true, further analyses of harmful content will not be performed in cases where blocklists are hit. When set to false, all analyses of harmful content will be performed, whether or not blocklists are hit. */ - haltOnBlocklistHit?: boolean; +/** The image analysis response. */ +export interface AnalyzeImageResultOutput { + /** Analysis result for categories. */ + categoriesAnalysis: Array; +} + +/** Image analysis result. */ +export interface ImageCategoriesAnalysisOutput { /** - * This refers to the type of text analysis output. If no value is assigned, the default value will be "FourSeverityLevels". + * The image analysis category. * - * Possible values: FourSeverityLevels, EightSeverityLevels + * Possible values: "Hate", "SelfHarm", "Sexual", "Violence" */ - outputType?: string; + category: ImageCategoryOutput; + /** The value increases with the severity of the input content. The value of this field is determined by the output type specified in the request. The output type could be ‘FourSeverityLevels’, and the output value can be 0, 2, 4, 6. */ + severity?: number; } /** The text analysis response. */ @@ -44,51 +44,43 @@ export interface TextCategoriesAnalysisOutput { /** * The text analysis category. * - * Possible values: Hate, SelfHarm, Sexual, Violence + * Possible values: "Hate", "SelfHarm", "Sexual", "Violence" */ - category: string; + category: TextCategoryOutput; /** The value increases with the severity of the input content. The value of this field is determined by the output type specified in the request. The output type could be ‘FourSeverityLevels’ or ‘EightSeverity Levels’, and the output value can be 0, 2, 4, 6 or 0, 1, 2, 3, 4, 5, 6, or 7. */ severity?: number; } -/** The image analysis request. */ -export interface AnalyzeImageOptionsOutput { - /** The image needs to be analyzed. */ - image: ImageDataOutput; - /** The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned. */ - categories?: string[]; - /** - * This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels". - * - * Possible values: FourSeverityLevels - */ - outputType?: string; +/** The combined analysis results of potential direct or indirect injection attacks. */ +export interface ShieldPromptResultOutput { + /** Direct injection attacks analysis result for the given user prompt. */ + userPromptAnalysis?: UserPromptInjectionAnalysisResultOutput; + /** Direct and indirect injection attacks analysis result for the given documents. */ + documentsAnalysis?: Array; } -/** The image can be either base64 encoded bytes or a blob URL. You can choose only one of these options. If both are provided, the request will be refused. The maximum image size is 2048 x 2048 pixels and should not exceed 4 MB, while the minimum image size is 50 x 50 pixels. */ -export interface ImageDataOutput { - /** The Base64 encoding of the image. */ - content?: string; - /** The blob url of the image. */ - blobUrl?: string; +/** The individual analysis result of potential injection attacks in the given user prompt. */ +export interface UserPromptInjectionAnalysisResultOutput { + /** Whether a potential injection attack is detected or not. */ + attackDetected: boolean; } -/** The image analysis response. */ -export interface AnalyzeImageResultOutput { - /** Analysis result for categories. */ - categoriesAnalysis: Array; +/** The individual analysis result of potential injection attacks in the given documents. */ +export interface DocumentInjectionAnalysisResultOutput { + /** Whether a potential injection attack is detected or not. */ + attackDetected: boolean; } -/** Image analysis result. */ -export interface ImageCategoriesAnalysisOutput { - /** - * The image analysis category. - * - * Possible values: Hate, SelfHarm, Sexual, Violence - */ - category: string; - /** The value increases with the severity of the input content. The value of this field is determined by the output type specified in the request. The output type could be ‘FourSeverityLevels’, and the output value can be 0, 2, 4, 6. */ - severity?: number; +/** The combined detection results of potential protected material. */ +export interface DetectTextProtectedMaterialResultOutput { + /** Analysis result for the given text. */ + protectedMaterialAnalysis: TextProtectedMaterialAnalysisResultOutput; +} + +/** The individual detection result of potential protected material. */ +export interface TextProtectedMaterialAnalysisResultOutput { + /** Whether potential protected material is detected or not. */ + detected: boolean; } /** Text Blocklist. */ @@ -105,8 +97,10 @@ export interface TextBlocklistItemOutput { readonly blocklistItemId: string; /** BlocklistItem description. */ description?: string; - /** BlocklistItem content. */ + /** BlocklistItem content. The length is counted using Unicode code point. */ text: string; + /** An optional properties indicating whether this item is to be matched as a regular expression. */ + isRegex?: boolean; } /** The response of adding blocklistItems to the text blocklist. */ @@ -115,6 +109,10 @@ export interface AddOrUpdateTextBlocklistItemsResultOutput { blocklistItems: Array; } +/** Alias for ImageCategoryOutput */ +export type ImageCategoryOutput = string; +/** Alias for TextCategoryOutput */ +export type TextCategoryOutput = string; /** Paged collection of TextBlocklist items */ export type PagedTextBlocklistOutput = Paged; /** Paged collection of TextBlocklistItem items */ diff --git a/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts b/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts index f0d91c952cda..3aac141db0e7 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/paginateHelper.ts @@ -1,8 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getPagedAsyncIterator, PagedAsyncIterableIterator, PagedResult } from "@azure/core-paging"; -import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; +import { + getPagedAsyncIterator, + PagedAsyncIterableIterator, + PagedResult, +} from "@azure/core-paging"; +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; /** * Helper type to extract the type of an array @@ -67,7 +75,9 @@ export function paginate( typeof customGetPage === "function" ? customGetPage : async (pageLink: string) => { - const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get(); + const result = firstRun + ? initialResponse + : await client.pathUnchecked(pageLink).get(); firstRun = false; checkPagingRequest(result); const nextLink = getNextLink(result.body, nextLinkName); @@ -93,7 +103,9 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; if (typeof nextLink !== "string" && typeof nextLink !== "undefined") { - throw new Error(`Body Property ${nextLinkName} should be a string or undefined`); + throw new Error( + `Body Property ${nextLinkName} should be a string or undefined`, + ); } return nextLink; @@ -121,7 +133,18 @@ function getElements(body: unknown, itemName: string): T[] { * Checks if a request failed */ function checkPagingRequest(response: PathUncheckedResponse): void { - const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"]; + const Http2xxStatusCodes = [ + "200", + "201", + "202", + "203", + "204", + "205", + "206", + "207", + "208", + "226", + ]; if (!Http2xxStatusCodes.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts index 85a8b04c5d7f..1ae56537ec78 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/parameters.ts @@ -3,12 +3,21 @@ import { RequestParameters } from "@azure-rest/core-client"; import { - AnalyzeTextOptions, AnalyzeImageOptions, + AnalyzeTextOptions, + ShieldPromptOptions, + DetectTextProtectedMaterialOptions, TextBlocklist, AddOrUpdateTextBlocklistItemsOptions, RemoveTextBlocklistItemsOptions, -} from "./models"; +} from "./models.js"; + +export interface AnalyzeImageBodyParam { + /** The image analysis request. */ + body: AnalyzeImageOptions; +} + +export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters; export interface AnalyzeTextBodyParam { /** The text analysis request. */ @@ -17,12 +26,20 @@ export interface AnalyzeTextBodyParam { export type AnalyzeTextParameters = AnalyzeTextBodyParam & RequestParameters; -export interface AnalyzeImageBodyParam { - /** The image analysis request. */ - body: AnalyzeImageOptions; +export interface ShieldPromptBodyParam { + /** The request body to be detected, which may contain direct or indirect injection attacks. */ + body: ShieldPromptOptions; } -export type AnalyzeImageParameters = AnalyzeImageBodyParam & RequestParameters; +export type ShieldPromptParameters = ShieldPromptBodyParam & RequestParameters; + +export interface DetectTextProtectedMaterialBodyParam { + /** The request body to be detected, which may contain protected material. */ + body: DetectTextProtectedMaterialOptions; +} + +export type DetectTextProtectedMaterialParameters = + DetectTextProtectedMaterialBodyParam & RequestParameters; export type GetTextBlocklistParameters = RequestParameters; /** The resource instance. */ export type TextBlocklistResourceMergeAndPatch = Partial; @@ -37,9 +54,10 @@ export interface CreateOrUpdateTextBlocklistMediaTypesParam { contentType: "application/merge-patch+json"; } -export type CreateOrUpdateTextBlocklistParameters = CreateOrUpdateTextBlocklistMediaTypesParam & - CreateOrUpdateTextBlocklistBodyParam & - RequestParameters; +export type CreateOrUpdateTextBlocklistParameters = + CreateOrUpdateTextBlocklistMediaTypesParam & + CreateOrUpdateTextBlocklistBodyParam & + RequestParameters; export type DeleteTextBlocklistParameters = RequestParameters; export type ListTextBlocklistsParameters = RequestParameters; @@ -48,15 +66,16 @@ export interface AddOrUpdateBlocklistItemsBodyParam { body: AddOrUpdateTextBlocklistItemsOptions; } -export type AddOrUpdateBlocklistItemsParameters = AddOrUpdateBlocklistItemsBodyParam & - RequestParameters; +export type AddOrUpdateBlocklistItemsParameters = + AddOrUpdateBlocklistItemsBodyParam & RequestParameters; export interface RemoveBlocklistItemsBodyParam { /** Options for removing blocklist items. */ body: RemoveTextBlocklistItemsOptions; } -export type RemoveBlocklistItemsParameters = RemoveBlocklistItemsBodyParam & RequestParameters; +export type RemoveBlocklistItemsParameters = RemoveBlocklistItemsBodyParam & + RequestParameters; export type GetTextBlocklistItemParameters = RequestParameters; export interface ListTextBlocklistItemsQueryParamProperties { @@ -72,4 +91,5 @@ export interface ListTextBlocklistItemsQueryParam { queryParameters?: ListTextBlocklistItemsQueryParamProperties; } -export type ListTextBlocklistItemsParameters = ListTextBlocklistItemsQueryParam & RequestParameters; +export type ListTextBlocklistItemsParameters = + ListTextBlocklistItemsQueryParam & RequestParameters; diff --git a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts index fb92d26ddc33..e126778be921 100644 --- a/sdk/contentsafety/ai-content-safety-rest/src/responses.ts +++ b/sdk/contentsafety/ai-content-safety-rest/src/responses.ts @@ -4,14 +4,33 @@ import { RawHttpHeaders } from "@azure/core-rest-pipeline"; import { HttpResponse, ErrorResponse } from "@azure-rest/core-client"; import { - AnalyzeTextResultOutput, AnalyzeImageResultOutput, + AnalyzeTextResultOutput, + ShieldPromptResultOutput, + DetectTextProtectedMaterialResultOutput, TextBlocklistOutput, PagedTextBlocklistOutput, AddOrUpdateTextBlocklistItemsResultOutput, TextBlocklistItemOutput, PagedTextBlocklistItemOutput, -} from "./outputModels"; +} from "./outputModels.js"; + +/** The request has succeeded. */ +export interface AnalyzeImage200Response extends HttpResponse { + status: "200"; + body: AnalyzeImageResultOutput; +} + +export interface AnalyzeImageDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface AnalyzeImageDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & AnalyzeImageDefaultHeaders; +} /** The request has succeeded. */ export interface AnalyzeText200Response extends HttpResponse { @@ -31,20 +50,38 @@ export interface AnalyzeTextDefaultResponse extends HttpResponse { } /** The request has succeeded. */ -export interface AnalyzeImage200Response extends HttpResponse { +export interface ShieldPrompt200Response extends HttpResponse { status: "200"; - body: AnalyzeImageResultOutput; + body: ShieldPromptResultOutput; } -export interface AnalyzeImageDefaultHeaders { +export interface ShieldPromptDefaultHeaders { /** String error code indicating what went wrong. */ "x-ms-error-code"?: string; } -export interface AnalyzeImageDefaultResponse extends HttpResponse { +export interface ShieldPromptDefaultResponse extends HttpResponse { status: string; body: ErrorResponse; - headers: RawHttpHeaders & AnalyzeImageDefaultHeaders; + headers: RawHttpHeaders & ShieldPromptDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DetectTextProtectedMaterial200Response extends HttpResponse { + status: "200"; + body: DetectTextProtectedMaterialResultOutput; +} + +export interface DetectTextProtectedMaterialDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DetectTextProtectedMaterialDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DetectTextProtectedMaterialDefaultHeaders; } /** The request has succeeded. */ @@ -81,7 +118,8 @@ export interface CreateOrUpdateTextBlocklistDefaultHeaders { "x-ms-error-code"?: string; } -export interface CreateOrUpdateTextBlocklistDefaultResponse extends HttpResponse { +export interface CreateOrUpdateTextBlocklistDefaultResponse + extends HttpResponse { status: string; body: ErrorResponse; headers: RawHttpHeaders & CreateOrUpdateTextBlocklistDefaultHeaders; diff --git a/sdk/contentsafety/ai-content-safety-rest/test/public/sampleTest.spec.ts b/sdk/contentsafety/ai-content-safety-rest/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..344657d6f17e --- /dev/null +++ b/sdk/contentsafety/ai-content-safety-rest/test/public/sampleTest.spec.ts @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createRecorder } from "./utils/recordedClient.js"; +import { assert, beforeEach, afterEach, it, describe } from "vitest"; + +describe("My test", () => { + // let recorder: Recorder; + + beforeEach(async function () { + // recorder = await createRecorder(this); + }); + + afterEach(async function () { + // await recorder.stop(); + }); + + it("sample test", async function () { + assert.equal(1, 1); + }); +}); diff --git a/sdk/contentsafety/ai-content-safety-rest/test/public/utils/recordedClient.ts b/sdk/contentsafety/ai-content-safety-rest/test/public/utils/recordedClient.ts index a43c2b63996e..a4d8acf86259 100644 --- a/sdk/contentsafety/ai-content-safety-rest/test/public/utils/recordedClient.ts +++ b/sdk/contentsafety/ai-content-safety-rest/test/public/utils/recordedClient.ts @@ -1,24 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Context } from "mocha"; import { Recorder, RecorderStartOptions, - assertEnvironmentVariable, + VitestTestContext, } from "@azure-tools/test-recorder"; -import "./env"; -import ContentSafety, { ContentSafetyClient } from "../../../src"; -import { AzureKeyCredential } from "@azure/core-auth"; -// import { ClientOptions } from "@azure-rest/core-client"; -const envSetupForPlayback: Record = { - CONTENT_SAFETY_ENDPOINT: "https://endpoint/", - CONTENT_SAFETY_API_KEY: "fake_key", +const replaceableVariables: Record = { + SUBSCRIPTION_ID: "azure_subscription_id", }; const recorderEnvSetup: RecorderStartOptions = { - envSetupForPlayback, + envSetupForPlayback: replaceableVariables, }; /** @@ -26,16 +20,10 @@ const recorderEnvSetup: RecorderStartOptions = { * Should be called first in the test suite to make sure environment variables are * read before they are being used. */ -export async function createRecorder(context: Context): Promise { - const recorder = new Recorder(context.currentTest); +export async function createRecorder( + context: VitestTestContext, +): Promise { + const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; } - -export function createClient(recorder: Recorder): ContentSafetyClient { - const endpoint = assertEnvironmentVariable("CONTENT_SAFETY_ENDPOINT"); - const key = assertEnvironmentVariable("CONTENT_SAFETY_API_KEY"); - const credential = new AzureKeyCredential(key); - const client = ContentSafety(endpoint, credential, recorder.configureClientOptions({})); - return client; -} diff --git a/sdk/contentsafety/ai-content-safety-rest/tsconfig.json b/sdk/contentsafety/ai-content-safety-rest/tsconfig.json index 63e57f77f784..3f36ef1bed9f 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsconfig.json +++ b/sdk/contentsafety/ai-content-safety-rest/tsconfig.json @@ -3,10 +3,19 @@ "compilerOptions": { "outDir": "./dist-esm", "declarationDir": "./types", - "lib": ["es6", "dom"], + "lib": [ + "es6", + "dom" + ], "paths": { - "@azure-rest/ai-content-safety": ["./src/index"] + "@azure-rest/ai-content-safety": [ + "./src/index" + ] } }, - "include": ["src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] -} + "include": [ + "src/**/*.ts", + "./test/**/*.ts", + "samples-dev/**/*.ts" + ] +} \ No newline at end of file diff --git a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml index 9d47983f6b57..64d4ed16b26b 100644 --- a/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml +++ b/sdk/contentsafety/ai-content-safety-rest/tsp-location.yaml @@ -1,3 +1,5 @@ -directory: specification/cognitiveservices/ContentSafety repo: Azure/azure-rest-api-specs -commit: 164375e67a1bffb207bcf603772c289dbe42d7b5 +commit: 274e6bec630de1762940d0f33adf105db3e42ebe +directory: specification/cognitiveservices/ContentSafety +additionalDirectories: [] +