teleton 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -12
- package/dist/{chunk-ND2X5FWB.js → chunk-5PLZ3KSO.js} +16 -3
- package/dist/{chunk-NERLQY2H.js → chunk-BGC2IUM5.js} +73 -15
- package/dist/{chunk-FNV5FF35.js → chunk-EK7M5K26.js} +29 -13
- package/dist/chunk-JQDLW7IE.js +107 -0
- package/dist/{chunk-VSMUAU5X.js → chunk-LAQOUFOJ.js} +2419 -2132
- package/dist/chunk-QOQWUUA4.js +158 -0
- package/dist/{chunk-LRCPA7SC.js → chunk-RMLQS3X6.js} +15 -3
- package/dist/{chunk-UDD7FYOU.js → chunk-WIKM24GZ.js} +1 -18
- package/dist/{chunk-RBU6JXD3.js → chunk-XDYDA2KV.js} +1 -1
- package/dist/{chunk-JHKWHGBM.js → chunk-YFG2QHLA.js} +380 -47
- package/dist/cli/index.js +216 -272
- package/dist/{client-3VWE7NC4.js → client-RTNALK7W.js} +3 -2
- package/dist/{get-my-gifts-RI7FAXAL.js → get-my-gifts-TPVUGUWT.js} +1 -1
- package/dist/index.js +9 -10
- package/dist/{memory-5SS3Q5EA.js → memory-JQZ6MTRU.js} +2 -2
- package/dist/{migrate-M7SJMDOL.js → migrate-GS5ACQDA.js} +2 -2
- package/dist/{server-NPSODUMA.js → server-TCJOBV3D.js} +292 -11
- package/dist/{setup-server-C7ZTPHD5.js → setup-server-YHYJLAMA.js} +77 -112
- package/dist/{tool-index-MIVK3D7H.js → tool-index-6HBRVXVG.js} +1 -1
- package/dist/web/assets/index-B6M9knfJ.css +1 -0
- package/dist/web/assets/index-DAGeQfVZ.js +72 -0
- package/dist/web/assets/{index.es-D81xLR29.js → index.es-CqZHj0tz.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/chunk-EHEV7FJ7.js +0 -157
- package/dist/chunk-QUAPFI2N.js +0 -42
- package/dist/endpoint-FLYNEZ2F.js +0 -7
- package/dist/format-transactions-FD74HI5N.js +0 -9
- package/dist/web/assets/index-BqwoDycr.js +0 -72
- package/dist/web/assets/index-CRDIf07k.css +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TeletonApp,
|
|
3
3
|
main
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-EHEV7FJ7.js";
|
|
4
|
+
} from "./chunk-LAQOUFOJ.js";
|
|
5
|
+
import "./chunk-WIKM24GZ.js";
|
|
7
6
|
import "./chunk-U7FQYCBQ.js";
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-QUAPFI2N.js";
|
|
7
|
+
import "./chunk-YFG2QHLA.js";
|
|
8
|
+
import "./chunk-BGC2IUM5.js";
|
|
11
9
|
import "./chunk-TSKJCWQQ.js";
|
|
12
10
|
import "./chunk-XBE4JB7C.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-5PLZ3KSO.js";
|
|
12
|
+
import "./chunk-JQDLW7IE.js";
|
|
13
|
+
import "./chunk-RMLQS3X6.js";
|
|
15
14
|
import "./chunk-OCLG5GKI.js";
|
|
16
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-XDYDA2KV.js";
|
|
17
16
|
import "./chunk-UCN6TI25.js";
|
|
18
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-EK7M5K26.js";
|
|
19
18
|
import "./chunk-XBKSS6DM.js";
|
|
20
19
|
import "./chunk-RO62LO6Z.js";
|
|
21
20
|
import "./chunk-VAUJSSD3.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
initializeMemory,
|
|
17
17
|
runMigrations,
|
|
18
18
|
setSchemaVersion
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-XDYDA2KV.js";
|
|
20
20
|
import "./chunk-UCN6TI25.js";
|
|
21
21
|
import {
|
|
22
22
|
AnthropicEmbeddingProvider,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
deserializeEmbedding,
|
|
28
28
|
hashText,
|
|
29
29
|
serializeEmbedding
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-EK7M5K26.js";
|
|
31
31
|
import "./chunk-XBKSS6DM.js";
|
|
32
32
|
import "./chunk-RO62LO6Z.js";
|
|
33
33
|
import "./chunk-VAUJSSD3.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getDatabase
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XDYDA2KV.js";
|
|
4
4
|
import "./chunk-UCN6TI25.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-EK7M5K26.js";
|
|
6
6
|
import "./chunk-XBKSS6DM.js";
|
|
7
7
|
import "./chunk-RO62LO6Z.js";
|
|
8
8
|
import "./chunk-VAUJSSD3.js";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getModelsForProvider
|
|
3
|
+
} from "./chunk-QOQWUUA4.js";
|
|
1
4
|
import {
|
|
2
5
|
CONFIGURABLE_KEYS,
|
|
3
6
|
WorkspaceSecurityError,
|
|
@@ -16,14 +19,16 @@ import {
|
|
|
16
19
|
validateWritePath,
|
|
17
20
|
writePluginSecret,
|
|
18
21
|
writeRawConfig
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-QUAPFI2N.js";
|
|
22
|
+
} from "./chunk-YFG2QHLA.js";
|
|
23
|
+
import "./chunk-BGC2IUM5.js";
|
|
22
24
|
import "./chunk-TSKJCWQQ.js";
|
|
23
25
|
import {
|
|
24
26
|
getErrorMessage
|
|
25
27
|
} from "./chunk-XBE4JB7C.js";
|
|
26
|
-
import
|
|
28
|
+
import {
|
|
29
|
+
getProviderMetadata,
|
|
30
|
+
validateApiKeyFormat
|
|
31
|
+
} from "./chunk-RMLQS3X6.js";
|
|
27
32
|
import "./chunk-UCN6TI25.js";
|
|
28
33
|
import "./chunk-XBKSS6DM.js";
|
|
29
34
|
import "./chunk-RO62LO6Z.js";
|
|
@@ -215,7 +220,7 @@ function createToolsRoutes(deps) {
|
|
|
215
220
|
try {
|
|
216
221
|
const config = deps.agent.getConfig();
|
|
217
222
|
const body = await c.req.json();
|
|
218
|
-
const { enabled, topK } = body;
|
|
223
|
+
const { enabled, topK, alwaysInclude, skipUnlimitedProviders } = body;
|
|
219
224
|
if (enabled !== void 0) {
|
|
220
225
|
config.tool_rag.enabled = enabled;
|
|
221
226
|
}
|
|
@@ -225,6 +230,28 @@ function createToolsRoutes(deps) {
|
|
|
225
230
|
}
|
|
226
231
|
config.tool_rag.top_k = topK;
|
|
227
232
|
}
|
|
233
|
+
if (alwaysInclude !== void 0) {
|
|
234
|
+
if (!Array.isArray(alwaysInclude) || alwaysInclude.some((s) => typeof s !== "string" || s.length === 0)) {
|
|
235
|
+
return c.json(
|
|
236
|
+
{ success: false, error: "alwaysInclude must be an array of non-empty strings" },
|
|
237
|
+
400
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
config.tool_rag.always_include = alwaysInclude;
|
|
241
|
+
}
|
|
242
|
+
if (skipUnlimitedProviders !== void 0) {
|
|
243
|
+
config.tool_rag.skip_unlimited_providers = skipUnlimitedProviders;
|
|
244
|
+
}
|
|
245
|
+
const raw = readRawConfig(deps.configPath);
|
|
246
|
+
setNestedValue(raw, "tool_rag.enabled", config.tool_rag.enabled);
|
|
247
|
+
setNestedValue(raw, "tool_rag.top_k", config.tool_rag.top_k);
|
|
248
|
+
setNestedValue(raw, "tool_rag.always_include", config.tool_rag.always_include);
|
|
249
|
+
setNestedValue(
|
|
250
|
+
raw,
|
|
251
|
+
"tool_rag.skip_unlimited_providers",
|
|
252
|
+
config.tool_rag.skip_unlimited_providers
|
|
253
|
+
);
|
|
254
|
+
writeRawConfig(raw, deps.configPath);
|
|
228
255
|
const toolIndex = deps.toolRegistry.getToolIndex();
|
|
229
256
|
const response = {
|
|
230
257
|
success: true,
|
|
@@ -232,7 +259,9 @@ function createToolsRoutes(deps) {
|
|
|
232
259
|
enabled: config.tool_rag.enabled,
|
|
233
260
|
indexed: toolIndex?.isIndexed ?? false,
|
|
234
261
|
topK: config.tool_rag.top_k,
|
|
235
|
-
totalTools: deps.toolRegistry.count
|
|
262
|
+
totalTools: deps.toolRegistry.count,
|
|
263
|
+
alwaysInclude: config.tool_rag.always_include,
|
|
264
|
+
skipUnlimitedProviders: config.tool_rag.skip_unlimited_providers
|
|
236
265
|
}
|
|
237
266
|
};
|
|
238
267
|
return c.json(response);
|
|
@@ -510,6 +539,69 @@ function createMemoryRoutes(deps) {
|
|
|
510
539
|
return c.json(response, 500);
|
|
511
540
|
}
|
|
512
541
|
});
|
|
542
|
+
app.get("/sources/:sourceKey", (c) => {
|
|
543
|
+
try {
|
|
544
|
+
const sourceKey = decodeURIComponent(c.req.param("sourceKey"));
|
|
545
|
+
const rows = deps.memory.db.prepare(
|
|
546
|
+
`
|
|
547
|
+
SELECT id, text, source, path, start_line, end_line, updated_at
|
|
548
|
+
FROM knowledge
|
|
549
|
+
WHERE COALESCE(path, source) = ?
|
|
550
|
+
ORDER BY start_line ASC, updated_at DESC
|
|
551
|
+
`
|
|
552
|
+
).all(sourceKey);
|
|
553
|
+
const chunks = rows.map((row) => ({
|
|
554
|
+
id: row.id,
|
|
555
|
+
text: row.text,
|
|
556
|
+
source: row.path || row.source,
|
|
557
|
+
startLine: row.start_line,
|
|
558
|
+
endLine: row.end_line,
|
|
559
|
+
updatedAt: row.updated_at
|
|
560
|
+
}));
|
|
561
|
+
const response = {
|
|
562
|
+
success: true,
|
|
563
|
+
data: chunks
|
|
564
|
+
};
|
|
565
|
+
return c.json(response);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
const response = {
|
|
568
|
+
success: false,
|
|
569
|
+
error: getErrorMessage(error)
|
|
570
|
+
};
|
|
571
|
+
return c.json(response, 500);
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
app.get("/sources", (c) => {
|
|
575
|
+
try {
|
|
576
|
+
const rows = deps.memory.db.prepare(
|
|
577
|
+
`
|
|
578
|
+
SELECT
|
|
579
|
+
COALESCE(path, source) AS source_key,
|
|
580
|
+
COUNT(*) AS entry_count,
|
|
581
|
+
MAX(updated_at) AS last_updated
|
|
582
|
+
FROM knowledge
|
|
583
|
+
GROUP BY source_key
|
|
584
|
+
ORDER BY last_updated DESC
|
|
585
|
+
`
|
|
586
|
+
).all();
|
|
587
|
+
const sources = rows.map((row) => ({
|
|
588
|
+
source: row.source_key,
|
|
589
|
+
entryCount: row.entry_count,
|
|
590
|
+
lastUpdated: row.last_updated
|
|
591
|
+
}));
|
|
592
|
+
const response = {
|
|
593
|
+
success: true,
|
|
594
|
+
data: sources
|
|
595
|
+
};
|
|
596
|
+
return c.json(response);
|
|
597
|
+
} catch (error) {
|
|
598
|
+
const response = {
|
|
599
|
+
success: false,
|
|
600
|
+
error: getErrorMessage(error)
|
|
601
|
+
};
|
|
602
|
+
return c.json(response, 500);
|
|
603
|
+
}
|
|
604
|
+
});
|
|
513
605
|
return app;
|
|
514
606
|
}
|
|
515
607
|
|
|
@@ -751,6 +843,16 @@ function errorResponse(c, error, status = 500) {
|
|
|
751
843
|
const response = { success: false, error: message };
|
|
752
844
|
return c.json(response, code);
|
|
753
845
|
}
|
|
846
|
+
var IMAGE_MIME_TYPES = {
|
|
847
|
+
".png": "image/png",
|
|
848
|
+
".jpg": "image/jpeg",
|
|
849
|
+
".jpeg": "image/jpeg",
|
|
850
|
+
".gif": "image/gif",
|
|
851
|
+
".webp": "image/webp",
|
|
852
|
+
".svg": "image/svg+xml",
|
|
853
|
+
".bmp": "image/bmp",
|
|
854
|
+
".ico": "image/x-icon"
|
|
855
|
+
};
|
|
754
856
|
function getWorkspaceStats(dir) {
|
|
755
857
|
let files = 0;
|
|
756
858
|
let size = 0;
|
|
@@ -823,6 +925,45 @@ function createWorkspaceRoutes(_deps) {
|
|
|
823
925
|
return errorResponse(c, error);
|
|
824
926
|
}
|
|
825
927
|
});
|
|
928
|
+
app.get("/raw", (c) => {
|
|
929
|
+
try {
|
|
930
|
+
const path = c.req.query("path");
|
|
931
|
+
if (!path) {
|
|
932
|
+
const response = { success: false, error: "Missing 'path' query parameter" };
|
|
933
|
+
return c.json(response, 400);
|
|
934
|
+
}
|
|
935
|
+
const validated = validateReadPath(path);
|
|
936
|
+
const mime = IMAGE_MIME_TYPES[validated.extension];
|
|
937
|
+
if (!mime) {
|
|
938
|
+
const response = {
|
|
939
|
+
success: false,
|
|
940
|
+
error: "Unsupported file type for raw preview"
|
|
941
|
+
};
|
|
942
|
+
return c.json(response, 415);
|
|
943
|
+
}
|
|
944
|
+
const stats = statSync(validated.absolutePath);
|
|
945
|
+
if (stats.size > 5 * 1024 * 1024) {
|
|
946
|
+
const response = {
|
|
947
|
+
success: false,
|
|
948
|
+
error: "Image too large for preview (max 5MB)"
|
|
949
|
+
};
|
|
950
|
+
return c.json(response, 413);
|
|
951
|
+
}
|
|
952
|
+
const buffer = readFileSync2(validated.absolutePath);
|
|
953
|
+
const headers = {
|
|
954
|
+
"Content-Type": mime,
|
|
955
|
+
"Content-Length": String(buffer.byteLength),
|
|
956
|
+
"Content-Disposition": "inline",
|
|
957
|
+
"Cache-Control": "private, max-age=60"
|
|
958
|
+
};
|
|
959
|
+
if (validated.extension === ".svg") {
|
|
960
|
+
headers["Content-Security-Policy"] = "sandbox";
|
|
961
|
+
}
|
|
962
|
+
return c.body(buffer, 200, headers);
|
|
963
|
+
} catch (error) {
|
|
964
|
+
return errorResponse(c, error);
|
|
965
|
+
}
|
|
966
|
+
});
|
|
826
967
|
app.get("/read", (c) => {
|
|
827
968
|
try {
|
|
828
969
|
const path = c.req.query("path");
|
|
@@ -961,6 +1102,7 @@ function createWorkspaceRoutes(_deps) {
|
|
|
961
1102
|
// src/webui/routes/tasks.ts
|
|
962
1103
|
import { Hono as Hono9 } from "hono";
|
|
963
1104
|
var VALID_STATUSES = ["pending", "in_progress", "done", "failed", "cancelled"];
|
|
1105
|
+
var TERMINAL_STATUSES = ["done", "failed", "cancelled"];
|
|
964
1106
|
function createTasksRoutes(deps) {
|
|
965
1107
|
const app = new Hono9();
|
|
966
1108
|
function store() {
|
|
@@ -1033,6 +1175,32 @@ function createTasksRoutes(deps) {
|
|
|
1033
1175
|
return c.json(response, 500);
|
|
1034
1176
|
}
|
|
1035
1177
|
});
|
|
1178
|
+
app.post("/clean", async (c) => {
|
|
1179
|
+
try {
|
|
1180
|
+
const body = await c.req.json().catch(() => ({ status: void 0 }));
|
|
1181
|
+
const status = body.status;
|
|
1182
|
+
if (!status || !TERMINAL_STATUSES.includes(status)) {
|
|
1183
|
+
const response2 = {
|
|
1184
|
+
success: false,
|
|
1185
|
+
error: `Invalid status. Must be one of: ${TERMINAL_STATUSES.join(", ")}`
|
|
1186
|
+
};
|
|
1187
|
+
return c.json(response2, 400);
|
|
1188
|
+
}
|
|
1189
|
+
const tasks = store().listTasks({ status });
|
|
1190
|
+
let deleted = 0;
|
|
1191
|
+
for (const t of tasks) {
|
|
1192
|
+
if (store().deleteTask(t.id)) deleted++;
|
|
1193
|
+
}
|
|
1194
|
+
const response = { success: true, data: { deleted } };
|
|
1195
|
+
return c.json(response);
|
|
1196
|
+
} catch (error) {
|
|
1197
|
+
const response = {
|
|
1198
|
+
success: false,
|
|
1199
|
+
error: getErrorMessage(error)
|
|
1200
|
+
};
|
|
1201
|
+
return c.json(response, 500);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1036
1204
|
app.post("/clean-done", (c) => {
|
|
1037
1205
|
try {
|
|
1038
1206
|
const doneTasks = store().listTasks({ status: "done" });
|
|
@@ -1078,17 +1246,21 @@ function createConfigRoutes(deps) {
|
|
|
1078
1246
|
try {
|
|
1079
1247
|
const raw = readRawConfig(deps.configPath);
|
|
1080
1248
|
const data = Object.entries(CONFIGURABLE_KEYS).map(([key, meta]) => {
|
|
1081
|
-
const
|
|
1082
|
-
const isSet =
|
|
1249
|
+
const rawValue = getNestedValue(raw, key);
|
|
1250
|
+
const isSet = rawValue != null && rawValue !== "" && !(Array.isArray(rawValue) && rawValue.length === 0);
|
|
1251
|
+
const displayValue = isSet ? meta.type === "array" ? JSON.stringify(rawValue) : meta.mask(String(rawValue)) : null;
|
|
1083
1252
|
return {
|
|
1084
1253
|
key,
|
|
1254
|
+
label: meta.label,
|
|
1085
1255
|
set: isSet,
|
|
1086
|
-
value:
|
|
1256
|
+
value: displayValue,
|
|
1087
1257
|
sensitive: meta.sensitive,
|
|
1088
1258
|
type: meta.type,
|
|
1089
1259
|
category: meta.category,
|
|
1090
1260
|
description: meta.description,
|
|
1091
|
-
...meta.options ? { options: meta.options } : {}
|
|
1261
|
+
...meta.options ? { options: meta.options } : {},
|
|
1262
|
+
...meta.optionLabels ? { optionLabels: meta.optionLabels } : {},
|
|
1263
|
+
...meta.itemType ? { itemType: meta.itemType } : {}
|
|
1092
1264
|
};
|
|
1093
1265
|
});
|
|
1094
1266
|
const response = { success: true, data };
|
|
@@ -1120,6 +1292,55 @@ function createConfigRoutes(deps) {
|
|
|
1120
1292
|
return c.json({ success: false, error: "Invalid JSON body" }, 400);
|
|
1121
1293
|
}
|
|
1122
1294
|
const value = body.value;
|
|
1295
|
+
if (meta.type === "array") {
|
|
1296
|
+
if (!Array.isArray(value)) {
|
|
1297
|
+
return c.json(
|
|
1298
|
+
{ success: false, error: "Value must be an array for array keys" },
|
|
1299
|
+
400
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
for (let i = 0; i < value.length; i++) {
|
|
1303
|
+
const itemStr = String(value[i]);
|
|
1304
|
+
const itemErr = meta.validate(itemStr);
|
|
1305
|
+
if (itemErr) {
|
|
1306
|
+
return c.json(
|
|
1307
|
+
{
|
|
1308
|
+
success: false,
|
|
1309
|
+
error: `Invalid item at index ${i} for ${key}: ${itemErr}`
|
|
1310
|
+
},
|
|
1311
|
+
400
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
try {
|
|
1316
|
+
const parsed = value.map((item) => meta.parse(String(item)));
|
|
1317
|
+
const raw = readRawConfig(deps.configPath);
|
|
1318
|
+
setNestedValue(raw, key, parsed);
|
|
1319
|
+
writeRawConfig(raw, deps.configPath);
|
|
1320
|
+
const runtimeConfig = deps.agent.getConfig();
|
|
1321
|
+
setNestedValue(runtimeConfig, key, parsed);
|
|
1322
|
+
const result = {
|
|
1323
|
+
key,
|
|
1324
|
+
label: meta.label,
|
|
1325
|
+
set: parsed.length > 0,
|
|
1326
|
+
value: JSON.stringify(parsed),
|
|
1327
|
+
sensitive: meta.sensitive,
|
|
1328
|
+
type: meta.type,
|
|
1329
|
+
category: meta.category,
|
|
1330
|
+
description: meta.description,
|
|
1331
|
+
...meta.itemType ? { itemType: meta.itemType } : {}
|
|
1332
|
+
};
|
|
1333
|
+
return c.json({ success: true, data: result });
|
|
1334
|
+
} catch (err) {
|
|
1335
|
+
return c.json(
|
|
1336
|
+
{
|
|
1337
|
+
success: false,
|
|
1338
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1339
|
+
},
|
|
1340
|
+
500
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1123
1344
|
if (value == null || typeof value !== "string") {
|
|
1124
1345
|
return c.json(
|
|
1125
1346
|
{ success: false, error: "Missing or invalid 'value' field" },
|
|
@@ -1137,11 +1358,24 @@ function createConfigRoutes(deps) {
|
|
|
1137
1358
|
const parsed = meta.parse(value);
|
|
1138
1359
|
const raw = readRawConfig(deps.configPath);
|
|
1139
1360
|
setNestedValue(raw, key, parsed);
|
|
1361
|
+
if (key === "telegram.owner_id" && typeof parsed === "number") {
|
|
1362
|
+
const adminIds = getNestedValue(raw, "telegram.admin_ids") ?? [];
|
|
1363
|
+
if (!adminIds.includes(parsed)) {
|
|
1364
|
+
setNestedValue(raw, "telegram.admin_ids", [...adminIds, parsed]);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1140
1367
|
writeRawConfig(raw, deps.configPath);
|
|
1141
1368
|
const runtimeConfig = deps.agent.getConfig();
|
|
1142
1369
|
setNestedValue(runtimeConfig, key, parsed);
|
|
1370
|
+
if (key === "telegram.owner_id" && typeof parsed === "number") {
|
|
1371
|
+
const rtAdminIds = getNestedValue(runtimeConfig, "telegram.admin_ids") ?? [];
|
|
1372
|
+
if (!rtAdminIds.includes(parsed)) {
|
|
1373
|
+
setNestedValue(runtimeConfig, "telegram.admin_ids", [...rtAdminIds, parsed]);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1143
1376
|
const result = {
|
|
1144
1377
|
key,
|
|
1378
|
+
label: meta.label,
|
|
1145
1379
|
set: true,
|
|
1146
1380
|
value: meta.mask(value),
|
|
1147
1381
|
sensitive: meta.sensitive,
|
|
@@ -1179,13 +1413,15 @@ function createConfigRoutes(deps) {
|
|
|
1179
1413
|
deleteNestedValue(runtimeConfig, key);
|
|
1180
1414
|
const result = {
|
|
1181
1415
|
key,
|
|
1416
|
+
label: meta.label,
|
|
1182
1417
|
set: false,
|
|
1183
1418
|
value: null,
|
|
1184
1419
|
sensitive: meta.sensitive,
|
|
1185
1420
|
type: meta.type,
|
|
1186
1421
|
category: meta.category,
|
|
1187
1422
|
description: meta.description,
|
|
1188
|
-
...meta.options ? { options: meta.options } : {}
|
|
1423
|
+
...meta.options ? { options: meta.options } : {},
|
|
1424
|
+
...meta.itemType ? { itemType: meta.itemType } : {}
|
|
1189
1425
|
};
|
|
1190
1426
|
return c.json({ success: true, data: result });
|
|
1191
1427
|
} catch (err) {
|
|
@@ -1195,6 +1431,51 @@ function createConfigRoutes(deps) {
|
|
|
1195
1431
|
);
|
|
1196
1432
|
}
|
|
1197
1433
|
});
|
|
1434
|
+
app.get("/models/:provider", (c) => {
|
|
1435
|
+
const provider = c.req.param("provider");
|
|
1436
|
+
const models = getModelsForProvider(provider);
|
|
1437
|
+
return c.json({ success: true, data: models });
|
|
1438
|
+
});
|
|
1439
|
+
app.get("/provider-meta/:provider", (c) => {
|
|
1440
|
+
const provider = c.req.param("provider");
|
|
1441
|
+
try {
|
|
1442
|
+
const meta = getProviderMetadata(provider);
|
|
1443
|
+
const needsKey = provider !== "claude-code" && provider !== "cocoon" && provider !== "local";
|
|
1444
|
+
return c.json({
|
|
1445
|
+
success: true,
|
|
1446
|
+
data: {
|
|
1447
|
+
needsKey,
|
|
1448
|
+
keyHint: meta.keyHint,
|
|
1449
|
+
keyPrefix: meta.keyPrefix,
|
|
1450
|
+
consoleUrl: meta.consoleUrl,
|
|
1451
|
+
displayName: meta.displayName
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
} catch (err) {
|
|
1455
|
+
return c.json(
|
|
1456
|
+
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
1457
|
+
400
|
|
1458
|
+
);
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
app.post("/validate-api-key", async (c) => {
|
|
1462
|
+
try {
|
|
1463
|
+
const body = await c.req.json();
|
|
1464
|
+
if (!body.provider || !body.apiKey) {
|
|
1465
|
+
return c.json({ success: false, error: "Missing provider or apiKey" }, 400);
|
|
1466
|
+
}
|
|
1467
|
+
const error = validateApiKeyFormat(body.provider, body.apiKey);
|
|
1468
|
+
return c.json({
|
|
1469
|
+
success: true,
|
|
1470
|
+
data: { valid: !error, error: error ?? null }
|
|
1471
|
+
});
|
|
1472
|
+
} catch (err) {
|
|
1473
|
+
return c.json(
|
|
1474
|
+
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
1475
|
+
400
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
});
|
|
1198
1479
|
return app;
|
|
1199
1480
|
}
|
|
1200
1481
|
|