From 59b4b3004b6b0ead723135e6383a6a75926474d1 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Tue, 1 Apr 2025 17:59:06 +0000 Subject: [PATCH] CodeGen from PR 33631 in Azure/azure-rest-api-specs Merge d6090327997f45e3f1a66259173cf3c05d46f00b into 146de83bbf88ee10272170163b0449ce782a3433 --- .../ai-projects-1dp/src/clientDefinitions.ts | 258 ++++++++++++ sdk/ai/ai-projects-1dp/src/index.ts | 15 + sdk/ai/ai-projects-1dp/src/isUnexpected.ts | 276 +++++++++++++ sdk/ai/ai-projects-1dp/src/logger.ts | 5 + sdk/ai/ai-projects-1dp/src/models.ts | 110 +++++ sdk/ai/ai-projects-1dp/src/outputModels.ts | 243 +++++++++++ sdk/ai/ai-projects-1dp/src/paginateHelper.ts | 294 ++++++++++++++ sdk/ai/ai-projects-1dp/src/parameters.ts | 266 +++++++++++++ sdk/ai/ai-projects-1dp/src/projectsClient.ts | 80 ++++ sdk/ai/ai-projects-1dp/src/responses.ts | 376 ++++++++++++++++++ .../test/public/sampleTest.spec.ts | 21 + .../test/public/utils/recordedClient.ts | 29 ++ sdk/ai/ai-projects-1dp/tsp-location.yaml | 4 + 13 files changed, 1977 insertions(+) create mode 100644 sdk/ai/ai-projects-1dp/src/clientDefinitions.ts create mode 100644 sdk/ai/ai-projects-1dp/src/index.ts create mode 100644 sdk/ai/ai-projects-1dp/src/isUnexpected.ts create mode 100644 sdk/ai/ai-projects-1dp/src/logger.ts create mode 100644 sdk/ai/ai-projects-1dp/src/models.ts create mode 100644 sdk/ai/ai-projects-1dp/src/outputModels.ts create mode 100644 sdk/ai/ai-projects-1dp/src/paginateHelper.ts create mode 100644 sdk/ai/ai-projects-1dp/src/parameters.ts create mode 100644 sdk/ai/ai-projects-1dp/src/projectsClient.ts create mode 100644 sdk/ai/ai-projects-1dp/src/responses.ts create mode 100644 sdk/ai/ai-projects-1dp/test/public/sampleTest.spec.ts create mode 100644 sdk/ai/ai-projects-1dp/test/public/utils/recordedClient.ts create mode 100644 sdk/ai/ai-projects-1dp/tsp-location.yaml diff --git a/sdk/ai/ai-projects-1dp/src/clientDefinitions.ts b/sdk/ai/ai-projects-1dp/src/clientDefinitions.ts new file mode 100644 index 000000000000..613f35a7cdec --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/clientDefinitions.ts @@ -0,0 +1,258 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { + ConnectionsGetParameters, + ConnectionsListParameters, + DatasetsListVersionsParameters, + DatasetsCreateParameters, + DatasetsListLatestParameters, + DatasetsGetVersionParameters, + DatasetsDeleteVersionParameters, + DatasetsCreateVersionParameters, + DatasetsStartPendingUploadVersionParameters, + DatasetsStartPendingUploadParameters, + IndexesListVersionsParameters, + IndexesCreateParameters, + IndexesListLatestParameters, + IndexesGetVersionParameters, + IndexesDeleteVersionParameters, + IndexesCreateVersionParameters, + DeploymentsGetParameters, + DeploymentsListParameters, +} from "./parameters.js"; +import type { + ConnectionsGet200Response, + ConnectionsGetDefaultResponse, + ConnectionsList200Response, + ConnectionsListDefaultResponse, + DatasetsListVersions200Response, + DatasetsListVersionsDefaultResponse, + DatasetsCreate200Response, + DatasetsCreateDefaultResponse, + DatasetsListLatest200Response, + DatasetsListLatestDefaultResponse, + DatasetsGetVersion200Response, + DatasetsGetVersionDefaultResponse, + DatasetsDeleteVersion204Response, + DatasetsDeleteVersionDefaultResponse, + DatasetsCreateVersion200Response, + DatasetsCreateVersion201Response, + DatasetsCreateVersionDefaultResponse, + DatasetsStartPendingUploadVersion200Response, + DatasetsStartPendingUploadVersionDefaultResponse, + DatasetsStartPendingUpload200Response, + DatasetsStartPendingUploadDefaultResponse, + IndexesListVersions200Response, + IndexesListVersionsDefaultResponse, + IndexesCreate200Response, + IndexesCreateDefaultResponse, + IndexesListLatest200Response, + IndexesListLatestDefaultResponse, + IndexesGetVersion200Response, + IndexesGetVersionDefaultResponse, + IndexesDeleteVersion204Response, + IndexesDeleteVersionDefaultResponse, + IndexesCreateVersion200Response, + IndexesCreateVersion201Response, + IndexesCreateVersionDefaultResponse, + DeploymentsGet200Response, + DeploymentsGetDefaultResponse, + DeploymentsList200Response, + DeploymentsListDefaultResponse, +} from "./responses.js"; +import type { Client, StreamableMethod } from "@azure-rest/core-client"; + +export interface ConnectionsGet { + /** Get a connection by name. */ + get( + options?: ConnectionsGetParameters, + ): StreamableMethod< + ConnectionsGet200Response | ConnectionsGetDefaultResponse + >; +} + +export interface ConnectionsList { + /** List all connections in the project */ + get( + options?: ConnectionsListParameters, + ): StreamableMethod< + ConnectionsList200Response | ConnectionsListDefaultResponse + >; +} + +export interface DatasetsListVersions { + /** List all versions of the given DatasetVersion */ + get( + options?: DatasetsListVersionsParameters, + ): StreamableMethod< + DatasetsListVersions200Response | DatasetsListVersionsDefaultResponse + >; + /** Create a new DatasetVersion. The version id will be generated by the service. */ + post( + options: DatasetsCreateParameters, + ): StreamableMethod< + DatasetsCreate200Response | DatasetsCreateDefaultResponse + >; +} + +export interface DatasetsListLatest { + /** List the latest version of each DatasetVersion */ + get( + options?: DatasetsListLatestParameters, + ): StreamableMethod< + DatasetsListLatest200Response | DatasetsListLatestDefaultResponse + >; +} + +export interface DatasetsGetVersion { + /** Get the specific version of the DatasetVersion */ + get( + options?: DatasetsGetVersionParameters, + ): StreamableMethod< + DatasetsGetVersion200Response | DatasetsGetVersionDefaultResponse + >; + /** Delete the specific version of the DatasetVersion */ + delete( + options?: DatasetsDeleteVersionParameters, + ): StreamableMethod< + DatasetsDeleteVersion204Response | DatasetsDeleteVersionDefaultResponse + >; + /** Create a new or replace an existing DatasetVersion with the given version id */ + put( + options: DatasetsCreateVersionParameters, + ): StreamableMethod< + | DatasetsCreateVersion200Response + | DatasetsCreateVersion201Response + | DatasetsCreateVersionDefaultResponse + >; +} + +export interface DatasetsStartPendingUploadVersion { + /** Create or start a pending upload of a dataset for a specific version. */ + post( + options: DatasetsStartPendingUploadVersionParameters, + ): StreamableMethod< + | DatasetsStartPendingUploadVersion200Response + | DatasetsStartPendingUploadVersionDefaultResponse + >; +} + +export interface DatasetsStartPendingUpload { + /** Create or start a pending upload of a dataset. The version id will be generated by the service. */ + post( + options: DatasetsStartPendingUploadParameters, + ): StreamableMethod< + | DatasetsStartPendingUpload200Response + | DatasetsStartPendingUploadDefaultResponse + >; +} + +export interface IndexesListVersions { + /** List all versions of the given Index */ + get( + options?: IndexesListVersionsParameters, + ): StreamableMethod< + IndexesListVersions200Response | IndexesListVersionsDefaultResponse + >; + /** Create a new Index. The version id will be generated by the service. */ + post( + options: IndexesCreateParameters, + ): StreamableMethod; +} + +export interface IndexesListLatest { + /** List the latest version of each Index */ + get( + options?: IndexesListLatestParameters, + ): StreamableMethod< + IndexesListLatest200Response | IndexesListLatestDefaultResponse + >; +} + +export interface IndexesGetVersion { + /** Get the specific version of the Index */ + get( + options?: IndexesGetVersionParameters, + ): StreamableMethod< + IndexesGetVersion200Response | IndexesGetVersionDefaultResponse + >; + /** Delete the specific version of the Index */ + delete( + options?: IndexesDeleteVersionParameters, + ): StreamableMethod< + IndexesDeleteVersion204Response | IndexesDeleteVersionDefaultResponse + >; + /** Create a new or replace an existing Index with the given version id */ + put( + options: IndexesCreateVersionParameters, + ): StreamableMethod< + | IndexesCreateVersion200Response + | IndexesCreateVersion201Response + | IndexesCreateVersionDefaultResponse + >; +} + +export interface DeploymentsGet { + /** Get a deployed model. */ + get( + options?: DeploymentsGetParameters, + ): StreamableMethod< + DeploymentsGet200Response | DeploymentsGetDefaultResponse + >; +} + +export interface DeploymentsList { + /** List all deployed models in the project */ + get( + options?: DeploymentsListParameters, + ): StreamableMethod< + DeploymentsList200Response | DeploymentsListDefaultResponse + >; +} + +export interface Routes { + /** Resource for '/connections/\{name\}' has methods for the following verbs: get */ + (path: "/connections/{name}", name: string): ConnectionsGet; + /** Resource for '/connections' has methods for the following verbs: get */ + (path: "/connections"): ConnectionsList; + /** Resource for '/datasets/\{name\}/versions' has methods for the following verbs: get, post */ + (path: "/datasets/{name}/versions", name: string): DatasetsListVersions; + /** Resource for '/datasets' has methods for the following verbs: get */ + (path: "/datasets"): DatasetsListLatest; + /** Resource for '/datasets/\{name\}/versions/\{version\}' has methods for the following verbs: get, delete, put */ + ( + path: "/datasets/{name}/versions/{version}", + name: string, + version: string, + ): DatasetsGetVersion; + /** Resource for '/datasets/\{name\}/versions/\{version\}/startPendingUploadVersion' has methods for the following verbs: post */ + ( + path: "/datasets/{name}/versions/{version}/startPendingUploadVersion", + name: string, + version: string, + ): DatasetsStartPendingUploadVersion; + /** Resource for '/datasets/\{name\}/startPendingUpload' has methods for the following verbs: post */ + ( + path: "/datasets/{name}/startPendingUpload", + name: string, + ): DatasetsStartPendingUpload; + /** Resource for '/indexes/\{name\}/versions' has methods for the following verbs: get, post */ + (path: "/indexes/{name}/versions", name: string): IndexesListVersions; + /** Resource for '/indexes' has methods for the following verbs: get */ + (path: "/indexes"): IndexesListLatest; + /** Resource for '/indexes/\{name\}/versions/\{version\}' has methods for the following verbs: get, delete, put */ + ( + path: "/indexes/{name}/versions/{version}", + name: string, + version: string, + ): IndexesGetVersion; + /** Resource for '/deployments/\{name\}' has methods for the following verbs: get */ + (path: "/deployments/{name}", name: string): DeploymentsGet; + /** Resource for '/deployments' has methods for the following verbs: get */ + (path: "/deployments"): DeploymentsList; +} + +export type ProjectsClient = Client & { + path: Routes; +}; diff --git a/sdk/ai/ai-projects-1dp/src/index.ts b/sdk/ai/ai-projects-1dp/src/index.ts new file mode 100644 index 000000000000..0afd734a7856 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/index.ts @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import ProjectsClient from "./projectsClient.js"; + +export * from "./projectsClient.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 ProjectsClient; diff --git a/sdk/ai/ai-projects-1dp/src/isUnexpected.ts b/sdk/ai/ai-projects-1dp/src/isUnexpected.ts new file mode 100644 index 000000000000..0fca0cc80137 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/isUnexpected.ts @@ -0,0 +1,276 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { + ConnectionsGet200Response, + ConnectionsGetDefaultResponse, + ConnectionsList200Response, + ConnectionsListDefaultResponse, + DatasetsListVersions200Response, + DatasetsListVersionsDefaultResponse, + DatasetsCreate200Response, + DatasetsCreateDefaultResponse, + DatasetsListLatest200Response, + DatasetsListLatestDefaultResponse, + DatasetsGetVersion200Response, + DatasetsGetVersionDefaultResponse, + DatasetsDeleteVersion204Response, + DatasetsDeleteVersionDefaultResponse, + DatasetsCreateVersion200Response, + DatasetsCreateVersion201Response, + DatasetsCreateVersionDefaultResponse, + DatasetsStartPendingUploadVersion200Response, + DatasetsStartPendingUploadVersionDefaultResponse, + DatasetsStartPendingUpload200Response, + DatasetsStartPendingUploadDefaultResponse, + IndexesListVersions200Response, + IndexesListVersionsDefaultResponse, + IndexesCreate200Response, + IndexesCreateDefaultResponse, + IndexesListLatest200Response, + IndexesListLatestDefaultResponse, + IndexesGetVersion200Response, + IndexesGetVersionDefaultResponse, + IndexesDeleteVersion204Response, + IndexesDeleteVersionDefaultResponse, + IndexesCreateVersion200Response, + IndexesCreateVersion201Response, + IndexesCreateVersionDefaultResponse, + DeploymentsGet200Response, + DeploymentsGetDefaultResponse, + DeploymentsList200Response, + DeploymentsListDefaultResponse, +} from "./responses.js"; + +const responseMap: Record = { + "GET /connections/{name}": ["200"], + "GET /connections": ["200"], + "GET /datasets/{name}/versions": ["200"], + "POST /datasets/{name}/versions": ["200"], + "GET /datasets": ["200"], + "GET /datasets/{name}/versions/{version}": ["200"], + "DELETE /datasets/{name}/versions/{version}": ["204"], + "PUT /datasets/{name}/versions/{version}": ["200", "201"], + "POST /datasets/{name}/versions/{version}/startPendingUploadVersion": ["200"], + "POST /datasets/{name}/startPendingUpload": ["200"], + "GET /indexes/{name}/versions": ["200"], + "POST /indexes/{name}/versions": ["200"], + "GET /indexes": ["200"], + "GET /indexes/{name}/versions/{version}": ["200"], + "DELETE /indexes/{name}/versions/{version}": ["204"], + "PUT /indexes/{name}/versions/{version}": ["200", "201"], + "GET /deployments/{name}": ["200"], + "GET /deployments": ["200"], +}; + +export function isUnexpected( + response: ConnectionsGet200Response | ConnectionsGetDefaultResponse, +): response is ConnectionsGetDefaultResponse; +export function isUnexpected( + response: ConnectionsList200Response | ConnectionsListDefaultResponse, +): response is ConnectionsListDefaultResponse; +export function isUnexpected( + response: + | DatasetsListVersions200Response + | DatasetsListVersionsDefaultResponse, +): response is DatasetsListVersionsDefaultResponse; +export function isUnexpected( + response: DatasetsCreate200Response | DatasetsCreateDefaultResponse, +): response is DatasetsCreateDefaultResponse; +export function isUnexpected( + response: DatasetsListLatest200Response | DatasetsListLatestDefaultResponse, +): response is DatasetsListLatestDefaultResponse; +export function isUnexpected( + response: DatasetsGetVersion200Response | DatasetsGetVersionDefaultResponse, +): response is DatasetsGetVersionDefaultResponse; +export function isUnexpected( + response: + | DatasetsDeleteVersion204Response + | DatasetsDeleteVersionDefaultResponse, +): response is DatasetsDeleteVersionDefaultResponse; +export function isUnexpected( + response: + | DatasetsCreateVersion200Response + | DatasetsCreateVersion201Response + | DatasetsCreateVersionDefaultResponse, +): response is DatasetsCreateVersionDefaultResponse; +export function isUnexpected( + response: + | DatasetsStartPendingUploadVersion200Response + | DatasetsStartPendingUploadVersionDefaultResponse, +): response is DatasetsStartPendingUploadVersionDefaultResponse; +export function isUnexpected( + response: + | DatasetsStartPendingUpload200Response + | DatasetsStartPendingUploadDefaultResponse, +): response is DatasetsStartPendingUploadDefaultResponse; +export function isUnexpected( + response: IndexesListVersions200Response | IndexesListVersionsDefaultResponse, +): response is IndexesListVersionsDefaultResponse; +export function isUnexpected( + response: IndexesCreate200Response | IndexesCreateDefaultResponse, +): response is IndexesCreateDefaultResponse; +export function isUnexpected( + response: IndexesListLatest200Response | IndexesListLatestDefaultResponse, +): response is IndexesListLatestDefaultResponse; +export function isUnexpected( + response: IndexesGetVersion200Response | IndexesGetVersionDefaultResponse, +): response is IndexesGetVersionDefaultResponse; +export function isUnexpected( + response: + | IndexesDeleteVersion204Response + | IndexesDeleteVersionDefaultResponse, +): response is IndexesDeleteVersionDefaultResponse; +export function isUnexpected( + response: + | IndexesCreateVersion200Response + | IndexesCreateVersion201Response + | IndexesCreateVersionDefaultResponse, +): response is IndexesCreateVersionDefaultResponse; +export function isUnexpected( + response: DeploymentsGet200Response | DeploymentsGetDefaultResponse, +): response is DeploymentsGetDefaultResponse; +export function isUnexpected( + response: DeploymentsList200Response | DeploymentsListDefaultResponse, +): response is DeploymentsListDefaultResponse; +export function isUnexpected( + response: + | ConnectionsGet200Response + | ConnectionsGetDefaultResponse + | ConnectionsList200Response + | ConnectionsListDefaultResponse + | DatasetsListVersions200Response + | DatasetsListVersionsDefaultResponse + | DatasetsCreate200Response + | DatasetsCreateDefaultResponse + | DatasetsListLatest200Response + | DatasetsListLatestDefaultResponse + | DatasetsGetVersion200Response + | DatasetsGetVersionDefaultResponse + | DatasetsDeleteVersion204Response + | DatasetsDeleteVersionDefaultResponse + | DatasetsCreateVersion200Response + | DatasetsCreateVersion201Response + | DatasetsCreateVersionDefaultResponse + | DatasetsStartPendingUploadVersion200Response + | DatasetsStartPendingUploadVersionDefaultResponse + | DatasetsStartPendingUpload200Response + | DatasetsStartPendingUploadDefaultResponse + | IndexesListVersions200Response + | IndexesListVersionsDefaultResponse + | IndexesCreate200Response + | IndexesCreateDefaultResponse + | IndexesListLatest200Response + | IndexesListLatestDefaultResponse + | IndexesGetVersion200Response + | IndexesGetVersionDefaultResponse + | IndexesDeleteVersion204Response + | IndexesDeleteVersionDefaultResponse + | IndexesCreateVersion200Response + | IndexesCreateVersion201Response + | IndexesCreateVersionDefaultResponse + | DeploymentsGet200Response + | DeploymentsGetDefaultResponse + | DeploymentsList200Response + | DeploymentsListDefaultResponse, +): response is + | ConnectionsGetDefaultResponse + | ConnectionsListDefaultResponse + | DatasetsListVersionsDefaultResponse + | DatasetsCreateDefaultResponse + | DatasetsListLatestDefaultResponse + | DatasetsGetVersionDefaultResponse + | DatasetsDeleteVersionDefaultResponse + | DatasetsCreateVersionDefaultResponse + | DatasetsStartPendingUploadVersionDefaultResponse + | DatasetsStartPendingUploadDefaultResponse + | IndexesListVersionsDefaultResponse + | IndexesCreateDefaultResponse + | IndexesListLatestDefaultResponse + | IndexesGetVersionDefaultResponse + | IndexesDeleteVersionDefaultResponse + | IndexesCreateVersionDefaultResponse + | DeploymentsGetDefaultResponse + | DeploymentsListDefaultResponse { + const lroOriginal = response.headers["x-ms-original-url"]; + const url = new URL(lroOriginal ?? response.request.url); + const method = response.request.method; + let pathDetails = responseMap[`${method} ${url.pathname}`]; + if (!pathDetails) { + pathDetails = getParametrizedPathSuccess(method, url.pathname); + } + return !pathDetails.includes(response.status); +} + +function getParametrizedPathSuccess(method: string, path: string): string[] { + const pathParts = path.split("/"); + + // Traverse list to match the longest candidate + // matchedLen: the length of candidate path + // matchedValue: the matched status code array + let matchedLen = -1, + matchedValue: string[] = []; + + // Iterate the responseMap to find a match + for (const [key, value] of Object.entries(responseMap)) { + // Extracting the path from the map key which is in format + // GET /path/foo + if (!key.startsWith(method)) { + continue; + } + const candidatePath = getPathFromMapKey(key); + // Get each part of the url path + const candidateParts = candidatePath.split("/"); + + // 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 + ) { + 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] || ""); + + if (!isMatched) { + found = false; + break; + } + continue; + } + + // If the candidate part is not a template and + // the parts don't match mark the candidate as not found + // to move on with the next candidate path. + if (candidateParts[i] !== pathParts[j]) { + found = false; + break; + } + } + + // We finished evaluating the current candidate parts + // Update the matched value if and only if we found the longer pattern + if (found && candidatePath.length > matchedLen) { + matchedLen = candidatePath.length; + matchedValue = value; + } + } + + return matchedValue; +} + +function getPathFromMapKey(mapKey: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/sdk/ai/ai-projects-1dp/src/logger.ts b/sdk/ai/ai-projects-1dp/src/logger.ts new file mode 100644 index 000000000000..26856543a80b --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/logger.ts @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { createClientLogger } from "@azure/logger"; +export const logger = createClientLogger("ai-projects-1dp"); diff --git a/sdk/ai/ai-projects-1dp/src/models.ts b/sdk/ai/ai-projects-1dp/src/models.ts new file mode 100644 index 000000000000..b036212b0153 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/models.ts @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** DatasetVersion Definition */ +export interface DatasetVersionParent { + /** [Required] Uri of the data. Example: https://go.microsoft.com/fwlink/?linkid=2202330 */ + datasetUri: string; + /** Asset stage */ + stage?: string; + /** The asset description text. */ + description?: string; + /** Tag dictionary. Tags can be added, removed, and updated. */ + tags?: Record; + type: DatasetType; +} + +/** FileDatasetVersion Definition */ +export interface FileDatasetVersion extends DatasetVersionParent { + /** Dataset type */ + type: "uri_file"; + /** Indicates OpenAI Purpose. FileDatasets created with this field will be compatible with OpenAI-specific features */ + openAIPurpose: string; +} + +/** FileDatasetVersion Definition */ +export interface FolderDatasetVersion extends DatasetVersionParent { + /** Dataset type */ + type: "uri_folder"; +} + +/** Represents a request for a pending upload. */ +export interface PendingUploadRequest { + /** If PendingUploadId is not provided, a random GUID will be used. */ + pendingUploadId?: string; + /** Name of Azure blob storage connection to use for generating temporary SAS token */ + connectionName?: string; + /** TemporaryBlobReference is the only supported type. */ + pendingUploadType: "TemporaryBlobReference"; +} + +/** Index resource Definition */ +export interface IndexParent { + /** Asset stage */ + stage?: string; + /** The asset description text. */ + description?: string; + /** Tag dictionary. Tags can be added, removed, and updated. */ + tags?: Record; + type: IndexType; +} + +/** Azure AI Search Index Definition */ +export interface AzureAISearchIndex extends IndexParent { + /** Type of index */ + type: "AzureSearch"; + /** Name of connection to Azure AI Search */ + connectionName: string; + /** Name of index in Azure AI Search resource to attach */ + indexName: string; +} + +/** Managed Azure AI Search Index Definition */ +export interface ManagedAzureAISearchIndex extends IndexParent { + /** Type of index */ + type: "ManagedAzureSearch"; + /** Vector store id of managed index */ + vectorStoreId: string; +} + +/** CosmosDB Vector Store Index Definition */ +export interface CosmosDBIndex extends IndexParent { + /** Type of index */ + type: "CosmosDBNoSqlVectorStore"; + /** Name of connection to CosmosDB */ + connectionName: string; + /** Name of the CosmosDB Database */ + databaseName: string; + /** Name of CosmosDB Container */ + containerName: string; + /** Embedding model configuration */ + embeddingConfiguration: EmbeddingConfiguration; +} + +/** Embedding configuration class */ +export interface EmbeddingConfiguration { + /** Deployment name of embedding model. It can point to a model deployment either in the parent AIServices or a connection. */ + modelDeploymentName: string; + /** Embedding field */ + embeddingField: string; +} + +/** DatasetVersion Definition */ +export type DatasetVersion = + | DatasetVersionParent + | FileDatasetVersion + | FolderDatasetVersion; +/** Index resource Definition */ +export type Index = + | IndexParent + | AzureAISearchIndex + | ManagedAzureAISearchIndex + | CosmosDBIndex; +/** Alias for ConnectionType */ +export type ConnectionType = string; +/** Alias for ListViewType */ +export type ListViewType = string; +/** Alias for DatasetType */ +export type DatasetType = string; +/** Alias for IndexType */ +export type IndexType = string; diff --git a/sdk/ai/ai-projects-1dp/src/outputModels.ts b/sdk/ai/ai-projects-1dp/src/outputModels.ts new file mode 100644 index 000000000000..1a75ff9fcc70 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/outputModels.ts @@ -0,0 +1,243 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** Response from the listSecrets operation */ +export interface ConnectionOutput { + /** The name of the resource */ + readonly name: string; + /** + * Category of the connection + * + * Possible values: "AzureOpenAI", "AzureBlob", "CognitiveSearch", "CosmosDB", "ApiKey", "AppInsights", "CustomKeys" + */ + readonly type: ConnectionTypeOutput; + /** The connection URL to be used for this service */ + readonly target: string; + /** + * The authentication type used by the connection + * + * Possible values: "ApiKey", "AAD", "SAS", "CustomKeys", "None" + */ + readonly authType: AuthenticationTypeOutput; + /** Metadata of the connection */ + readonly metadata: Record; +} + +/** Paged collection of Connection items */ +export interface PagedConnectionOutput { + /** The Connection items on this page */ + value: Array; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Paged collection of DatasetVersion items */ +export interface PagedDatasetVersionOutput { + /** The DatasetVersion items on this page */ + value: Array; + /** The link to the next page of items */ + nextLink?: string; +} + +/** DatasetVersion Definition */ +export interface DatasetVersionOutputParent { + /** [Required] Uri of the data. Example: https://go.microsoft.com/fwlink/?linkid=2202330 */ + datasetUri: string; + /** Indicates if dataset is reference only or managed by dataset service. If true, the underlying data will be deleted when the dataset version is deleted */ + readonly isReference?: boolean; + /** Asset stage */ + stage?: string; + /** A unique identifier for the asset, assetId probably? */ + readonly id?: string; + /** The name of the resource */ + readonly name: string; + /** The version of the resource */ + readonly version: string; + /** The asset description text. */ + description?: string; + /** Tag dictionary. Tags can be added, removed, and updated. */ + tags?: Record; + type: DatasetTypeOutput; +} + +/** FileDatasetVersion Definition */ +export interface FileDatasetVersionOutput extends DatasetVersionOutputParent { + /** Dataset type */ + type: "uri_file"; + /** Indicates OpenAI Purpose. FileDatasets created with this field will be compatible with OpenAI-specific features */ + openAIPurpose: string; +} + +/** FileDatasetVersion Definition */ +export interface FolderDatasetVersionOutput extends DatasetVersionOutputParent { + /** Dataset type */ + type: "uri_folder"; +} + +/** Represents the response for a pending upload request */ +export interface PendingUploadResponseOutput { + /** Container-level read, write, list SAS. */ + blobReferenceForConsumption: BlobReferenceForConsumptionOutput; + /** ID for this upload request. */ + pendingUploadId: string; + /** Version of dataset to be created if user did not specify version when initially creating upload */ + datasetVersion?: string; + /** TemporaryBlobReference is the only supported type */ + pendingUploadType: "TemporaryBlobReference"; +} + +/** Represents a reference to a blob for consumption */ +export interface BlobReferenceForConsumptionOutput { + /** Blob URI path for client to upload data. Example: https://blob.windows.core.net/Container/Path */ + blobUri: string; + /** ARM ID of the storage account to use. */ + storageAccountArmId: string; + /** Credential info to access the storage account. */ + credential: SasCredentialOutput; +} + +/** SAS Credential definition */ +export interface SasCredentialOutput { + /** SAS uri */ + readonly sasUri: string; + /** Type of credential */ + readonly type: "SAS"; +} + +/** Paged collection of Index items */ +export interface PagedIndexOutput { + /** The Index items on this page */ + value: Array; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Index resource Definition */ +export interface IndexOutputParent { + /** Asset stage */ + stage?: string; + /** A unique identifier for the asset, assetId probably? */ + readonly id?: string; + /** The name of the resource */ + readonly name: string; + /** The version of the resource */ + readonly version: string; + /** The asset description text. */ + description?: string; + /** Tag dictionary. Tags can be added, removed, and updated. */ + tags?: Record; + type: IndexTypeOutput; +} + +/** Azure AI Search Index Definition */ +export interface AzureAISearchIndexOutput extends IndexOutputParent { + /** Type of index */ + type: "AzureSearch"; + /** Name of connection to Azure AI Search */ + connectionName: string; + /** Name of index in Azure AI Search resource to attach */ + indexName: string; +} + +/** Managed Azure AI Search Index Definition */ +export interface ManagedAzureAISearchIndexOutput extends IndexOutputParent { + /** Type of index */ + type: "ManagedAzureSearch"; + /** Vector store id of managed index */ + vectorStoreId: string; +} + +/** CosmosDB Vector Store Index Definition */ +export interface CosmosDBIndexOutput extends IndexOutputParent { + /** Type of index */ + type: "CosmosDBNoSqlVectorStore"; + /** Name of connection to CosmosDB */ + connectionName: string; + /** Name of the CosmosDB Database */ + databaseName: string; + /** Name of CosmosDB Container */ + containerName: string; + /** Embedding model configuration */ + embeddingConfiguration: EmbeddingConfigurationOutput; +} + +/** Embedding configuration class */ +export interface EmbeddingConfigurationOutput { + /** Deployment name of embedding model. It can point to a model deployment either in the parent AIServices or a connection. */ + modelDeploymentName: string; + /** Embedding field */ + embeddingField: string; +} + +/** Model Deployment Definition */ +export interface DeploymentOutputParent { + /** Name of the deployment */ + readonly name: string; + type: DeploymentTypeOutput; +} + +/** Paged collection of Deployment items */ +export interface PagedDeploymentOutput { + /** The Deployment items on this page */ + value: Array; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Model Deployment Definition */ +export interface ModelDeploymentOutput extends DeploymentOutputParent { + /** The type of the deployment */ + type: "ModelDeployment"; + /** Publisher-specific name of the deployed model */ + readonly modelName: string; + /** Publisher-specific version of the deployed model */ + readonly modelVersion: string; + /** Name of the deployed model's publisher */ + readonly modelPublisher: string; + /** Capabilities of deployed model */ + readonly capabilities: Record; + /** Sku of the model deployment */ + readonly sku: SkuOutput; + /** Name of the connection the deployment comes from */ + readonly connectionName?: string; +} + +/** Sku information */ +export interface SkuOutput { + /** Sku capacity */ + capacity: number; + /** Sku family */ + family: string; + /** Sku name */ + name: string; + /** Sku size */ + size: string; + /** Sku tier */ + tier: string; +} + +/** DatasetVersion Definition */ +export type DatasetVersionOutput = + | DatasetVersionOutputParent + | FileDatasetVersionOutput + | FolderDatasetVersionOutput; +/** Index resource Definition */ +export type IndexOutput = + | IndexOutputParent + | AzureAISearchIndexOutput + | ManagedAzureAISearchIndexOutput + | CosmosDBIndexOutput; +/** Model Deployment Definition */ +export type DeploymentOutput = DeploymentOutputParent | ModelDeploymentOutput; +/** Alias for ConnectionTypeOutput */ +export type ConnectionTypeOutput = string; +/** Alias for AuthenticationTypeOutput */ +export type AuthenticationTypeOutput = string; +/** Alias for DatasetTypeOutput */ +export type DatasetTypeOutput = string; +/** Alias for RepeatabilityResultOutput */ +export type RepeatabilityResultOutput = "accepted" | "rejected"; +/** Alias for IndexTypeOutput */ +export type IndexTypeOutput = string; +/** Alias for DeploymentTypeOutput */ +export type DeploymentTypeOutput = string; diff --git a/sdk/ai/ai-projects-1dp/src/paginateHelper.ts b/sdk/ai/ai-projects-1dp/src/paginateHelper.ts new file mode 100644 index 000000000000..70694e2c93c6 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/paginateHelper.ts @@ -0,0 +1,294 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { Client, PathUncheckedResponse } from "@azure-rest/core-client"; +import { createRestError } from "@azure-rest/core-client"; + +/** + * returns an async iterator that iterates over results. It also has a `byPage` + * method that returns pages of items at once. + * + * @param pagedResult - an object that specifies how to get pages. + * @returns a paged async iterator that iterates over results. + */ +function getPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings = PageSettings, + TLink = string, +>( + pagedResult: PagedResult, +): PagedAsyncIterableIterator { + const iter = getItemAsyncIterator( + pagedResult, + ); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: + pagedResult?.byPage ?? + (((settings?: PageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken as unknown as TLink | undefined, + }); + }) as unknown as ( + settings?: TPageSettings, + ) => AsyncIterableIterator), + }; +} + +async function* getItemAsyncIterator( + pagedResult: PagedResult, +): AsyncIterableIterator { + const pages = getPageAsyncIterator(pagedResult); + const firstVal = await pages.next(); + // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is + if (!Array.isArray(firstVal.value)) { + // can extract elements from this page + const { toElements } = pagedResult; + if (toElements) { + yield* toElements(firstVal.value) as TElement[]; + for await (const page of pages) { + yield* toElements(page) as TElement[]; + } + } else { + yield firstVal.value; + // `pages` is of type `AsyncIterableIterator` but TPage = TElement in this case + yield* pages as unknown as AsyncIterableIterator; + } + } else { + yield* firstVal.value; + for await (const page of pages) { + // pages is of type `AsyncIterableIterator` so `page` is of type `TPage`. In this branch, + // it must be the case that `TPage = TElement[]` + yield* page as unknown as TElement[]; + } + } +} + +async function* getPageAsyncIterator( + pagedResult: PagedResult, + options: { + pageLink?: TLink; + } = {}, +): AsyncIterableIterator { + const { pageLink } = options; + let response = await pagedResult.getPage( + pageLink ?? pagedResult.firstPageLink, + ); + if (!response) { + return; + } + yield response.page; + while (response.nextPageLink) { + response = await pagedResult.getPage(response.nextPageLink); + if (!response) { + return; + } + yield response.page; + } +} + +/** + * An interface that tracks the settings for paged iteration + */ +export interface PageSettings { + /** + * The token that keeps track of where to continue the iterator + */ + continuationToken?: string; +} + +/** + * An interface that allows async iterable iteration both to completion and by page. + */ +export interface PagedAsyncIterableIterator< + TElement, + TPage = TElement[], + TPageSettings = PageSettings, +> { + /** + * The next method, part of the iteration protocol + */ + next(): Promise>; + /** + * The connection to the async iterator, part of the iteration protocol + */ + [Symbol.asyncIterator](): PagedAsyncIterableIterator< + TElement, + TPage, + TPageSettings + >; + /** + * Return an AsyncIterableIterator that works a page at a time + */ + byPage: (settings?: TPageSettings) => AsyncIterableIterator; +} + +/** + * An interface that describes how to communicate with the service. + */ +interface PagedResult { + /** + * Link to the first page of results. + */ + firstPageLink: TLink; + /** + * A method that returns a page of results. + */ + getPage: ( + pageLink: TLink, + ) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>; + /** + * a function to implement the `byPage` method on the paged async iterator. + */ + byPage?: (settings?: TPageSettings) => AsyncIterableIterator; + + /** + * A function to extract elements from a page. + */ + toElements?: (page: TPage) => unknown[]; +} + +/** + * Helper type to extract the type of an array + */ +export type GetArrayType = T extends Array ? TData : never; + +/** + * The type of a custom function that defines how to get a page and a link to the next one if any. + */ +export type GetPage = (pageLink: string) => Promise<{ + page: TPage; + nextPageLink?: string; +}>; + +/** + * Options for the paging helper + */ +export interface PagingOptions { + /** + * Custom function to extract pagination details for crating the PagedAsyncIterableIterator + */ + customGetPage?: GetPage[]>; +} + +/** + * Helper type to infer the Type of the paged elements from the response type + * This type is generated based on the swagger information for x-ms-pageable + * specifically on the itemName property which indicates the property of the response + * where the page items are found. The default value is `value`. + * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter + */ +export type PaginateReturn = TResult extends { + body: { value?: infer TPage }; +} + ? GetArrayType + : Array; + +/** + * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension + * @param client - Client to use for sending the next page requests + * @param initialResponse - Initial response containing the nextLink and current page of elements + * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results + * @returns - PagedAsyncIterableIterator to iterate the elements + */ +export function paginate( + client: Client, + initialResponse: TResponse, + options: PagingOptions = {}, +): PagedAsyncIterableIterator> { + // Extract element type from initial response + type TElement = PaginateReturn; + let firstRun = true; + const itemName = "value"; + const nextLinkName = "nextLink"; + const { customGetPage } = options; + const pagedResult: PagedResult = { + firstPageLink: "", + getPage: + typeof customGetPage === "function" + ? customGetPage + : async (pageLink: string) => { + const result = firstRun + ? initialResponse + : await client.pathUnchecked(pageLink).get(); + firstRun = false; + checkPagingRequest(result); + const nextLink = getNextLink(result.body, nextLinkName); + const values = getElements(result.body, itemName); + return { + page: values, + nextPageLink: nextLink, + }; + }, + }; + + return getPagedAsyncIterator(pagedResult); +} + +/** + * Gets for the value of nextLink in the body + */ +function getNextLink(body: unknown, nextLinkName?: string): string | undefined { + if (!nextLinkName) { + return 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`, + ); + } + + return nextLink; +} + +/** + * Gets the elements of the current request in the body. + */ +function getElements(body: unknown, itemName: string): T[] { + const value = (body as Record)[itemName] as T[]; + + // value has to be an array according to the x-ms-pageable extension. + // The fact that this must be an array is used above to calculate the + // type of elements in the page in PaginateReturn + if (!Array.isArray(value)) { + throw new Error( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`, + ); + } + + return value ?? []; +} + +/** + * Checks if a request failed + */ +function checkPagingRequest(response: PathUncheckedResponse): void { + 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}`, + response, + ); + } +} diff --git a/sdk/ai/ai-projects-1dp/src/parameters.ts b/sdk/ai/ai-projects-1dp/src/parameters.ts new file mode 100644 index 000000000000..21a4b25bbfa3 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/parameters.ts @@ -0,0 +1,266 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { RawHttpHeadersInput } from "@azure/core-rest-pipeline"; +import type { RequestParameters } from "@azure-rest/core-client"; +import type { + ConnectionType, + ListViewType, + DatasetVersion, + PendingUploadRequest, + Index, +} from "./models.js"; + +export interface ConnectionsGetHeaders { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +export interface ConnectionsGetHeaderParam { + headers?: RawHttpHeadersInput & ConnectionsGetHeaders; +} + +export type ConnectionsGetParameters = ConnectionsGetHeaderParam & + RequestParameters; + +export interface ConnectionsListHeaders { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +export interface ConnectionsListQueryParamProperties { + /** + * Specific type of connection to return in list + * + * Possible values: "AzureOpenAI", "AzureBlob", "CognitiveSearch", "CosmosDB", "ApiKey", "AppInsights", "CustomKeys" + */ + connectionType?: ConnectionType; + /** The number of result items to return. */ + top?: number; + /** The number of result items to skip. */ + skip?: number; + /** The maximum number of result items per page. */ + maxpagesize?: number; +} + +export interface ConnectionsListQueryParam { + queryParameters?: ConnectionsListQueryParamProperties; +} + +export interface ConnectionsListHeaderParam { + headers?: RawHttpHeadersInput & ConnectionsListHeaders; +} + +export type ConnectionsListParameters = ConnectionsListQueryParam & + ConnectionsListHeaderParam & + RequestParameters; + +export interface DatasetsListVersionsQueryParamProperties { + /** Top count of results, top count cannot be greater than the page size. If topCount > page size, results with be default page size count will be returned */ + top?: number; + /** Continuation token for pagination. */ + skip?: string; + /** Comma-separated list of tag names (and optionally values). Example: tag1,tag2=value2 */ + tags?: string; + /** + * [ListViewType.ActiveOnly, ListViewType.ArchivedOnly, ListViewType.All] View type for including/excluding (for example) archived entities. + * + * Possible values: "ActiveOnly", "ArchivedOnly", "All" + */ + listViewType?: ListViewType; +} + +export interface DatasetsListVersionsQueryParam { + queryParameters?: DatasetsListVersionsQueryParamProperties; +} + +export type DatasetsListVersionsParameters = DatasetsListVersionsQueryParam & + RequestParameters; + +export interface DatasetsListLatestQueryParamProperties { + /** Top count of results, top count cannot be greater than the page size. If topCount > page size, results with be default page size count will be returned */ + top?: number; + /** Continuation token for pagination. */ + skip?: string; + /** Comma-separated list of tag names (and optionally values). Example: tag1,tag2=value2 */ + tags?: string; + /** + * [ListViewType.ActiveOnly, ListViewType.ArchivedOnly, ListViewType.All] View type for including/excluding (for example) archived entities. + * + * Possible values: "ActiveOnly", "ArchivedOnly", "All" + */ + listViewType?: ListViewType; +} + +export interface DatasetsListLatestQueryParam { + queryParameters?: DatasetsListLatestQueryParamProperties; +} + +export type DatasetsListLatestParameters = DatasetsListLatestQueryParam & + RequestParameters; +export type DatasetsGetVersionParameters = RequestParameters; +export type DatasetsDeleteVersionParameters = RequestParameters; + +export interface DatasetsCreateHeaders { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "Repeatability-Request-ID"?: string; + /** Specifies the date and time at which the request was first created. */ + "Repeatability-First-Sent"?: string; + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +export interface DatasetsCreateBodyParam { + /** The definition of the DatasetVersion to create */ + body: DatasetVersion; +} + +export interface DatasetsCreateHeaderParam { + headers?: RawHttpHeadersInput & DatasetsCreateHeaders; +} + +export type DatasetsCreateParameters = DatasetsCreateHeaderParam & + DatasetsCreateBodyParam & + RequestParameters; + +export interface DatasetsCreateVersionBodyParam { + /** The definition of the DatasetVersion to create */ + body: DatasetVersion; +} + +export type DatasetsCreateVersionParameters = DatasetsCreateVersionBodyParam & + RequestParameters; + +export interface DatasetsStartPendingUploadVersionBodyParam { + /** Parameters for the action */ + body: PendingUploadRequest; +} + +export type DatasetsStartPendingUploadVersionParameters = + DatasetsStartPendingUploadVersionBodyParam & RequestParameters; + +export interface DatasetsStartPendingUploadBodyParam { + /** Parameters for the action */ + body: PendingUploadRequest; +} + +export type DatasetsStartPendingUploadParameters = + DatasetsStartPendingUploadBodyParam & RequestParameters; + +export interface IndexesListVersionsQueryParamProperties { + /** Top count of results, top count cannot be greater than the page size. If topCount > page size, results with be default page size count will be returned */ + top?: number; + /** Continuation token for pagination. */ + skip?: string; + /** Comma-separated list of tag names (and optionally values). Example: tag1,tag2=value2 */ + tags?: string; + /** + * [ListViewType.ActiveOnly, ListViewType.ArchivedOnly, ListViewType.All] View type for including/excluding (for example) archived entities. + * + * Possible values: "ActiveOnly", "ArchivedOnly", "All" + */ + listViewType?: ListViewType; +} + +export interface IndexesListVersionsQueryParam { + queryParameters?: IndexesListVersionsQueryParamProperties; +} + +export type IndexesListVersionsParameters = IndexesListVersionsQueryParam & + RequestParameters; + +export interface IndexesListLatestQueryParamProperties { + /** Top count of results, top count cannot be greater than the page size. If topCount > page size, results with be default page size count will be returned */ + top?: number; + /** Continuation token for pagination. */ + skip?: string; + /** Comma-separated list of tag names (and optionally values). Example: tag1,tag2=value2 */ + tags?: string; + /** + * [ListViewType.ActiveOnly, ListViewType.ArchivedOnly, ListViewType.All] View type for including/excluding (for example) archived entities. + * + * Possible values: "ActiveOnly", "ArchivedOnly", "All" + */ + listViewType?: ListViewType; +} + +export interface IndexesListLatestQueryParam { + queryParameters?: IndexesListLatestQueryParamProperties; +} + +export type IndexesListLatestParameters = IndexesListLatestQueryParam & + RequestParameters; +export type IndexesGetVersionParameters = RequestParameters; +export type IndexesDeleteVersionParameters = RequestParameters; + +export interface IndexesCreateHeaders { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "Repeatability-Request-ID"?: string; + /** Specifies the date and time at which the request was first created. */ + "Repeatability-First-Sent"?: string; + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +export interface IndexesCreateBodyParam { + /** The definition of the Index to create */ + body: Index; +} + +export interface IndexesCreateHeaderParam { + headers?: RawHttpHeadersInput & IndexesCreateHeaders; +} + +export type IndexesCreateParameters = IndexesCreateHeaderParam & + IndexesCreateBodyParam & + RequestParameters; + +export interface IndexesCreateVersionBodyParam { + /** The definition of the Index to create */ + body: Index; +} + +export type IndexesCreateVersionParameters = IndexesCreateVersionBodyParam & + RequestParameters; + +export interface DeploymentsGetHeaders { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +export interface DeploymentsGetHeaderParam { + headers?: RawHttpHeadersInput & DeploymentsGetHeaders; +} + +export type DeploymentsGetParameters = DeploymentsGetHeaderParam & + RequestParameters; + +export interface DeploymentsListHeaders { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +export interface DeploymentsListQueryParamProperties { + /** Model publisher to filter models by */ + modelPublisher?: string; + /** Model name (the publisher specific name) to filter models by */ + modelName?: string; + /** The number of result items to return. */ + top?: number; + /** The number of result items to skip. */ + skip?: number; + /** The maximum number of result items per page. */ + maxpagesize?: number; +} + +export interface DeploymentsListQueryParam { + queryParameters?: DeploymentsListQueryParamProperties; +} + +export interface DeploymentsListHeaderParam { + headers?: RawHttpHeadersInput & DeploymentsListHeaders; +} + +export type DeploymentsListParameters = DeploymentsListQueryParam & + DeploymentsListHeaderParam & + RequestParameters; diff --git a/sdk/ai/ai-projects-1dp/src/projectsClient.ts b/sdk/ai/ai-projects-1dp/src/projectsClient.ts new file mode 100644 index 000000000000..985f42966b60 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/projectsClient.ts @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { ClientOptions } from "@azure-rest/core-client"; +import { getClient } from "@azure-rest/core-client"; +import { logger } from "./logger.js"; +import type { + TokenCredential, + KeyCredential, + isKeyCredential, +} from "@azure/core-auth"; +import type { ProjectsClient } from "./clientDefinitions.js"; + +/** The optional parameters for the client */ +export interface ProjectsClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + +/** + * Initialize a new instance of `ProjectsClient` + * @param endpointParam - Project endpoint in the form of: https://.services.ai.azure.com/api/projects/ + * @param credentials - uniquely identify client credential + * @param options - the parameter for all optional parameters + */ +export default function createClient( + endpointParam: string, + credentials: TokenCredential | KeyCredential, + { apiVersion = "latest", ...options }: ProjectsClientOptions = {}, +): ProjectsClient { + const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; + const userAgentInfo = `azsdk-js-ai-projects-1dp-rest/1.0.0-beta.1`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` + : `${userAgentInfo}`; + options = { + ...options, + userAgentOptions: { + userAgentPrefix, + }, + loggingOptions: { + logger: options.loggingOptions?.logger ?? logger.info, + }, + credentials: { + scopes: options.credentials?.scopes ?? [ + "https://cognitiveservices.azure.com/.default", + ], + }, + }; + const client = getClient(endpointUrl, credentials, options) as ProjectsClient; + + 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); + }, + }); + if (isKeyCredential(credentials)) { + client.pipeline.addPolicy({ + name: "customKeyCredentialPolicy", + async sendRequest(request, next) { + request.headers.set("Authorization", "Bearer " + credentials.key); + return next(request); + }, + }); + } + + return client; +} diff --git a/sdk/ai/ai-projects-1dp/src/responses.ts b/sdk/ai/ai-projects-1dp/src/responses.ts new file mode 100644 index 000000000000..f9bfab1a4b1d --- /dev/null +++ b/sdk/ai/ai-projects-1dp/src/responses.ts @@ -0,0 +1,376 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { RawHttpHeaders } from "@azure/core-rest-pipeline"; +import type { HttpResponse, ErrorResponse } from "@azure-rest/core-client"; +import type { + ConnectionOutput, + PagedConnectionOutput, + PagedDatasetVersionOutput, + DatasetVersionOutput, + RepeatabilityResultOutput, + PendingUploadResponseOutput, + PagedIndexOutput, + IndexOutput, + DeploymentOutput, + PagedDeploymentOutput, +} from "./outputModels.js"; + +export interface ConnectionsGet200Headers { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +/** The request has succeeded. */ +export interface ConnectionsGet200Response extends HttpResponse { + status: "200"; + body: ConnectionOutput; + headers: RawHttpHeaders & ConnectionsGet200Headers; +} + +export interface ConnectionsGetDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface ConnectionsGetDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & ConnectionsGetDefaultHeaders; +} + +export interface ConnectionsList200Headers { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +/** The request has succeeded. */ +export interface ConnectionsList200Response extends HttpResponse { + status: "200"; + body: PagedConnectionOutput; + headers: RawHttpHeaders & ConnectionsList200Headers; +} + +export interface ConnectionsListDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface ConnectionsListDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & ConnectionsListDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DatasetsListVersions200Response extends HttpResponse { + status: "200"; + body: PagedDatasetVersionOutput; +} + +export interface DatasetsListVersionsDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsListVersionsDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsListVersionsDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DatasetsListLatest200Response extends HttpResponse { + status: "200"; + body: PagedDatasetVersionOutput; +} + +export interface DatasetsListLatestDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsListLatestDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsListLatestDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DatasetsGetVersion200Response extends HttpResponse { + status: "200"; + body: DatasetVersionOutput; +} + +export interface DatasetsGetVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsGetVersionDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsGetVersionDefaultHeaders; +} + +/** There is no content to send for this request, but the headers may be useful. */ +export interface DatasetsDeleteVersion204Response extends HttpResponse { + status: "204"; +} + +export interface DatasetsDeleteVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsDeleteVersionDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsDeleteVersionDefaultHeaders; +} + +export interface DatasetsCreate200Headers { + /** Indicates whether the repeatable request was accepted or rejected. */ + "repeatability-result"?: RepeatabilityResultOutput; + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +/** The request has succeeded. */ +export interface DatasetsCreate200Response extends HttpResponse { + status: "200"; + body: DatasetVersionOutput; + headers: RawHttpHeaders & DatasetsCreate200Headers; +} + +export interface DatasetsCreateDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsCreateDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsCreateDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DatasetsCreateVersion200Response extends HttpResponse { + status: "200"; + body: DatasetVersionOutput; +} + +/** The request has succeeded and a new resource has been created as a result. */ +export interface DatasetsCreateVersion201Response extends HttpResponse { + status: "201"; + body: DatasetVersionOutput; +} + +export interface DatasetsCreateVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsCreateVersionDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsCreateVersionDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DatasetsStartPendingUploadVersion200Response + extends HttpResponse { + status: "200"; + body: PendingUploadResponseOutput; +} + +export interface DatasetsStartPendingUploadVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsStartPendingUploadVersionDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsStartPendingUploadVersionDefaultHeaders; +} + +/** The request has succeeded. */ +export interface DatasetsStartPendingUpload200Response extends HttpResponse { + status: "200"; + body: PendingUploadResponseOutput; +} + +export interface DatasetsStartPendingUploadDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DatasetsStartPendingUploadDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DatasetsStartPendingUploadDefaultHeaders; +} + +/** The request has succeeded. */ +export interface IndexesListVersions200Response extends HttpResponse { + status: "200"; + body: PagedIndexOutput; +} + +export interface IndexesListVersionsDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface IndexesListVersionsDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & IndexesListVersionsDefaultHeaders; +} + +/** The request has succeeded. */ +export interface IndexesListLatest200Response extends HttpResponse { + status: "200"; + body: PagedIndexOutput; +} + +export interface IndexesListLatestDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface IndexesListLatestDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & IndexesListLatestDefaultHeaders; +} + +/** The request has succeeded. */ +export interface IndexesGetVersion200Response extends HttpResponse { + status: "200"; + body: IndexOutput; +} + +export interface IndexesGetVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface IndexesGetVersionDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & IndexesGetVersionDefaultHeaders; +} + +/** There is no content to send for this request, but the headers may be useful. */ +export interface IndexesDeleteVersion204Response extends HttpResponse { + status: "204"; +} + +export interface IndexesDeleteVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface IndexesDeleteVersionDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & IndexesDeleteVersionDefaultHeaders; +} + +export interface IndexesCreate200Headers { + /** Indicates whether the repeatable request was accepted or rejected. */ + "repeatability-result"?: RepeatabilityResultOutput; + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +/** The request has succeeded. */ +export interface IndexesCreate200Response extends HttpResponse { + status: "200"; + body: IndexOutput; + headers: RawHttpHeaders & IndexesCreate200Headers; +} + +export interface IndexesCreateDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface IndexesCreateDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & IndexesCreateDefaultHeaders; +} + +/** The request has succeeded. */ +export interface IndexesCreateVersion200Response extends HttpResponse { + status: "200"; + body: IndexOutput; +} + +/** The request has succeeded and a new resource has been created as a result. */ +export interface IndexesCreateVersion201Response extends HttpResponse { + status: "201"; + body: IndexOutput; +} + +export interface IndexesCreateVersionDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface IndexesCreateVersionDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & IndexesCreateVersionDefaultHeaders; +} + +export interface DeploymentsGet200Headers { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +/** The request has succeeded. */ +export interface DeploymentsGet200Response extends HttpResponse { + status: "200"; + body: DeploymentOutput; + headers: RawHttpHeaders & DeploymentsGet200Headers; +} + +export interface DeploymentsGetDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DeploymentsGetDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DeploymentsGetDefaultHeaders; +} + +export interface DeploymentsList200Headers { + /** An opaque, globally-unique, client-generated string identifier for the request. */ + "x-ms-client-request-id"?: string; +} + +/** The request has succeeded. */ +export interface DeploymentsList200Response extends HttpResponse { + status: "200"; + body: PagedDeploymentOutput; + headers: RawHttpHeaders & DeploymentsList200Headers; +} + +export interface DeploymentsListDefaultHeaders { + /** String error code indicating what went wrong. */ + "x-ms-error-code"?: string; +} + +export interface DeploymentsListDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponse; + headers: RawHttpHeaders & DeploymentsListDefaultHeaders; +} diff --git a/sdk/ai/ai-projects-1dp/test/public/sampleTest.spec.ts b/sdk/ai/ai-projects-1dp/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..d4919ac91ac5 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/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/ai/ai-projects-1dp/test/public/utils/recordedClient.ts b/sdk/ai/ai-projects-1dp/test/public/utils/recordedClient.ts new file mode 100644 index 000000000000..6e425fdcfdf9 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/test/public/utils/recordedClient.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + Recorder, + RecorderStartOptions, + VitestTestContext, +} from "@azure-tools/test-recorder"; + +const replaceableVariables: Record = { + SUBSCRIPTION_ID: "azure_subscription_id", +}; + +const recorderEnvSetup: RecorderStartOptions = { + envSetupForPlayback: replaceableVariables, +}; + +/** + * creates the recorder and reads the environment variables from the `.env` file. + * 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: VitestTestContext, +): Promise { + const recorder = new Recorder(context); + await recorder.start(recorderEnvSetup); + return recorder; +} diff --git a/sdk/ai/ai-projects-1dp/tsp-location.yaml b/sdk/ai/ai-projects-1dp/tsp-location.yaml new file mode 100644 index 000000000000..8dfd9a5f62f9 --- /dev/null +++ b/sdk/ai/ai-projects-1dp/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/ai/Azure.AI.Projects +commit: 189e6ecaef7f18cbc5bb453ab9752cf0b03234bb +repo: /mnt/vss/_work/1/s/azure-rest-api-specs +additionalDirectories: