Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Abstractions" Version="1.1.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="10.0.0" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.14" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static void OkLine(this IAnsiConsole console, string message)

public static void ErrorLine(this IAnsiConsole console, string message)
{
// TODO: This needs to write to stderr
console.MarkupLine(Glyphs.Cross.Space() + message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static async Task<int> RenderInteractiveAsync(
IApiClient client,
CancellationToken ct)
{
const string apiMessage = "For which client do you want to list the clients?";
const string apiMessage = "For which API do you want to list the clients?";
var apiId = await context.GetOrSelectApiId(apiMessage);

var container = PaginationContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async Task PublishClient(StatusContext? ctx)
break;

case IClientVersionPublishFailed { Errors: var clientErrors }:
console.Error.WriteLine("Client publish failed");
console.ErrorLine("Client publish failed");
console.PrintErrorsAndExit(clientErrors);
stopSignal.OnNext(Unit.Default);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async Task ValidateClient(StatusContext? ctx)
switch (x.Data?.OnClientVersionValidationUpdate)
{
case IClientVersionValidationFailed { Errors: var schemaErrors }:
console.Error.WriteLine("The client is invalid:");
console.ErrorLine("The client is invalid:");
console.PrintErrorsAndExit(schemaErrors);
stopSignal.OnNext(Unit.Default);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ await FusionPublishHelpers.ReleaseDeploymentSlot(
}
catch (Exception exception)
{
console.Error.WriteLine(exception.Message);
console.ErrorLine(exception.Message);

if (!string.IsNullOrEmpty(requestId))
{
Expand Down Expand Up @@ -330,7 +330,7 @@ async Task<bool> ComposeAsync(Stream archiveStream, Stream? existingConfiguratio
{
foreach (var error in result.Errors)
{
console.Error.WriteLine(error.Message);
console.ErrorLine(error.Message);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async Task ValidateSchema(StatusContext? ctx)
switch (x.Data?.OnSchemaVersionValidationUpdate)
{
case ISchemaVersionValidationFailed { Errors: var schemaErrors }:
console.Error.WriteLine("The schema is invalid:");
console.ErrorLine("The schema is invalid:");
console.PrintErrorsAndExit(schemaErrors);
stopSignal.OnNext(Unit.Default);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async Task<int> ValidateAsync(StatusContext? ctx)
return ExitCodes.Success;
}

console.Error.WriteLine("The validation failed:");
console.ErrorLine("The validation failed:");
if (failed is not null)
{
console.PrintErrorsAndExit(failed.Errors);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using ChilliCream.Nitro.CommandLine.Client;

namespace ChilliCream.Nitro.CommandLine.Commands.Mcp.Components;

internal sealed class McpFeatureCollectionDetailPrompt
{
private readonly IMcpFeatureCollectionDetailPrompt_McpFeatureCollection _data;

private McpFeatureCollectionDetailPrompt(IMcpFeatureCollectionDetailPrompt_McpFeatureCollection data)
{
_data = data;
}

public McpFeatureCollectionDetailPromptResult ToObject(string[] formats)
{
return new McpFeatureCollectionDetailPromptResult
{
Id = _data.Id,
Name = _data.Name
};
}

public static McpFeatureCollectionDetailPrompt From(IMcpFeatureCollectionDetailPrompt_McpFeatureCollection data) => new(data);

public class McpFeatureCollectionDetailPromptResult
{
public required string Id { get; init; }

public required string Name { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fragment McpFeatureCollectionDetailPrompt_McpFeatureCollection on McpFeatureCollection {
id
name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ChilliCream.Nitro.CommandLine.Client;
using ChilliCream.Nitro.CommandLine.Helpers;

namespace ChilliCream.Nitro.CommandLine.Commands.Mcp.Components;

public sealed class SelectMcpFeatureCollectionPrompt(IApiClient client, string apiId)
{
private string _title = "Select an MCP Feature Collection from the list below.";

public SelectMcpFeatureCollectionPrompt Title(string title)
{
_title = title;
return this;
}

public async Task<ISelectMcpFeatureCollectionPrompt_McpFeatureCollection?> RenderAsync(
IAnsiConsole console,
CancellationToken cancellationToken)
{
var paginationContainer = PaginationContainer.Create(
(after, first, ct)
=> client.SelectMcpFeatureCollectionPromptQuery.ExecuteAsync(apiId, after, first, ct),
p => p.ApiById?.McpFeatureCollections?.PageInfo,
p => p.ApiById?.McpFeatureCollections?.Edges);

var selectedEdge = await PagedSelectionPrompt
.New(paginationContainer)
.Title(_title)
.UseConverter(x => x.Node.Name)
.RenderAsync(console, cancellationToken);

return selectedEdge?.Node;
}

public static SelectMcpFeatureCollectionPrompt New(IApiClient client, string apiId)
=> new(client, apiId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
query SelectMcpFeatureCollectionPromptQuery($apiId: ID!, $after: String, $first: Int) {
apiById(id: $apiId) {
mcpFeatureCollections(after: $after, first: $first) {
edges {
...SelectMcpFeatureCollectionPrompt_McpFeatureCollectionEdge
}
pageInfo {
...PageInfo
}
}
}
}

fragment SelectMcpFeatureCollectionPrompt_McpFeatureCollectionEdge on ApiMcpFeatureCollectionsEdge {
cursor
node {
...SelectMcpFeatureCollectionPrompt_McpFeatureCollection
}
}

fragment SelectMcpFeatureCollectionPrompt_McpFeatureCollection on McpFeatureCollection {
id
name
...McpFeatureCollectionDetailPrompt_McpFeatureCollection
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.CommandLine.Invocation;
using ChilliCream.Nitro.CommandLine.Client;
using ChilliCream.Nitro.CommandLine.Commands.Apis.Inputs;
using ChilliCream.Nitro.CommandLine.Commands.Mcp.Components;
using ChilliCream.Nitro.CommandLine.Commands.Mcp.Options;
using ChilliCream.Nitro.CommandLine.Configuration;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Options;
using ChilliCream.Nitro.CommandLine.Results;
using static ChilliCream.Nitro.CommandLine.ThrowHelper;

namespace ChilliCream.Nitro.CommandLine.Commands.Mcp;

internal sealed class CreateMcpFeatureCollectionCommand : Command
{
public CreateMcpFeatureCollectionCommand() : base("create")
{
Description = "Creates a new MCP Feature Collection";

AddOption(Opt<OptionalApiIdOption>.Instance);
AddOption(Opt<McpFeatureCollectionNameOption>.Instance);

this.SetHandler(
ExecuteAsync,
Bind.FromServiceProvider<InvocationContext>(),
Bind.FromServiceProvider<IAnsiConsole>(),
Bind.FromServiceProvider<IApiClient>(),
Bind.FromServiceProvider<CancellationToken>());
}

private static async Task<int> ExecuteAsync(
InvocationContext context,
IAnsiConsole console,
IApiClient client,
CancellationToken cancellationToken)
{
console.WriteLine();
console.WriteLine("Creating an MCP Feature Collection");
console.WriteLine();

const string apiMessage = "For which api do you want to create an MCP Feature Collection?";
var apiId = await context.GetOrSelectApiId(apiMessage);

var name = await context
.OptionOrAskAsync("Name", Opt<McpFeatureCollectionNameOption>.Instance, cancellationToken);

var input = new CreateMcpFeatureCollectionInput { Name = name, ApiId = apiId };
var result =
await client.CreateMcpFeatureCollectionCommandMutation.ExecuteAsync(input, cancellationToken);

console.EnsureNoErrors(result);
var data = console.EnsureData(result);
console.PrintErrorsAndExit(data.CreateMcpFeatureCollection.Errors);

var createdMcpFeatureCollection = data.CreateMcpFeatureCollection.McpFeatureCollection;
if (createdMcpFeatureCollection is null)
{
throw Exit("Could not create MCP Feature Collection.");
}

console.OkLine($"MCP Feature Collection {createdMcpFeatureCollection.Name.AsHighlight()} created.");

if (createdMcpFeatureCollection is IMcpFeatureCollectionDetailPrompt_McpFeatureCollection detail)
{
context.SetResult(McpFeatureCollectionDetailPrompt.From(detail).ToObject([]));
}

return ExitCodes.Success;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mutation CreateMcpFeatureCollectionCommandMutation($input: CreateMcpFeatureCollectionInput!) {
createMcpFeatureCollection(input: $input) {
mcpFeatureCollection {
...CreateMcpFeatureCollectionCommandMutation_McpFeatureCollection
}
errors {
...Error
...ApiNotFoundError
...UnauthorizedOperation
}
}
}

fragment CreateMcpFeatureCollectionCommandMutation_McpFeatureCollection on McpFeatureCollection {
name
id
...McpFeatureCollectionDetailPrompt_McpFeatureCollection
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.CommandLine.Invocation;
using ChilliCream.Nitro.CommandLine.Arguments;
using ChilliCream.Nitro.CommandLine.Client;
using ChilliCream.Nitro.CommandLine.Commands.Apis.Components;
using ChilliCream.Nitro.CommandLine.Commands.Mcp.Components;
using ChilliCream.Nitro.CommandLine.Configuration;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Options;
using ChilliCream.Nitro.CommandLine.Results;
using ChilliCream.Nitro.CommandLine.Services.Sessions;
using static ChilliCream.Nitro.CommandLine.ThrowHelper;

namespace ChilliCream.Nitro.CommandLine.Commands.Mcp;

internal sealed class DeleteMcpFeatureCollectionCommand : Command
{
public DeleteMcpFeatureCollectionCommand() : base("delete")
{
Description = "Deletes an MCP Feature Collection";

AddOption(Opt<ForceOption>.Instance);
AddArgument(Opt<OptionalIdArgument>.Instance);

this.SetHandler(
ExecuteAsync,
Bind.FromServiceProvider<InvocationContext>(),
Bind.FromServiceProvider<IAnsiConsole>(),
Bind.FromServiceProvider<IApiClient>(),
Opt<OptionalIdArgument>.Instance,
Bind.FromServiceProvider<CancellationToken>());
}

private static async Task<int> ExecuteAsync(
InvocationContext context,
IAnsiConsole console,
IApiClient client,
string? mcpFeatureCollectionId,
CancellationToken cancellationToken)
{
console.WriteLine();
console.WriteLine("Deleting an MCP Feature Collection");
console.WriteLine();

const string apiMessage = "For which api do you want to delete an MCP Feature Collection?";
const string mcpFeatureCollectionMessage = "Which MCP Feature Collection do you want to delete?";

if (mcpFeatureCollectionId is null)
{
if (!console.IsHumanReadable())
{
throw Exit("The MCP Feature Collection id is required in non-interactive mode.");
}

var workspaceId = context.RequireWorkspaceId();

var selectedApi = await SelectApiPrompt
.New(client, workspaceId)
.Title(apiMessage)
.RenderAsync(console, cancellationToken) ?? throw NoApiSelected();

var apiId = selectedApi.Id;

var selectedMcpFeatureCollection = await SelectMcpFeatureCollectionPrompt
.New(client, apiId)
.Title(mcpFeatureCollectionMessage)
.RenderAsync(console, cancellationToken) ?? throw NoMcpFeatureCollectionSelected();

console.WriteLine("Selected MCP Feature Collection: " + selectedMcpFeatureCollection.Name);

mcpFeatureCollectionId = selectedMcpFeatureCollection.Id;
console.OkQuestion(mcpFeatureCollectionMessage, mcpFeatureCollectionId);
}
else
{
console.OkQuestion(mcpFeatureCollectionMessage, mcpFeatureCollectionId);
}

var shouldDelete = await context.ConfirmWhenNotForced(
$"Do you want to delete the MCP Feature Collection with the id {mcpFeatureCollectionId}?"
.EscapeMarkup(),
cancellationToken);

if (!shouldDelete)
{
console.OkLine("Aborted.");
return ExitCodes.Success;
}

var input = new DeleteMcpFeatureCollectionByIdInput { McpFeatureCollectionId = mcpFeatureCollectionId };
var result =
await client.DeleteMcpFeatureCollectionByIdCommandMutation.ExecuteAsync(input, cancellationToken);

console.EnsureNoErrors(result);
var data = console.EnsureData(result);
console.PrintErrorsAndExit(data.DeleteMcpFeatureCollectionById.Errors);

var deletedMcpFeatureCollection = data.DeleteMcpFeatureCollectionById.McpFeatureCollection;
if (deletedMcpFeatureCollection is null)
{
throw Exit("Could not delete the MCP Feature Collection.");
}

console.OkLine($"MCP Feature Collection {deletedMcpFeatureCollection.Name.AsHighlight()} was deleted.");

if (deletedMcpFeatureCollection is IMcpFeatureCollectionDetailPrompt_McpFeatureCollection detail)
{
context.SetResult(McpFeatureCollectionDetailPrompt.From(detail).ToObject([]));
}

return ExitCodes.Success;
}
}
Loading
Loading