Skip to content

Commit

Permalink
Update list connections return type (#32093)
Browse files Browse the repository at this point in the history
Co-authored-by: Grace Brigham <[email protected]>
  • Loading branch information
GraceBrigham and Grace Brigham authored Dec 9, 2024
1 parent e9034fa commit 114fa7e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion sdk/ai/ai-projects/review/ai-projects.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export interface ConnectionsOperations {
getConnection: (connectionName: string, requestParams?: OptionalRequestParameters) => Promise<GetConnectionResponseOutput>;
getConnectionWithSecrets: (connectionName: string, requestParams?: OptionalRequestParameters) => Promise<GetConnectionResponseOutput>;
getWorkspace: (requestParams?: OptionalRequestParameters) => Promise<GetWorkspaceResponseOutput>;
listConnections: (options?: ListConnectionsQueryParamProperties, requestParams?: OptionalRequestParameters) => Promise<ListConnectionsResponseOutput>;
listConnections: (options?: ListConnectionsQueryParamProperties, requestParams?: OptionalRequestParameters) => Promise<Array<GetConnectionResponseOutput>>;
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export async function main(): Promise<void> {

// List the details of all the connections
const connections = await client.connections.listConnections();
console.log(`Retrieved ${connections.value.length} connections`);
console.log(`Retrieved ${connections.length} connections`);

// Get the details of a connection, without credentials
const connectionName = connections.value[0].name;
const connectionName = connections[0].name;
const connection = await client.connections.getConnection(connectionName);
console.log(`Retrieved connection, connection name: ${connection.name}`);

Expand Down
6 changes: 3 additions & 3 deletions sdk/ai/ai-projects/src/connections/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { Client, createRestError } from "@azure-rest/core-client";
import { GetConnectionResponseOutput, GetWorkspaceResponseOutput, ListConnectionsResponseOutput } from "./inputOutput.js";
import { GetConnectionResponseOutput, GetWorkspaceResponseOutput } from "./inputOutput.js";
import { GetWorkspaceParameters, GetConnectionParameters, GetConnectionWithSecretsParameters, ListConnectionsParameters } from "../generated/src/parameters.js";

const expectedStatuses = ["200"];
Expand All @@ -23,12 +23,12 @@ export async function getWorkspace(
export async function listConnections(
context: Client,
options?: ListConnectionsParameters
): Promise<ListConnectionsResponseOutput> {
): Promise<Array<GetConnectionResponseOutput>> {
const result = await context.path("/connections").get(options);
if (!expectedStatuses.includes(result.status)) {
throw createRestError(result);
}
return result.body;
return result.body.value;
}

/** Get the details of a single connection, without credentials. */
Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/ai-projects/src/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Client } from "@azure-rest/core-client";
import { OptionalRequestParameters } from "../agents/customModels.js";
import { ListConnectionsQueryParamProperties } from "../generated/src/parameters.js";
import { GetConnectionResponseOutput, GetWorkspaceResponseOutput, ListConnectionsResponseOutput } from "./inputOutput.js";
import { GetConnectionResponseOutput, GetWorkspaceResponseOutput } from "./inputOutput.js";
import { getConnection, getConnectionWithSecrets, getWorkspace, listConnections } from "./connections.js";

export interface ConnectionsOperations {
Expand All @@ -17,7 +17,7 @@ export interface ConnectionsOperations {
listConnections: (
options?: ListConnectionsQueryParamProperties,
requestParams?: OptionalRequestParameters
) => Promise<ListConnectionsResponseOutput>;
) => Promise<Array<GetConnectionResponseOutput>>;
/** Get the details of a single connection, without credentials */
getConnection: (
connectionName: string,
Expand Down
12 changes: 6 additions & 6 deletions sdk/ai/ai-projects/test/public/connections/connections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ describe("Agents - assistants", () => {
// List connections
const connectionsList = await connections.listConnections();
assert.isNotNull(connectionsList);
assert.isAtLeast(connectionsList.value.length, 1);
console.log(`Retrieved ${connectionsList.value.length} connections`);
assert.isAtLeast(connectionsList.length, 1);
console.log(`Retrieved ${connectionsList.length} connections`);
});

it("should retrieve a connection without secrets", async function () {
// List connections
const connectionsList = await connections.listConnections();
assert.isNotNull(connectionsList);
assert.isAtLeast(connectionsList.value.length, 1);
assert.isAtLeast(connectionsList.length, 1);

// Retrieve one connection
for (const _connection of connectionsList.value) {
for (const _connection of connectionsList) {
const connectionName = _connection.name;
const connection = await connections.getConnection(connectionName);
assert.isNotNull(connection);
Expand All @@ -62,10 +62,10 @@ describe("Agents - assistants", () => {
// List connections
const connectionsList = await connections.listConnections();
assert.isNotNull(connectionsList);
assert.isAtLeast(connectionsList.value.length, 1);
assert.isAtLeast(connectionsList.length, 1);

// Retrieve one connection with secrets
for (const _connection of connectionsList.value) {
for (const _connection of connectionsList) {
const connectionName = _connection.name;
const connection = await connections.getConnectionWithSecrets(connectionName);
assert.isNotNull(connection);
Expand Down

0 comments on commit 114fa7e

Please sign in to comment.