Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Add new POST endpoint for executing workflows in AI21 Studio API #84

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@

#nullable enable

namespace AI21
{
public partial class Ai21Api
{
partial void PrepareRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostArguments(
global::System.Net.Http.HttpClient httpClient,
ref string organizationId,
ref string dataSource,
ref string workflowName,
ref int? requestStartTime);
partial void PrepareRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string organizationId,
string dataSource,
string workflowName,
int? requestStartTime);
partial void ProcessRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Run Workflow
/// </summary>
/// <param name="organizationId"></param>
/// <param name="dataSource"></param>
/// <param name="workflowName"></param>
/// <param name="requestStartTime">
/// Default Value: 1730898900272
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::AI21.ApiException"></exception>
public async global::System.Threading.Tasks.Task<string> RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostAsync(
string organizationId,
string dataSource,
string workflowName,
int? requestStartTime = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
client: HttpClient);
PrepareRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostArguments(
httpClient: HttpClient,
organizationId: ref organizationId,
dataSource: ref dataSource,
workflowName: ref workflowName,
requestStartTime: ref requestStartTime);

var __pathBuilder = new PathBuilder(
path: $"/studio/v1/connectors/connected-users/{organizationId}/data-sources/{dataSource}/workflows/{workflowName}/run",
baseUri: HttpClient.BaseAddress);
__pathBuilder
.AddOptionalParameter("request_start_time", requestStartTime?.ToString())
;
var __path = __pathBuilder.ToString();
using var __httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));
#if NET6_0_OR_GREATER
__httpRequest.Version = global::System.Net.HttpVersion.Version11;
__httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher;
#endif

foreach (var __authorization in Authorizations)
{
if (__authorization.Type == "Http" ||
__authorization.Type == "OAuth2")
{
__httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: __authorization.Name,
parameter: __authorization.Value);
}
else if (__authorization.Type == "ApiKey" &&
__authorization.Location == "Header")
{
__httpRequest.Headers.Add(__authorization.Name, __authorization.Value);
}
}

PrepareRequest(
client: HttpClient,
request: __httpRequest);
PrepareRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostRequest(
httpClient: HttpClient,
httpRequestMessage: __httpRequest,
organizationId: organizationId,
dataSource: dataSource,
workflowName: workflowName,
requestStartTime: requestStartTime);

using var __response = await HttpClient.SendAsync(
request: __httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: HttpClient,
response: __response);
ProcessRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse(
httpClient: HttpClient,
httpResponseMessage: __response);
// Validation Error
if ((int)__response.StatusCode == 422)
{
string? __content_422 = null;
global::AI21.HTTPValidationError? __value_422 = null;
if (ReadResponseAsString)
{
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
__value_422 = global::AI21.HTTPValidationError.FromJson(__content_422, JsonSerializerContext);
}
else
{
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
__value_422 = await global::AI21.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerContext).ConfigureAwait(false);
}

throw new global::AI21.ApiException<global::AI21.HTTPValidationError>(
message: __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_422,
ResponseObject = __value_422,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

if (ReadResponseAsString)
{
var __content = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

ProcessResponseContent(
client: HttpClient,
response: __response,
content: ref __content);
ProcessRunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponseContent(
httpClient: HttpClient,
httpResponseMessage: __response,
content: ref __content);

try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::AI21.ApiException(
message: __content ?? __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseBody = __content,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

return __content;
}
else
{
try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::AI21.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

var __content = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

return __content;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#nullable enable

namespace AI21
{
public partial interface IAi21Api
{
/// <summary>
/// Run Workflow
/// </summary>
/// <param name="organizationId"></param>
/// <param name="dataSource"></param>
/// <param name="workflowName"></param>
/// <param name="requestStartTime">
/// Default Value: 1730898900272
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::AI21.ApiException"></exception>
global::System.Threading.Tasks.Task<string> RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostAsync(
string organizationId,
string dataSource,
string workflowName,
int? requestStartTime = default,
global::System.Threading.CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#nullable enable

namespace AI21
{
public sealed partial class RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse
{
/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
/// </summary>
public string ToJson(
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
this.GetType(),
jsonSerializerContext);
}

/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public string ToJson(
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerContext.
/// </summary>
public static global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse? FromJson(
string json,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Deserialize(
json,
typeof(global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse),
jsonSerializerContext) as global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse;
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse? FromJson(
string json,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Deserialize<global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerContext.
/// </summary>
public static async global::System.Threading.Tasks.ValueTask<global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
jsonStream,
typeof(global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse),
jsonSerializerContext).ConfigureAwait(false)) as global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse;
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::System.Threading.Tasks.ValueTask<global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::AI21.RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse?>(
jsonStream,
jsonSerializerOptions);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#nullable enable

namespace AI21
{
/// <summary>
///
/// </summary>
public sealed partial class RunWorkflowStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceWorkflowsWorkflowNameRunPostResponse
{

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::System.Text.Json.Serialization.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
41 changes: 41 additions & 0 deletions src/libs/AI21/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,47 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
'/studio/v1/connectors/connected-users/{organization_id}/data-sources/{data_source}/workflows/{workflow_name}/run':
post:
summary: Run Workflow
operationId: run_workflow_studio_v1_connectors_connected_users__organization_id__data_sources__data_source__workflows__workflow_name__run_post
parameters:
- name: organization_id
in: path
required: true
schema:
title: Organization Id
type: string
- name: data_source
in: path
required: true
schema:
title: Data Source
type: string
- name: workflow_name
in: path
required: true
schema:
title: Workflow Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
Comment on lines +555 to +595
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Enhance endpoint documentation and schema definitions.

The new workflow execution endpoint needs additional documentation and schema definitions:

  1. Add a description field explaining the endpoint's purpose and behavior
  2. Define the request body schema for the POST method
  3. Define a proper response schema instead of an empty object
  4. Add common error responses (400, 401, 403, 500)

Apply this diff to enhance the endpoint definition:

  '/studio/v1/connectors/connected-users/{organization_id}/data-sources/{data_source}/workflows/{workflow_name}/run':
    post:
      summary: Run Workflow
+     description: |
+       Execute a specific workflow for the given organization and data source.
+       This endpoint allows triggering automated workflows associated with connected data sources.
      operationId: run_workflow_studio_v1_connectors_connected_users__organization_id__data_sources__data_source__workflows__workflow_name__run_post
      parameters:
        - name: organization_id
          in: path
          required: true
          schema:
            title: Organization Id
            type: string
+         description: Unique identifier of the organization
        - name: data_source
          in: path
          required: true
          schema:
            title: Data Source
            type: string
+         description: Identifier of the data source
        - name: workflow_name
          in: path
          required: true
          schema:
            title: Workflow Name
            type: string
+         description: Name of the workflow to execute
        - name: request_start_time
          in: query
          schema:
            title: Request Start Time
            type: integer
            default: '1730898900272'
+     requestBody:
+       required: true
+       content:
+         application/json:
+           schema:
+             type: object
+             properties:
+               parameters:
+                 type: object
+                 description: Optional parameters for the workflow
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
+               type: object
+               required:
+                 - workflow_id
+                 - status
+               properties:
+                 workflow_id:
+                   type: string
+                   description: Unique identifier of the workflow execution
+                 status:
+                   type: string
+                   enum: [STARTED, COMPLETED]
+                   description: Current status of the workflow
        '400':
+         description: Bad Request
+         content:
+           application/json:
+             schema:
+               $ref: '#/components/schemas/HTTPValidationError'
+       '401':
+         description: Unauthorized
+       '403':
+         description: Forbidden
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
+       '500':
+         description: Internal Server Error
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'/studio/v1/connectors/connected-users/{organization_id}/data-sources/{data_source}/workflows/{workflow_name}/run':
post:
summary: Run Workflow
operationId: run_workflow_studio_v1_connectors_connected_users__organization_id__data_sources__data_source__workflows__workflow_name__run_post
parameters:
- name: organization_id
in: path
required: true
schema:
title: Organization Id
type: string
- name: data_source
in: path
required: true
schema:
title: Data Source
type: string
- name: workflow_name
in: path
required: true
schema:
title: Workflow Name
type: string
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
responses:
'200':
description: Successful Response
content:
application/json:
schema: { }
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
'/studio/v1/connectors/connected-users/{organization_id}/data-sources/{data_source}/workflows/{workflow_name}/run':
post:
summary: Run Workflow
description: |
Execute a specific workflow for the given organization and data source.
This endpoint allows triggering automated workflows associated with connected data sources.
operationId: run_workflow_studio_v1_connectors_connected_users__organization_id__data_sources__data_source__workflows__workflow_name__run_post
parameters:
- name: organization_id
in: path
required: true
schema:
title: Organization Id
type: string
description: Unique identifier of the organization
- name: data_source
in: path
required: true
schema:
title: Data Source
type: string
description: Identifier of the data source
- name: workflow_name
in: path
required: true
schema:
title: Workflow Name
type: string
description: Name of the workflow to execute
- name: request_start_time
in: query
schema:
title: Request Start Time
type: integer
default: '1730898900272'
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
parameters:
type: object
description: Optional parameters for the workflow
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: object
required:
- workflow_id
- status
properties:
workflow_id:
type: string
description: Unique identifier of the workflow execution
status:
type: string
enum: [STARTED, COMPLETED]
description: Current status of the workflow
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
'401':
description: Unauthorized
'403':
description: Forbidden
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
'500':
description: Internal Server Error

components:
schemas:
AssistantMessage:
Expand Down
Loading