@musnows/scriverse 0.3.7 → 0.3.8
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/dist/ai.js +59 -0
- package/dist/ai.js.map +1 -1
- package/dist/app.js +136 -35
- package/dist/app.js.map +1 -1
- package/dist/http-logging.js +2 -2
- package/dist/http-logging.js.map +1 -1
- package/dist/logger.js +2 -2
- package/dist/logger.js.map +1 -1
- package/dist/pagination.js +42 -0
- package/dist/pagination.js.map +1 -0
- package/dist/public/app.js +226 -76
- package/dist/public/index.html +37 -8
- package/dist/public/markdown.js +35 -1
- package/dist/public/page-route.js +12 -0
- package/dist/public/styles.css +64 -22
- package/dist/security.js +41 -4
- package/dist/security.js.map +1 -1
- package/dist/store.js +303 -0
- package/dist/store.js.map +1 -1
- package/dist/user-auth.js +30 -0
- package/dist/user-auth.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
package/dist/ai.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PLATFORM_AI_WORK_ID } from "./database.js";
|
|
2
2
|
import { AppError, notFound } from "./errors.js";
|
|
3
3
|
import { logger, sanitizeError } from "./logger.js";
|
|
4
|
+
import { paginated, paginationSql } from "./pagination.js";
|
|
4
5
|
import { currentRequestActor } from "./request-context.js";
|
|
5
6
|
import { fetchSafeAiEndpoint } from "./security.js";
|
|
6
7
|
import { clamp, id, json, maskSecret, normalizeBaseUrl, now } from "./utils.js";
|
|
@@ -799,6 +800,11 @@ export class AiManager {
|
|
|
799
800
|
listProviders() {
|
|
800
801
|
return this.store.db.all("SELECT * FROM providers WHERE work_id = ? ORDER BY created_at", PLATFORM_AI_WORK_ID).map((row) => this.mapProvider(row));
|
|
801
802
|
}
|
|
803
|
+
listProvidersPage(pagination) {
|
|
804
|
+
const page = paginationSql(pagination);
|
|
805
|
+
const rows = this.store.db.all(`SELECT * FROM providers WHERE work_id = ? ORDER BY created_at${page.sql}`, PLATFORM_AI_WORK_ID, ...page.params);
|
|
806
|
+
return paginated(rows.map((row) => this.mapProvider(row)), pagination);
|
|
807
|
+
}
|
|
802
808
|
getProvider(providerId) {
|
|
803
809
|
return this.mapProvider(this.getProviderRow(providerId));
|
|
804
810
|
}
|
|
@@ -900,15 +906,31 @@ export class AiManager {
|
|
|
900
906
|
this.getProviderRow(providerId);
|
|
901
907
|
return this.store.db.all("SELECT * FROM models WHERE provider_id = ? ORDER BY created_at", providerId).map((row) => this.mapModel(row));
|
|
902
908
|
}
|
|
909
|
+
listModelsPage(providerId, pagination) {
|
|
910
|
+
this.getProviderRow(providerId);
|
|
911
|
+
const page = paginationSql(pagination);
|
|
912
|
+
const rows = this.store.db.all(`SELECT * FROM models WHERE provider_id = ? ORDER BY created_at${page.sql}`, providerId, ...page.params);
|
|
913
|
+
return paginated(rows.map((row) => this.mapModel(row)), pagination);
|
|
914
|
+
}
|
|
903
915
|
listPlatformModels() {
|
|
904
916
|
return this.store.db
|
|
905
917
|
.all("SELECT m.*, p.name AS provider_name FROM models m JOIN providers p ON p.id = m.provider_id WHERE p.work_id = ? ORDER BY p.created_at, m.created_at", PLATFORM_AI_WORK_ID)
|
|
906
918
|
.map((row) => ({ ...this.mapModel(row), providerName: stringValue(row, "provider_name") }));
|
|
907
919
|
}
|
|
920
|
+
listPlatformModelsPage(pagination) {
|
|
921
|
+
const page = paginationSql(pagination);
|
|
922
|
+
const rows = this.store.db.all(`SELECT m.*, p.name AS provider_name FROM models m JOIN providers p ON p.id = m.provider_id
|
|
923
|
+
WHERE p.work_id = ? ORDER BY p.created_at, m.created_at${page.sql}`, PLATFORM_AI_WORK_ID, ...page.params);
|
|
924
|
+
return paginated(rows.map((row) => ({ ...this.mapModel(row), providerName: stringValue(row, "provider_name") })), pagination);
|
|
925
|
+
}
|
|
908
926
|
listWorkModels(workId) {
|
|
909
927
|
this.store.getWork(workId);
|
|
910
928
|
return this.listPlatformModels();
|
|
911
929
|
}
|
|
930
|
+
listWorkModelsPage(workId, pagination) {
|
|
931
|
+
this.store.getWork(workId);
|
|
932
|
+
return this.listPlatformModelsPage(pagination);
|
|
933
|
+
}
|
|
912
934
|
getModel(modelId) {
|
|
913
935
|
const row = this.getModelRow(modelId);
|
|
914
936
|
return this.mapModel(row);
|
|
@@ -941,6 +963,15 @@ export class AiManager {
|
|
|
941
963
|
model: this.getModel(stringValue(row, "model_id"))
|
|
942
964
|
}));
|
|
943
965
|
}
|
|
966
|
+
listTaskDefaultsPage(workId, pagination) {
|
|
967
|
+
this.store.getWork(workId);
|
|
968
|
+
const page = paginationSql(pagination);
|
|
969
|
+
const rows = this.store.db.all(`SELECT * FROM task_defaults WHERE work_id = ? ORDER BY task_type${page.sql}`, workId, ...page.params);
|
|
970
|
+
return paginated(rows.map((row) => ({
|
|
971
|
+
taskType: stringValue(row, "task_type"),
|
|
972
|
+
model: this.getModel(stringValue(row, "model_id"))
|
|
973
|
+
})), pagination);
|
|
974
|
+
}
|
|
944
975
|
async createSuggestion(input) {
|
|
945
976
|
const action = input.taskType === "continue" ? "append" : input.taskType === "polish" ? "replace-selection" : "note";
|
|
946
977
|
if (action === "replace-selection" && !input.scope.selection) {
|
|
@@ -1039,6 +1070,14 @@ export class AiManager {
|
|
|
1039
1070
|
: this.store.db.all("SELECT * FROM ai_suggestions WHERE work_id = ? ORDER BY created_at DESC", workId);
|
|
1040
1071
|
return rows.map((row) => this.mapSuggestion(row));
|
|
1041
1072
|
}
|
|
1073
|
+
listSuggestionsPage(workId, pagination, status) {
|
|
1074
|
+
this.store.getWork(workId);
|
|
1075
|
+
const page = paginationSql(pagination);
|
|
1076
|
+
const rows = status
|
|
1077
|
+
? this.store.db.all(`SELECT * FROM ai_suggestions WHERE work_id = ? AND status = ? ORDER BY created_at DESC${page.sql}`, workId, status, ...page.params)
|
|
1078
|
+
: this.store.db.all(`SELECT * FROM ai_suggestions WHERE work_id = ? ORDER BY created_at DESC${page.sql}`, workId, ...page.params);
|
|
1079
|
+
return paginated(rows.map((row) => this.mapSuggestion(row)), pagination);
|
|
1080
|
+
}
|
|
1042
1081
|
getSuggestion(suggestionId) {
|
|
1043
1082
|
const row = this.store.db.get("SELECT * FROM ai_suggestions WHERE id = ?", suggestionId);
|
|
1044
1083
|
if (!row)
|
|
@@ -1124,6 +1163,26 @@ export class AiManager {
|
|
|
1124
1163
|
completedAt: row.completed_at === null ? null : stringValue(row, "completed_at")
|
|
1125
1164
|
}));
|
|
1126
1165
|
}
|
|
1166
|
+
listCallsPage(workId, pagination) {
|
|
1167
|
+
this.store.getWork(workId);
|
|
1168
|
+
const page = paginationSql(pagination);
|
|
1169
|
+
const rows = this.store.db.all(`SELECT * FROM ai_calls WHERE work_id = ? ORDER BY created_at DESC${page.sql}`, workId, ...page.params);
|
|
1170
|
+
return paginated(rows.map((row) => ({
|
|
1171
|
+
id: stringValue(row, "id"),
|
|
1172
|
+
workId: stringValue(row, "work_id"),
|
|
1173
|
+
taskType: stringValue(row, "task_type"),
|
|
1174
|
+
provider: this.getProvider(stringValue(row, "provider_id")),
|
|
1175
|
+
model: this.getModel(stringValue(row, "model_id")),
|
|
1176
|
+
contextScope: json(stringValue(row, "context_scope_json"), {}),
|
|
1177
|
+
parameters: json(stringValue(row, "parameters_json"), {}),
|
|
1178
|
+
status: stringValue(row, "status"),
|
|
1179
|
+
failure: row.failure === null ? null : stringValue(row, "failure"),
|
|
1180
|
+
inputChars: numberValue(row, "input_chars"),
|
|
1181
|
+
outputChars: numberValue(row, "output_chars"),
|
|
1182
|
+
createdAt: stringValue(row, "created_at"),
|
|
1183
|
+
completedAt: row.completed_at === null ? null : stringValue(row, "completed_at")
|
|
1184
|
+
})), pagination);
|
|
1185
|
+
}
|
|
1127
1186
|
async runTask(taskId, modelId) {
|
|
1128
1187
|
const task = this.store.getTask(taskId);
|
|
1129
1188
|
const workId = String(task.workId);
|