Add OpenRouter chat provider; fix Windows load errors (0.17.0).

- OpenRouter as an alternative chat provider: server-side API key
  (settings.json or OPENROUTER_API_KEY), model list with vision marks and
  filter, SSE streaming, images as data URLs. Memory embeddings stay on Ollama;
  park/warm LLM are no-ops for the remote provider.
- AssistentSaveKnowledgeAttach: JArray param is not supported by SwarmUI API
  reflection and aborted registration of every later API call; use string[].
- SQLite bootstrap: preload native e_sqlite3 for the current OS/arch
  (win/osx/linux) and resolve DllImport to it.
- settings.json: shared-read + atomic write with retry to avoid Windows
  sharing violations.
- csproj: fix MSB4012 in the native SQLite copy target.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
mrleo1nid
2026-09-17 06:18:47 +03:00
co-authored by Claude Opus 5
parent f2b92e96ca
commit d67f5e396e
13 changed files with 740 additions and 56 deletions
+44 -9
View File
@@ -35,14 +35,7 @@ internal static class AssistentSqliteBootstrap
{
return;
}
string[] relPaths =
[
Path.Combine("runtimes", "linux-x64", "native", "libe_sqlite3.so"),
Path.Combine("runtimes", "linux-x64", "native", "e_sqlite3.so"),
"libe_sqlite3.so",
"e_sqlite3.so",
];
foreach (string rel in relPaths)
foreach (string rel in CandidatePaths())
{
string path = Path.Combine(extDir, rel);
if (!File.Exists(path))
@@ -51,7 +44,8 @@ internal static class AssistentSqliteBootstrap
}
try
{
NativeLibrary.Load(path);
IntPtr handle = NativeLibrary.Load(path);
RegisterResolver(handle);
return;
}
catch (Exception ex)
@@ -60,4 +54,45 @@ internal static class AssistentSqliteBootstrap
}
}
}
/// <summary>Native e_sqlite3 locations for the current OS / arch, most specific first.</summary>
static string[] CandidatePaths()
{
string arch = RuntimeInformation.ProcessArchitecture switch
{
Architecture.Arm64 => "arm64",
Architecture.X86 => "x86",
Architecture.Arm => "arm",
_ => "x64",
};
if (OperatingSystem.IsWindows())
{
return [Path.Combine("runtimes", $"win-{arch}", "native", "e_sqlite3.dll"), "e_sqlite3.dll"];
}
if (OperatingSystem.IsMacOS())
{
return [Path.Combine("runtimes", $"osx-{arch}", "native", "libe_sqlite3.dylib"), "libe_sqlite3.dylib"];
}
return
[
Path.Combine("runtimes", $"linux-{arch}", "native", "libe_sqlite3.so"),
Path.Combine("runtimes", $"linux-{arch}", "native", "e_sqlite3.so"),
"libe_sqlite3.so",
"e_sqlite3.so",
];
}
/// <summary>The provider's [DllImport("e_sqlite3")] would otherwise probe the host dir, not the extension dir.</summary>
static void RegisterResolver(IntPtr handle)
{
try
{
NativeLibrary.SetDllImportResolver(typeof(SQLite3Provider_e_sqlite3).Assembly,
(name, _, _) => name.Contains("e_sqlite3", StringComparison.OrdinalIgnoreCase) ? handle : IntPtr.Zero);
}
catch (InvalidOperationException)
{
// A resolver is already set for this assembly — the preloaded handle still helps on Windows.
}
}
}