セッション Python プラグイン移行ガイド - 2025 年 5 月

SessionsPythonPluginは、Azure Code インタープリター動的セッション API の最新バージョン (2024-10-02-preview) を使用するように更新されました。 新しい API では、プラグインのパブリック API サーフェスに反映される破壊的変更が導入されました。

この移行ガイドは、既存のコードを最新バージョンのプラグインに移行するのに役立ちます。

プラグインの初期化

プラグイン コンストラクターシグネチャが、CancellationToken関数の引数としてauthTokenProviderを受け入れるように変更されました。 この変更により、必要に応じてトークン生成プロセスを取り消すことができます。

// Before
static async Task<string> GetAuthTokenAsync()
{
    return tokenProvider.GetToken();
}

// After
static async Task<string> GetAuthTokenAsync(CancellationToken ct)
{
    return tokenProvider.GetToken(ct);
}

var plugin = new SessionsPythonPlugin(settings, httpClientFactory, GetAuthTokenAsync);

UploadFileAsync メソッド

UploadFileAsync メソッドシグネチャは、パラメーターの目的をより適切に表すために変更されました。

// Before
string remoteFilePath = "your_file.txt";
string? localFilePath = "C:\documents\your_file.txt";

await plugin.UploadFileAsync(remoteFilePath: remoteFilePath, localFilePath: localFilePath);

// After
string remoteFileName = "your_file.txt";
string localFilePath = "C:\documents\your_file.txt";

await plugin.UploadFileAsync(remoteFileName: remoteFileName, localFilePath: localFilePath);

DownloadFileAsync メソッド

同様に、 DownloadFileAsync メソッドシグネチャは、パラメーターの目的をより適切に表すために変更されました。

// Before
string remoteFilePath = "your_file.txt";
await plugin.DownloadFileAsync(remoteFilePath: remoteFilePath);

// After
string remoteFileName = "your_file.txt";
await plugin.DownloadFileAsync(remoteFileName: remoteFileName);

ExecuteCodeAsync メソッド

ExecuteCodeAsync メソッドシグネチャは、実行結果を操作するための構造化された方法を提供するように変更されました。

// Before
string result = await plugin.ExecuteCodeAsync(code: "print('Hello, world!')");

// After
SessionsPythonCodeExecutionResult result = await plugin.ExecuteCodeAsync(code: "print('Hello, world!')");
string status = result.Status;
string? executionResult = result.Result?.ExecutionResult;
string? stdout = result.Result?.StdOut;
string? stderr = result.Result?.StdErr;

SessionsRemoteFileMetadata クラス

SessionsRemoteFileMetadataメソッドとUploadFileAsync メソッドで使用される ListFilesAsync モデル クラスは、リモート ファイルとディレクトリのメタデータをより適切に表すように更新されました。

// Before
SessionsRemoteFileMetadata file = await plugin.UploadFileAsync(...);
string fileName = file.Filename;
long fileSize = file.Size;
DateTime? lastModified = file.LastModifiedTime;

// After
SessionsRemoteFileMetadata file = await plugin.UploadFileAsync(...);
string name = file.Name;
long? size = file.SizeInBytes;
DateTime lastModified = file.LastModifiedAt;