Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
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
Expand Up @@ -3,15 +3,12 @@

using Microsoft.DotNet.Interactive.Connection;
using Microsoft.DotNet.Interactive.Jupyter.Connection;
using Microsoft.DotNet.Interactive.Jupyter.Http;
using Microsoft.DotNet.Interactive.Jupyter.ZMQ;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Completions;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.Reactive.Disposables;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive.Jupyter;
Expand Down Expand Up @@ -138,82 +135,4 @@ private int GetParseResultHash(ParseResult parseResult)

return (values).GetHashCode();
}
}

public sealed class JupyterLocalKernelConnectionOptions : IJupyterKernelConnectionOptions
{
private static JupyterConnection _currentJupyterConnection;

/// <summary>
/// Represents connection to the kernels in the current environment
/// </summary>
private static JupyterConnection CurrentConnection
{
get
{
_currentJupyterConnection ??= new(new JupyterKernelSpecModule());
return _currentJupyterConnection;
}
}

public IJupyterConnection GetConnection(ParseResult connectionOptionsParseResult)
{
return CurrentConnection;
}

public IReadOnlyCollection<Option> GetOptions()
{
return Array.Empty<Option>();
}
}

public sealed class JupyterHttpKernelConnectionOptions : IJupyterKernelConnectionOptions
{
private readonly IReadOnlyCollection<Option> _options;

public Option<string> TargetUrl { get; } =
new("--url", "URl to connect to the jupyter server")
{
};

public Option<string> Token { get; } =
new("--token", "token to connect to the jupyter server")
{
};

private Option<bool> UseBearerAuth { get; } =
new("--bearer", "auth type is bearer token")
{
};

public JupyterHttpKernelConnectionOptions()
{
_options = new List<Option>
{
TargetUrl,
Token,
UseBearerAuth
};
}

public IJupyterConnection GetConnection(ParseResult connectionOptionsParseResult)
{
var targetUrl = connectionOptionsParseResult.GetValueForOption(TargetUrl);

if (targetUrl is null)
{
return null;
}

var token = connectionOptionsParseResult.GetValueForOption(Token);
var useBearerAuth = connectionOptionsParseResult.GetValueForOption(UseBearerAuth);

var connection = new JupyterHttpConnection(new Uri(targetUrl), new JupyterTokenProvider(token, useBearerAuth ? AuthorizationScheme.Bearer : null));
return connection;
}

public IReadOnlyCollection<Option> GetOptions()
{
return _options;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Parsing;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.DotNet.Interactive.Jupyter.Connection;
using Microsoft.DotNet.Interactive.Jupyter.Http;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Parsing;

namespace Microsoft.DotNet.Interactive.Jupyter;

public sealed class JupyterHttpKernelConnectionOptions : IJupyterKernelConnectionOptions
{
private readonly IReadOnlyCollection<Option> _options;

public Option<string> TargetUrl { get; } =
new("--url", "URl to connect to the jupyter server")
{
};

public Option<string> Token { get; } =
new("--token", "token to connect to the jupyter server")
{
};

private Option<bool> UseBearerAuth { get; } =
new("--bearer", "auth type is bearer token")
{
};

public JupyterHttpKernelConnectionOptions()
{
_options = new List<Option>
{
TargetUrl,
Token,
UseBearerAuth
};
}

public IJupyterConnection GetConnection(ParseResult connectionOptionsParseResult)
{
var targetUrl = connectionOptionsParseResult.GetValueForOption(TargetUrl);

if (targetUrl is null)
{
return null;
}

var token = connectionOptionsParseResult.GetValueForOption(Token);
var useBearerAuth = connectionOptionsParseResult.GetValueForOption(UseBearerAuth);

var connection = new JupyterHttpConnection(new Uri(targetUrl), new JupyterTokenProvider(token, useBearerAuth ? AuthorizationScheme.Bearer : null));
return connection;
}

public IReadOnlyCollection<Option> GetOptions()
{
return _options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.DotNet.Interactive.Jupyter.Connection;
using Microsoft.DotNet.Interactive.Jupyter.ZMQ;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Parsing;

namespace Microsoft.DotNet.Interactive.Jupyter;

public sealed class JupyterLocalKernelConnectionOptions : IJupyterKernelConnectionOptions
{
private static JupyterConnection _currentJupyterConnection;

/// <summary>
/// Represents connection to the kernels in the current environment
/// </summary>
private static JupyterConnection CurrentConnection
{
get
{
_currentJupyterConnection ??= new(new JupyterKernelSpecModule());
return _currentJupyterConnection;
}
}

public IJupyterConnection GetConnection(ParseResult connectionOptionsParseResult)
{
return CurrentConnection;
}

public IReadOnlyCollection<Option> GetOptions()
{
return Array.Empty<Option>();
}
}
42 changes: 6 additions & 36 deletions src/Microsoft.DotNet.Interactive.Jupyter/Protocol/CompleteReply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,24 @@

namespace Microsoft.DotNet.Interactive.Jupyter.Protocol;

public class CompletionResultMetadata
{
[JsonIgnore]
public static string Experimental = "_jupyter_types_experimental";

[JsonPropertyName("end")]
public int End { get; }

[JsonPropertyName("start")]
public int Start { get; }

[JsonPropertyName("type")]
public string Type { get; }

[JsonPropertyName("text")]
public string Text { get; }

[JsonPropertyName("displayText")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string DisplayText { get; }

public CompletionResultMetadata(int start = 0, int end = 0, string text = null, string type = null, string displayText = null)
{
Start = start;
End = end;
Text = text;
Type = type;
DisplayText = displayText;
}
}

[JupyterMessageType(JupyterMessageContentTypes.CompleteReply)]
public class CompleteReply : ReplyMessage
{
[JsonPropertyName("matches")]
public IReadOnlyList<string> Matches { get; }

[JsonPropertyName("cursor_start")]
public int CursorStart { get; }
[JsonPropertyName("cursor_start")]
public int CursorStart { get; }

[JsonPropertyName("cursor_end")]
public int CursorEnd { get; }
[JsonPropertyName("cursor_end")]
public int CursorEnd { get; }

[JsonPropertyName("metadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IReadOnlyDictionary<string, IReadOnlyList<CompletionResultMetadata>> MetaData { get; }

[JsonPropertyName("status")] public string Status { get; }
[JsonPropertyName("status")]
public string Status { get; }

public CompleteReply(int cursorStart = 0, int cursorEnd = 0, IReadOnlyList<string> matches = null, IReadOnlyDictionary<string, IReadOnlyList<CompletionResultMetadata>> metaData = null, string status = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Microsoft.DotNet.Interactive.Jupyter.Protocol;

public class CompletionResultMetadata
{
[JsonIgnore]
public static string Experimental = "_jupyter_types_experimental";

[JsonPropertyName("end")]
public int End { get; }

[JsonPropertyName("start")]
public int Start { get; }

[JsonPropertyName("type")]
public string Type { get; }

[JsonPropertyName("text")]
public string Text { get; }

[JsonPropertyName("displayText")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string DisplayText { get; }

public CompletionResultMetadata(int start = 0, int end = 0, string text = null, string type = null, string displayText = null)
{
Start = start;
End = end;
Text = text;
Type = type;
DisplayText = displayText;
}
}