Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
feat(tools): add ability to activate tools from search query parameter
Browse files
src/routes/+layout.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import "../styles/main.css";
|
| 3 |
|
| 4 |
-
import { onDestroy } from "svelte";
|
| 5 |
import { goto, invalidate } from "$app/navigation";
|
| 6 |
import { base } from "$app/paths";
|
| 7 |
import { page } from "$app/stores";
|
|
@@ -117,14 +117,37 @@
|
|
| 117 |
|
| 118 |
const settings = createSettingsStore(data.settings);
|
| 119 |
|
| 120 |
-
|
| 121 |
-
if ($
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
}
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
$: mobileNavTitle = ["/models", "/assistants", "/privacy"].includes($page.route.id ?? "")
|
| 130 |
? ""
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
import "../styles/main.css";
|
| 3 |
|
| 4 |
+
import { onDestroy, onMount } from "svelte";
|
| 5 |
import { goto, invalidate } from "$app/navigation";
|
| 6 |
import { base } from "$app/paths";
|
| 7 |
import { page } from "$app/stores";
|
|
|
|
| 117 |
|
| 118 |
const settings = createSettingsStore(data.settings);
|
| 119 |
|
| 120 |
+
onMount(async () => {
|
| 121 |
+
if ($page.url.searchParams.has("model")) {
|
| 122 |
+
await settings
|
| 123 |
+
.instantSet({
|
| 124 |
+
activeModel: $page.url.searchParams.get("model") ?? $settings.activeModel,
|
| 125 |
+
})
|
| 126 |
+
.then(async () => {
|
| 127 |
+
const query = new URLSearchParams($page.url.searchParams.toString());
|
| 128 |
+
query.delete("model");
|
| 129 |
+
await goto(`${base}/?${query.toString()}`, {
|
| 130 |
+
invalidateAll: true,
|
| 131 |
+
});
|
| 132 |
+
});
|
| 133 |
}
|
| 134 |
+
|
| 135 |
+
if ($page.url.searchParams.has("tools")) {
|
| 136 |
+
const tools = $page.url.searchParams.get("tools")?.split(",");
|
| 137 |
+
|
| 138 |
+
await settings
|
| 139 |
+
.instantSet({
|
| 140 |
+
tools: [...($settings.tools ?? []), ...(tools ?? [])],
|
| 141 |
+
})
|
| 142 |
+
.then(async () => {
|
| 143 |
+
const query = new URLSearchParams($page.url.searchParams.toString());
|
| 144 |
+
query.delete("tools");
|
| 145 |
+
await goto(`${base}/?${query.toString()}`, {
|
| 146 |
+
invalidateAll: true,
|
| 147 |
+
});
|
| 148 |
+
});
|
| 149 |
+
}
|
| 150 |
+
});
|
| 151 |
|
| 152 |
$: mobileNavTitle = ["/models", "/assistants", "/privacy"].includes($page.route.id ?? "")
|
| 153 |
? ""
|
src/routes/settings/(nav)/+server.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { z } from "zod";
|
|
| 3 |
import { authCondition } from "$lib/server/auth";
|
| 4 |
import { DEFAULT_SETTINGS, type SettingsEditable } from "$lib/types/Settings";
|
| 5 |
import { toolFromConfigs } from "$lib/server/tools/index.js";
|
|
|
|
| 6 |
|
| 7 |
export async function POST({ request, locals }) {
|
| 8 |
const body = await request.json();
|
|
@@ -29,6 +30,15 @@ export async function POST({ request, locals }) {
|
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
await collections.settings.updateOne(
|
| 33 |
authCondition(locals),
|
| 34 |
{
|
|
|
|
| 3 |
import { authCondition } from "$lib/server/auth";
|
| 4 |
import { DEFAULT_SETTINGS, type SettingsEditable } from "$lib/types/Settings";
|
| 5 |
import { toolFromConfigs } from "$lib/server/tools/index.js";
|
| 6 |
+
import { ObjectId } from "mongodb";
|
| 7 |
|
| 8 |
export async function POST({ request, locals }) {
|
| 9 |
const body = await request.json();
|
|
|
|
| 30 |
});
|
| 31 |
}
|
| 32 |
|
| 33 |
+
// make sure all tools exist
|
| 34 |
+
if (settings.tools) {
|
| 35 |
+
settings.tools = await collections.tools
|
| 36 |
+
.find({ _id: { $in: settings.tools.map((toolId) => new ObjectId(toolId)) } })
|
| 37 |
+
.project({ _id: 1 })
|
| 38 |
+
.toArray()
|
| 39 |
+
.then((tools) => tools.map((tool) => tool._id.toString()));
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
await collections.settings.updateOne(
|
| 43 |
authCondition(locals),
|
| 44 |
{
|