@musnows/scriverse 0.4.12 → 0.5.1

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/app.js CHANGED
@@ -295,9 +295,17 @@ const modelSchema = z.object({
295
295
  const aiPromptSchema = z.object({
296
296
  systemPrompt: z.string().max(100_000).optional()
297
297
  });
298
- const platformUiSettingsSchema = z.object({
299
- toastPosition: z.enum(["bottom-right", "top-right"])
298
+ const platformPageSizesSchema = z.object({
299
+ characters: z.number().int().min(10).max(100).optional(),
300
+ analysisTasks: z.number().int().min(10).max(100).optional(),
301
+ fileVersions: z.number().int().min(10).max(100).optional()
300
302
  }).strict();
303
+ const platformUiSettingsSchema = z.object({
304
+ toastPosition: z.enum(["bottom-right", "top-right"]).optional(),
305
+ pageSizes: platformPageSizesSchema.optional()
306
+ }).strict().refine((input) => input.toastPosition !== undefined || input.pageSizes !== undefined, {
307
+ message: "至少需要提供一项界面设置"
308
+ });
301
309
  const aiToolCallResultSchema = z.object({
302
310
  id: z.string().min(1).max(300),
303
311
  name: z.string().min(1).max(200),
@@ -426,6 +434,19 @@ function redactRaceMembers(record, permissions) {
426
434
  function redactOrganizationMembers(record, permissions) {
427
435
  return permissions.characters === "none" ? { ...record, memberIds: [], members: [] } : record;
428
436
  }
437
+ function redactTaskCharacterNames(record, permissions) {
438
+ const { scopeSummaryWithoutCharacterNames, ...result } = record;
439
+ if (permissions.characters !== "none")
440
+ return result;
441
+ if (typeof scopeSummaryWithoutCharacterNames === "string")
442
+ result.scopeSummary = scopeSummaryWithoutCharacterNames;
443
+ const scope = recordValue(result.scope);
444
+ if (scope) {
445
+ const { targetCharacters: _targetCharacters, ...redactedScope } = scope;
446
+ result.scope = redactedScope;
447
+ }
448
+ return result;
449
+ }
429
450
  function redactMergeRecords(value, mapper) {
430
451
  const record = recordValue(value);
431
452
  if (!record)
@@ -1323,25 +1344,27 @@ export function createRuntime(options) {
1323
1344
  data(response, store.mergeCharacters({ reviewId: request.params.reviewId, ...input }));
1324
1345
  });
1325
1346
  app.get("/api/works/:workId/tasks", (request, response) => {
1326
- const pagination = parsePagination(request.query);
1327
- const summary = request.query.view === "summary";
1328
- data(response, pagination
1329
- ? (summary ? store.listTaskSummariesPage(request.params.workId, pagination) : store.listTasksPage(request.params.workId, pagination))
1330
- : store.listTasks(request.params.workId));
1347
+ const permissions = requestPermissions(request, request.params.workId);
1348
+ data(response, mapRecords(store.listTaskSummariesPage(request.params.workId, parsePagination(request.query) ?? { page: 1, limit: 30, offset: 0 }), (task) => redactTaskCharacterNames(task, permissions)));
1331
1349
  });
1332
1350
  app.post("/api/works/:workId/tasks", (request, response) => {
1333
1351
  const input = parse(analysisTaskSchema, request.body);
1334
- data(response, store.createTask(request.params.workId, input), 201);
1352
+ data(response, redactTaskCharacterNames(store.createTask(request.params.workId, input), requestPermissions(request, request.params.workId)), 201);
1335
1353
  });
1336
1354
  app.post("/api/works/:workId/tasks/auto-run", (request, response) => {
1337
1355
  data(response, ai.startAutoRunBatch(request.params.workId));
1338
1356
  });
1339
- app.get("/api/tasks/:taskId", (request, response) => data(response, store.getTask(request.params.taskId)));
1357
+ app.get("/api/tasks/:taskId", (request, response) => data(response, redactTaskCharacterNames(store.getTask(request.params.taskId), requestPermissions(request))));
1358
+ app.get("/api/tasks/:taskId/trace", (request, response) => data(response, ai.getTaskTrace(request.params.taskId)));
1359
+ app.get("/api/tasks/:taskId/trace/calls/:callId", (request, response) => {
1360
+ const full = parse(z.enum(["true", "false"]).default("false"), request.query.full ?? "false") === "true";
1361
+ data(response, ai.getTaskTraceCall(request.params.taskId, request.params.callId, full));
1362
+ });
1340
1363
  app.post("/api/tasks/:taskId/run", async (request, response) => {
1341
1364
  const input = parse(z.object({ modelId: identifier.optional() }), request.body ?? {});
1342
- data(response, await ai.runTask(request.params.taskId, input.modelId));
1365
+ data(response, redactTaskCharacterNames(await ai.runTask(request.params.taskId, input.modelId), requestPermissions(request)));
1343
1366
  });
1344
- app.post("/api/tasks/:taskId/cancel", (request, response) => data(response, ai.cancelTask(request.params.taskId)));
1367
+ app.post("/api/tasks/:taskId/cancel", (request, response) => data(response, redactTaskCharacterNames(ai.cancelTask(request.params.taskId), requestPermissions(request))));
1345
1368
  app.get("/api/platform/ai/providers", (request, response) => {
1346
1369
  const pagination = parsePagination(request.query);
1347
1370
  data(response, pagination ? ai.listProvidersPage(pagination) : ai.listProviders());