Implemented the transcription API (#623)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-01-11 16:02:28 +01:00
1 parent b94614b0ab
commit 529986837e
42 files changed
+700 -138

No files matched your search

@@ -8,6 +8,68 @@ public class Builder
public static Builder Create() => new();
public static MIMEType FromFilename(string filenameOrPath)
{
var extension = Path.GetExtension(filenameOrPath);
if (string.IsNullOrEmpty(extension))
throw new ArgumentException("Filename or path does not have a valid extension.", nameof(filenameOrPath));
extension = extension.TrimStart('.').ToLowerInvariant();
var builder = Create();
return extension switch
{
// Application types
"pdf" => builder.UseApplication().UseSubtype(ApplicationSubtype.PDF).Build(),
"zip" => builder.UseApplication().UseSubtype(ApplicationSubtype.ZIP).Build(),
"doc" => builder.UseApplication().UseSubtype(ApplicationSubtype.WORD_OLD).Build(),
"docx" => builder.UseApplication().UseSubtype(ApplicationSubtype.WORD).Build(),
"xls" => builder.UseApplication().UseSubtype(ApplicationSubtype.EXCEL_OLD).Build(),
"xlsx" => builder.UseApplication().UseSubtype(ApplicationSubtype.EXCEL).Build(),
"ppt" => builder.UseApplication().UseSubtype(ApplicationSubtype.POWERPOINT_OLD).Build(),
"pptx" => builder.UseApplication().UseSubtype(ApplicationSubtype.POWERPOINT).Build(),
"json" => builder.UseApplication().UseSubtype(ApplicationSubtype.JSON).Build(),
"xml" => builder.UseApplication().UseSubtype(ApplicationSubtype.XML).Build(),
// Text types
"txt" => builder.UseText().UseSubtype(TextSubtype.PLAIN).Build(),
"html" or "htm" => builder.UseText().UseSubtype(TextSubtype.HTML).Build(),
"css" => builder.UseText().UseSubtype(TextSubtype.CSS).Build(),
"csv" => builder.UseText().UseSubtype(TextSubtype.CSV).Build(),
"js" => builder.UseText().UseSubtype(TextSubtype.JAVASCRIPT).Build(),
"md" or "markdown" => builder.UseText().UseSubtype(TextSubtype.MARKDOWN).Build(),
// Audio types
"wav" => builder.UseAudio().UseSubtype(AudioSubtype.WAV).Build(),
"mp3" => builder.UseAudio().UseSubtype(AudioSubtype.MP3).Build(),
"ogg" => builder.UseAudio().UseSubtype(AudioSubtype.OGG).Build(),
"aac" => builder.UseAudio().UseSubtype(AudioSubtype.AAC).Build(),
"flac" => builder.UseAudio().UseSubtype(AudioSubtype.FLAC).Build(),
"m4a" => builder.UseAudio().UseSubtype(AudioSubtype.M4A).Build(),
"aiff" or "aif" => builder.UseAudio().UseSubtype(AudioSubtype.AIFF).Build(),
"mpga" => builder.UseAudio().UseSubtype(AudioSubtype.MPEG).Build(),
"webm" => builder.UseAudio().UseSubtype(AudioSubtype.WEBM).Build(),
// Image types
"jpg" or "jpeg" => builder.UseImage().UseSubtype(ImageSubtype.JPEG).Build(),
"png" => builder.UseImage().UseSubtype(ImageSubtype.PNG).Build(),
"gif" => builder.UseImage().UseSubtype(ImageSubtype.GIF).Build(),
"tiff" or "tif" => builder.UseImage().UseSubtype(ImageSubtype.TIFF).Build(),
"webp" => builder.UseImage().UseSubtype(ImageSubtype.WEBP).Build(),
"svg" => builder.UseImage().UseSubtype(ImageSubtype.SVG).Build(),
"heic" => builder.UseImage().UseSubtype(ImageSubtype.HEIC).Build(),
// Video types
"mp4" => builder.UseVideo().UseSubtype(VideoSubtype.MP4).Build(),
"avi" => builder.UseVideo().UseSubtype(VideoSubtype.AVI).Build(),
"mov" => builder.UseVideo().UseSubtype(VideoSubtype.MOV).Build(),
"mkv" => builder.UseVideo().UseSubtype(VideoSubtype.MKV).Build(),
"mpeg" or "mpg" => builder.UseVideo().UseSubtype(VideoSubtype.MPEG).Build(),
_ => throw new ArgumentException($"Unsupported file extension: '.{extension}'.", nameof(filenameOrPath))
};
}
public static MIMEType FromTextRepresentation(string textRepresentation)
{
var parts = textRepresentation.Split('/');
@@ -0,0 +1,32 @@
namespace AIStudio.Tools;
/// <summary>
/// Represents the type of secret store used for API keys.
/// </summary>
/// <remarks>
/// Different provider types use different prefixes for storing API keys.
/// This prevents collisions when the same instance name is used across
/// different provider types (e.g., LLM, Embedding, Transcription).
/// </remarks>
public enum SecretStoreType
{
/// <summary>
/// LLM provider secrets. Uses the legacy "provider::" prefix for backward compatibility.
/// </summary>
LLM_PROVIDER = 0,
/// <summary>
/// Embedding provider secrets. Uses the "embedding::" prefix.
/// </summary>
EMBEDDING_PROVIDER,
/// <summary>
/// Transcription provider secrets. Uses the "transcription::" prefix.
/// </summary>
TRANSCRIPTION_PROVIDER,
/// <summary>
/// Image provider secrets. Uses the "image::" prefix.
/// </summary>
IMAGE_PROVIDER,
}
@@ -0,0 +1,21 @@
namespace AIStudio.Tools;
public static class SecretStoreTypeExtensions
{
/// <summary>
/// Gets the prefix string associated with the SecretStoreType.
/// </summary>
/// <remarks>
/// LLM_PROVIDER uses the legacy "provider" prefix for backward compatibility.
/// </remarks>
/// <param name="type">The SecretStoreType enum value.</param>
/// <returns>>The corresponding prefix string.</returns>
public static string Prefix(this SecretStoreType type) => type switch
{
SecretStoreType.LLM_PROVIDER => "provider",
SecretStoreType.EMBEDDING_PROVIDER => "embedding",
SecretStoreType.TRANSCRIPTION_PROVIDER => "transcription",
_ => "provider",
};
}
@@ -9,68 +9,76 @@ public sealed partial class RustService
/// </summary>
/// <param name="secretId">The secret ID to get the API key for.</param>
/// <param name="isTrying">Indicates if we are trying to get the API key. In that case, we don't log errors.</param>
/// <param name="storeType">The secret store type. Defaults to LLM_PROVIDER for backward compatibility.</param>
/// <returns>The requested secret.</returns>
public async Task<RequestedSecret> GetAPIKey(ISecretId secretId, bool isTrying = false)
public async Task<RequestedSecret> GetAPIKey(ISecretId secretId, SecretStoreType storeType, bool isTrying = false)
{
var secretRequest = new SelectSecretRequest($"provider::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, isTrying);
var prefix = storeType.Prefix();
var secretRequest = new SelectSecretRequest($"{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, isTrying);
var result = await this.http.PostAsJsonAsync("/secrets/get", secretRequest, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
if(!isTrying)
this.logger!.LogError($"Failed to get the API key for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
this.logger!.LogError($"Failed to get the API key for '{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key' due to an API issue: '{result.StatusCode}'");
return new RequestedSecret(false, new EncryptedText(string.Empty), TB("Failed to get the API key due to an API issue."));
}
var secret = await result.Content.ReadFromJsonAsync<RequestedSecret>(this.jsonRustSerializerOptions);
if (!secret.Success && !isTrying)
this.logger!.LogError($"Failed to get the API key for secret ID '{secretId.SecretId}': '{secret.Issue}'");
this.logger!.LogError($"Failed to get the API key for '{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key': '{secret.Issue}'");
this.logger!.LogDebug($"Successfully retrieved the API key for '{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key'.");
return secret;
}
/// <summary>
/// Try to store the API key for the given secret ID.
/// </summary>
/// <param name="secretId">The secret ID to store the API key for.</param>
/// <param name="key">The API key to store.</param>
/// <param name="storeType">The secret store type. Defaults to LLM_PROVIDER for backward compatibility.</param>
/// <returns>The store secret response.</returns>
public async Task<StoreSecretResponse> SetAPIKey(ISecretId secretId, string key)
public async Task<StoreSecretResponse> SetAPIKey(ISecretId secretId, string key, SecretStoreType storeType)
{
var prefix = storeType.Prefix();
var encryptedKey = await this.encryptor!.Encrypt(key);
var request = new StoreSecretRequest($"provider::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, encryptedKey);
var request = new StoreSecretRequest($"{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, encryptedKey);
var result = await this.http.PostAsJsonAsync("/secrets/store", request, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to store the API key for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
this.logger!.LogError($"Failed to store the API key for '{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key' due to an API issue: '{result.StatusCode}'");
return new StoreSecretResponse(false, TB("Failed to get the API key due to an API issue."));
}
var state = await result.Content.ReadFromJsonAsync<StoreSecretResponse>(this.jsonRustSerializerOptions);
if (!state.Success)
this.logger!.LogError($"Failed to store the API key for secret ID '{secretId.SecretId}': '{state.Issue}'");
this.logger!.LogError($"Failed to store the API key for '{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key': '{state.Issue}'");
this.logger!.LogDebug($"Successfully stored the API key for '{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key'.");
return state;
}
/// <summary>
/// Tries to delete the API key for the given secret ID.
/// </summary>
/// <param name="secretId">The secret ID to delete the API key for.</param>
/// <param name="storeType">The secret store type. Defaults to LLM_PROVIDER for backward compatibility.</param>
/// <returns>The delete secret response.</returns>
public async Task<DeleteSecretResponse> DeleteAPIKey(ISecretId secretId)
public async Task<DeleteSecretResponse> DeleteAPIKey(ISecretId secretId, SecretStoreType storeType)
{
var request = new SelectSecretRequest($"provider::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, false);
var prefix = storeType.Prefix();
var request = new SelectSecretRequest($"{prefix}::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, false);
var result = await this.http.PostAsJsonAsync("/secrets/delete", request, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to delete the API key for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new DeleteSecretResponse{Success = false, WasEntryFound = false, Issue = TB("Failed to delete the API key due to an API issue.")};
}
var state = await result.Content.ReadFromJsonAsync<DeleteSecretResponse>(this.jsonRustSerializerOptions);
if (!state.Success)
this.logger!.LogError($"Failed to delete the API key for secret ID '{secretId.SecretId}': '{state.Issue}'");
return state;
}
}