diff --git a/sdk/translation/ai-translation-document-rest/package.json b/sdk/translation/ai-translation-document-rest/package.json index 51da48ebafb7..3784c98c3818 100644 --- a/sdk/translation/ai-translation-document-rest/package.json +++ b/sdk/translation/ai-translation-document-rest/package.json @@ -48,12 +48,12 @@ "dependencies": { "@azure/core-rest-pipeline": "^1.8.0", "@azure/logger": "^1.0.0", - "@azure/core-paging": "^1.2.0", + "@azure/core-paging": "^1.5.0", "@azure-rest/core-client": "^2.0.0", "@azure/core-auth": "^1.6.0", "tslib": "^2.6.2", - "@azure/core-lro": "3.0.0-beta.1", - "@azure/abort-controller": "^2.0.0" + "@azure/core-lro": "^3.0.0", + "@azure/abort-controller": "^2.1.2" }, "devDependencies": { "@azure/storage-blob": "^12.23.0", diff --git a/sdk/translation/ai-translation-document-rest/review/ai-translation-document.api.md b/sdk/translation/ai-translation-document-rest/review/ai-translation-document.api.md index fc4be2bced16..7912358013cb 100644 --- a/sdk/translation/ai-translation-document-rest/review/ai-translation-document.api.md +++ b/sdk/translation/ai-translation-document-rest/review/ai-translation-document.api.md @@ -8,10 +8,6 @@ import { AbortSignalLike } from '@azure/abort-controller'; import { CancelOnProgress } from '@azure/core-lro'; import { Client } from '@azure-rest/core-client'; import { ClientOptions } from '@azure-rest/core-client'; -import { createFile } from '@azure/core-rest-pipeline'; -import { createFileFromStream } from '@azure/core-rest-pipeline'; -import { CreateFileFromStreamOptions } from '@azure/core-rest-pipeline'; -import { CreateFileOptions } from '@azure/core-rest-pipeline'; import { CreateHttpPollerOptions } from '@azure/core-lro'; import { ErrorResponse } from '@azure-rest/core-client'; import { HttpResponse } from '@azure-rest/core-client'; @@ -59,17 +55,9 @@ export interface CancelTranslationDefaultResponse extends HttpResponse { export type CancelTranslationParameters = RequestParameters; // @public -function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): DocumentTranslationClient; +function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, { apiVersion, ...options }?: DocumentTranslationClientOptions): DocumentTranslationClient; export default createClient; -export { createFile } - -export { createFileFromStream } - -export { CreateFileFromStreamOptions } - -export { CreateFileOptions } - // @public export interface DocumentFilter { prefix?: string; @@ -103,6 +91,7 @@ export interface DocumentTranslate { // @public (undocumented) export interface DocumentTranslate200Headers { + "content-type": "application/octet-stream"; "x-ms-client-request-id"?: string; } @@ -117,8 +106,7 @@ export interface DocumentTranslate200Response extends HttpResponse { // @public (undocumented) export interface DocumentTranslateBodyParam { - // (undocumented) - body?: DocumentTranslateContent; + body: DocumentTranslateContent; } // @public @@ -201,6 +189,11 @@ export type DocumentTranslationClient = Client & { path: Routes; }; +// @public +export interface DocumentTranslationClientOptions extends ClientOptions { + apiVersion?: string; +} + // @public export interface FileFormatOutput { contentTypes: string[]; @@ -212,7 +205,7 @@ export interface FileFormatOutput { } // @public -export type FileFormatType = "document" | "glossary" | string; +export type FileFormatType = string; // @public export type GetArrayType = T extends Array ? TData : never; @@ -494,6 +487,7 @@ export interface SimplePollerLike, TResul getOperationState(): TState; getResult(): TResult | undefined; isDone(): boolean; + // @deprecated isStopped(): boolean; onProgress(callback: (state: TState) => void): CancelOnProgress; poll(options?: { @@ -521,7 +515,7 @@ export interface SourceInput { // @public (undocumented) export interface StartTranslation { get(options?: GetTranslationsStatusParameters): StreamableMethod; - post(options?: StartTranslationParameters): StreamableMethod; + post(options: StartTranslationParameters): StreamableMethod; } // @public (undocumented) @@ -539,8 +533,7 @@ export interface StartTranslation202Response extends HttpResponse { // @public (undocumented) export interface StartTranslationBodyParam { - // (undocumented) - body?: StartTranslationDetails; + body: StartTranslationDetails; } // @public (undocumented) @@ -573,7 +566,7 @@ export interface StartTranslationLogicalResponse extends HttpResponse { export type StartTranslationParameters = StartTranslationBodyParam & RequestParameters; // @public -export type StatusOutput = "NotStarted" | "Running" | "Succeeded" | "Failed" | "Cancelled" | "Cancelling" | "ValidationFailed" | string; +export type StatusOutput = string; // @public export interface StatusSummaryOutput { @@ -587,10 +580,10 @@ export interface StatusSummaryOutput { } // @public -export type StorageInputType = "Folder" | "File" | string; +export type StorageInputType = string; // @public -export type StorageSource = "AzureBlob" | string; +export type StorageSource = string; // @public export interface SupportedFileFormatsOutput { @@ -607,7 +600,7 @@ export interface TargetInput { } // @public -export type TranslationErrorCodeOutput = "InvalidRequest" | "InvalidArgument" | "InternalServerError" | "ServiceUnavailable" | "ResourceNotFound" | "Unauthorized" | "RequestRateTooHigh" | string; +export type TranslationErrorCodeOutput = string; // @public export interface TranslationErrorOutput { diff --git a/sdk/translation/ai-translation-document-rest/src/clientDefinitions.ts b/sdk/translation/ai-translation-document-rest/src/clientDefinitions.ts index a22d60d72914..0537002de237 100644 --- a/sdk/translation/ai-translation-document-rest/src/clientDefinitions.ts +++ b/sdk/translation/ai-translation-document-rest/src/clientDefinitions.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { DocumentTranslateParameters, StartTranslationParameters, @@ -61,7 +64,7 @@ export interface StartTranslation { * must be unique. */ post( - options?: StartTranslationParameters, + options: StartTranslationParameters, ): StreamableMethod; /** * Returns a list of batch requests submitted and the status for each diff --git a/sdk/translation/ai-translation-document-rest/src/documentTranslationClient.ts b/sdk/translation/ai-translation-document-rest/src/documentTranslationClient.ts index 6a4ac1257c61..a5ff5e05a896 100644 --- a/sdk/translation/ai-translation-document-rest/src/documentTranslationClient.ts +++ b/sdk/translation/ai-translation-document-rest/src/documentTranslationClient.ts @@ -1,11 +1,20 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger"; import { TokenCredential, KeyCredential } from "@azure/core-auth"; import { DocumentTranslationClient } from "./clientDefinitions"; +/** The optional parameters for the client */ +export interface DocumentTranslationClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `DocumentTranslationClient` * @param endpointParam - Supported document Translation endpoint, protocol and hostname, for example: https://{TranslatorResourceName}.cognitiveservices.azure.com/translator. @@ -15,11 +24,10 @@ import { DocumentTranslationClient } from "./clientDefinitions"; export default function createClient( endpointParam: string, credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + { apiVersion = "2024-05-01", ...options }: DocumentTranslationClientOptions = {}, ): DocumentTranslationClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/translator`; - options.apiVersion = options.apiVersion ?? "2024-05-01"; - const userAgentInfo = `azsdk-js-ai-translation-document-rest/1.0.0-beta.2`; + const userAgentInfo = `azsdk-js-ai-translation-document-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` @@ -37,8 +45,24 @@ export default function createClient( apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; - const client = getClient(endpointUrl, credentials, options) as DocumentTranslationClient; + 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/translation/ai-translation-document-rest/src/index.ts b/sdk/translation/ai-translation-document-rest/src/index.ts index 18dea894bf91..d93097620d82 100644 --- a/sdk/translation/ai-translation-document-rest/src/index.ts +++ b/sdk/translation/ai-translation-document-rest/src/index.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import DocumentTranslationClient from "./documentTranslationClient"; export * from "./documentTranslationClient"; @@ -12,11 +15,5 @@ export * from "./models"; export * from "./outputModels"; export * from "./paginateHelper"; export * from "./pollingHelper"; -export { - createFile, - createFileFromStream, - type CreateFileOptions, - type CreateFileFromStreamOptions, -} from "@azure/core-rest-pipeline"; export default DocumentTranslationClient; diff --git a/sdk/translation/ai-translation-document-rest/src/isUnexpected.ts b/sdk/translation/ai-translation-document-rest/src/isUnexpected.ts index 8895255f070e..e14648bc9c1f 100644 --- a/sdk/translation/ai-translation-document-rest/src/isUnexpected.ts +++ b/sdk/translation/ai-translation-document-rest/src/isUnexpected.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { DocumentTranslate200Response, DocumentTranslateDefaultResponse, diff --git a/sdk/translation/ai-translation-document-rest/src/logger.ts b/sdk/translation/ai-translation-document-rest/src/logger.ts index 0d6fc077f63f..d08ff659f155 100644 --- a/sdk/translation/ai-translation-document-rest/src/logger.ts +++ b/sdk/translation/ai-translation-document-rest/src/logger.ts @@ -1,5 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { createClientLogger } from "@azure/logger"; export const logger = createClientLogger("ai-translation-document"); diff --git a/sdk/translation/ai-translation-document-rest/src/models.ts b/sdk/translation/ai-translation-document-rest/src/models.ts index f7c05d3d49b7..db7ce7ad13b7 100644 --- a/sdk/translation/ai-translation-document-rest/src/models.ts +++ b/sdk/translation/ai-translation-document-rest/src/models.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + export interface DocumentTranslateContentDocumentPartDescriptor { name: "document"; body: string | Uint8Array | ReadableStream | NodeJS.ReadableStream | File; @@ -27,7 +30,11 @@ export interface BatchRequest { source: SourceInput; /** Location of the destination for the output */ targets: Array; - /** Storage type of the input documents source string */ + /** + * Storage type of the input documents source string + * + * Possible values: "Folder", "File" + */ storageType?: StorageInputType; } @@ -42,7 +49,11 @@ export interface SourceInput { * If none is specified, we will perform auto detect on the document */ language?: string; - /** Storage Source */ + /** + * Storage Source + * + * Possible values: "AzureBlob" + */ storageSource?: StorageSource; } @@ -73,7 +84,11 @@ export interface TargetInput { language: string; /** List of Glossary */ glossaries?: Array; - /** Storage Source */ + /** + * Storage Source + * + * Possible values: "AzureBlob" + */ storageSource?: StorageSource; } @@ -92,7 +107,11 @@ export interface Glossary { format: string; /** Optional Version. If not specified, default is used. */ version?: string; - /** Storage Source */ + /** + * Storage Source + * + * Possible values: "AzureBlob" + */ storageSource?: StorageSource; } @@ -104,8 +123,8 @@ export type DocumentTranslateContent = | DocumentTranslateContentGlossaryPartDescriptor >; /** Alias for StorageSource */ -export type StorageSource = "AzureBlob" | string; +export type StorageSource = string; /** Alias for StorageInputType */ -export type StorageInputType = "Folder" | "File" | string; +export type StorageInputType = string; /** Alias for FileFormatType */ -export type FileFormatType = "document" | "glossary" | string; +export type FileFormatType = string; diff --git a/sdk/translation/ai-translation-document-rest/src/outputModels.ts b/sdk/translation/ai-translation-document-rest/src/outputModels.ts index d4b38b596f78..1b4a84572f72 100644 --- a/sdk/translation/ai-translation-document-rest/src/outputModels.ts +++ b/sdk/translation/ai-translation-document-rest/src/outputModels.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /** Translation job Status Response */ export interface TranslationsStatusOutput { /** The summary status of individual operation */ @@ -17,7 +20,11 @@ export interface TranslationStatusOutput { createdDateTimeUtc: string; /** Date time in which the operation's status has been updated */ lastActionDateTimeUtc: string; - /** List of possible statuses for job or document */ + /** + * List of possible statuses for job or document + * + * Possible values: "NotStarted", "Running", "Succeeded", "Failed", "Cancelled", "Cancelling", "ValidationFailed" + */ status: StatusOutput; /** * This contains an outer error with error code, message, details, target and an @@ -33,7 +40,11 @@ export interface TranslationStatusOutput { * inner error with more descriptive details. */ export interface TranslationErrorOutput { - /** Enums containing high level error codes. */ + /** + * Enums containing high level error codes. + * + * Possible values: "InvalidRequest", "InvalidArgument", "InternalServerError", "ServiceUnavailable", "ResourceNotFound", "Unauthorized", "RequestRateTooHigh" + */ code: TranslationErrorCodeOutput; /** Gets high level error message. */ message: string; @@ -112,7 +123,11 @@ export interface DocumentStatusOutput { createdDateTimeUtc: string; /** Date time in which the operation's status has been updated */ lastActionDateTimeUtc: string; - /** List of possible statuses for job or document */ + /** + * List of possible statuses for job or document + * + * Possible values: "NotStarted", "Running", "Succeeded", "Failed", "Cancelled", "Cancelling", "ValidationFailed" + */ status: StatusOutput; /** To language */ to: string; @@ -160,22 +175,6 @@ export interface FileFormatOutput { } /** Alias for StatusOutput */ -export type StatusOutput = - | "NotStarted" - | "Running" - | "Succeeded" - | "Failed" - | "Cancelled" - | "Cancelling" - | "ValidationFailed" - | string; +export type StatusOutput = string; /** Alias for TranslationErrorCodeOutput */ -export type TranslationErrorCodeOutput = - | "InvalidRequest" - | "InvalidArgument" - | "InternalServerError" - | "ServiceUnavailable" - | "ResourceNotFound" - | "Unauthorized" - | "RequestRateTooHigh" - | string; +export type TranslationErrorCodeOutput = string; diff --git a/sdk/translation/ai-translation-document-rest/src/paginateHelper.ts b/sdk/translation/ai-translation-document-rest/src/paginateHelper.ts index e27846d32a90..50bd3bbfed76 100644 --- a/sdk/translation/ai-translation-document-rest/src/paginateHelper.ts +++ b/sdk/translation/ai-translation-document-rest/src/paginateHelper.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// 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"; diff --git a/sdk/translation/ai-translation-document-rest/src/parameters.ts b/sdk/translation/ai-translation-document-rest/src/parameters.ts index 4c5d3eed021d..959347358014 100644 --- a/sdk/translation/ai-translation-document-rest/src/parameters.ts +++ b/sdk/translation/ai-translation-document-rest/src/parameters.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { RawHttpHeadersInput } from "@azure/core-rest-pipeline"; import { RequestParameters } from "@azure-rest/core-client"; import { DocumentTranslateContent, StartTranslationDetails, FileFormatType } from "./models.js"; @@ -11,7 +14,8 @@ export interface DocumentTranslateHeaders { } export interface DocumentTranslateBodyParam { - body?: DocumentTranslateContent; + /** Document Translate Request Content */ + body: DocumentTranslateContent; } export interface DocumentTranslateQueryParamProperties { @@ -60,7 +64,8 @@ export type DocumentTranslateParameters = DocumentTranslateQueryParam & RequestParameters; export interface StartTranslationBodyParam { - body?: StartTranslationDetails; + /** Translation job submission batch request */ + body: StartTranslationDetails; } export type StartTranslationParameters = StartTranslationBodyParam & RequestParameters; @@ -191,7 +196,11 @@ export interface GetDocumentsStatusQueryParam { export type GetDocumentsStatusParameters = GetDocumentsStatusQueryParam & RequestParameters; export interface GetSupportedFormatsQueryParamProperties { - /** the type of format like document or glossary */ + /** + * the type of format like document or glossary + * + * Possible values: "document", "glossary" + */ type?: FileFormatType; } diff --git a/sdk/translation/ai-translation-document-rest/src/pollingHelper.ts b/sdk/translation/ai-translation-document-rest/src/pollingHelper.ts index ea26a2f21d09..1497121c109c 100644 --- a/sdk/translation/ai-translation-document-rest/src/pollingHelper.ts +++ b/sdk/translation/ai-translation-document-rest/src/pollingHelper.ts @@ -1,12 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { Client, HttpResponse } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; import { CancelOnProgress, CreateHttpPollerOptions, - LongRunningOperation, + RunningOperation, OperationResponse, OperationState, createHttpPoller, @@ -25,10 +28,6 @@ export interface SimplePollerLike, TResul * Returns true if the poller has finished polling. */ isDone(): boolean; - /** - * Returns true if the poller is stopped. - */ - isStopped(): boolean; /** * Returns the state of the operation. */ @@ -79,6 +78,12 @@ export interface SimplePollerLike, TResul * @deprecated Use abortSignal to stop polling instead. */ stopPolling(): void; + + /** + * Returns true if the poller is stopped. + * @deprecated Use abortSignal status to track this instead. + */ + isStopped(): boolean; } /** @@ -101,14 +106,14 @@ export async function getLongRunningPoller( options: CreateHttpPollerOptions> = {}, ): Promise, TResult>> { const abortController = new AbortController(); - const poller: LongRunningOperation = { + const poller: RunningOperation = { sendInitialRequest: async () => { // In the case of Rest Clients we are building the LRO poller object from a response that's the reason // we are not triggering the initial request here, just extracting the information from the // response we were provided. return getLroResponse(initialResponse); }, - sendPollRequest: async (path, sendPollRequestOptions?: { abortSignal?: AbortSignalLike }) => { + sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => { // This is the callback that is going to be called to poll the service // to get the latest status. We use the client provided and the polling path // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location @@ -116,7 +121,7 @@ export async function getLongRunningPoller( function abortListener(): void { abortController.abort(); } - const inputAbortSignal = sendPollRequestOptions?.abortSignal; + const inputAbortSignal = pollOptions?.abortSignal; const abortSignal = abortController.signal; if (inputAbortSignal?.aborted) { abortController.abort(); @@ -146,7 +151,7 @@ export async function getLongRunningPoller( return httpPoller.isDone; }, isStopped() { - return httpPoller.isStopped; + return abortController.signal.aborted; }, getOperationState() { if (!httpPoller.operationState) { diff --git a/sdk/translation/ai-translation-document-rest/src/responses.ts b/sdk/translation/ai-translation-document-rest/src/responses.ts index 092076a87256..625cc8f018ae 100644 --- a/sdk/translation/ai-translation-document-rest/src/responses.ts +++ b/sdk/translation/ai-translation-document-rest/src/responses.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { RawHttpHeaders } from "@azure/core-rest-pipeline"; import { HttpResponse, ErrorResponse } from "@azure-rest/core-client"; import { @@ -14,6 +17,8 @@ import { export interface DocumentTranslate200Headers { /** An opaque, globally-unique, client-generated string identifier for the request. */ "x-ms-client-request-id"?: string; + /** response content type */ + "content-type": "application/octet-stream"; } /** The request has succeeded. */ diff --git a/sdk/translation/ai-translation-document-rest/tsp-location.yaml b/sdk/translation/ai-translation-document-rest/tsp-location.yaml index 2cac054a5f24..0a5b75888fd3 100644 --- a/sdk/translation/ai-translation-document-rest/tsp-location.yaml +++ b/sdk/translation/ai-translation-document-rest/tsp-location.yaml @@ -1,4 +1,4 @@ -commit: c27f2af6b7ffa0e2d966fc0926b9d19242f9f774 +commit: 27a9398801386caaba2df7e1a4d1a8abd19e3789 repo: Azure/azure-rest-api-specs directory: specification/translation/Azure.AI.DocumentTranslation