@musnows/scriverse 0.5.11 → 0.6.0

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
@@ -293,8 +293,7 @@ const providerSchema = z.object({
293
293
  status: z.enum(["enabled", "disabled"]).optional(),
294
294
  note: z.string().max(10_000).optional(),
295
295
  concurrencyLimit: z.number().int().min(1).max(100).optional(),
296
- rpmLimit: z.number().int().min(1).max(10_000).optional(),
297
- maxTokens: z.number().int().min(1).max(32_768).optional()
296
+ rpmLimit: z.number().int().min(1).max(10_000).optional()
298
297
  });
299
298
  const modelSchema = z.object({
300
299
  displayName: nonEmpty.max(200),
@@ -373,7 +372,8 @@ const workAiSettingsSchema = z.object({
373
372
  autoRunFailureThreshold: z.number().int().min(1).max(10).optional(),
374
373
  bookSummaryContextPercent: z.number().int().min(1).max(90).optional(),
375
374
  contextCompactThreshold: z.number().int().min(50).max(90).optional(),
376
- agentTools: z.array(z.enum(["story_index", "read_chapters", "grep", "search_story_entities", "read_character_sections", "search_drafts"])).max(6).optional()
375
+ agentTools: z.array(z.enum(["story_index", "read_chapters", "grep", "search_story_entities", "read_character_sections", "search_drafts"])).max(6).optional(),
376
+ titleGenerationModelId: z.string().trim().max(200).optional()
377
377
  }).strict();
378
378
  const contextSchema = z.object({
379
379
  type: z.enum(["none", "selection", "chapter", "volume", "book", "entities"]),
@@ -873,6 +873,10 @@ export function createRuntime(options) {
873
873
  data(response, store.createImportedWork(input, originalFileName, extension.slice(1), parsedNovel), 201);
874
874
  });
875
875
  app.get("/api/works/:workId", (request, response) => {
876
+ if (request.query.directory === "volumes") {
877
+ data(response, store.getWorkVolumeDirectory(request.params.workId));
878
+ return;
879
+ }
876
880
  const pagination = parsePagination(request.query);
877
881
  data(response, pagination ? store.getWorkDirectoryPage(request.params.workId, pagination) : store.getWorkDirectory(request.params.workId));
878
882
  });
@@ -998,6 +1002,12 @@ export function createRuntime(options) {
998
1002
  data(response, store.updateVolume(request.params.volumeId, volumeInput, expectedVersionNo, "manual", null, changeNote));
999
1003
  });
1000
1004
  app.get("/api/volumes/:volumeId", (request, response) => data(response, store.getVolume(request.params.volumeId)));
1005
+ app.get("/api/volumes/:volumeId/chapters", (request, response) => {
1006
+ const pagination = parsePagination(request.query);
1007
+ data(response, pagination
1008
+ ? store.listVolumeChaptersPage(request.params.volumeId, pagination)
1009
+ : store.listVolumeChapters(request.params.volumeId));
1010
+ });
1001
1011
  app.delete("/api/volumes/:volumeId", (request, response) => {
1002
1012
  const input = parse(z.object({ expectedVersionNo: expectedVersionNoSchema }).strict(), request.body ?? {});
1003
1013
  store.deleteVolume(request.params.volumeId, input.expectedVersionNo);
@@ -1660,6 +1670,8 @@ export function createRuntime(options) {
1660
1670
  app.patch("/api/works/:workId/ai-settings", (request, response) => {
1661
1671
  const workId = request.params.workId;
1662
1672
  const input = parse(workAiSettingsSchema, request.body);
1673
+ if (input.titleGenerationModelId)
1674
+ ai.assertModelAvailable(input.titleGenerationModelId);
1663
1675
  const before = store.getWorkAiSettings(workId);
1664
1676
  let updated = store.updateWorkAiSettings(workId, input);
1665
1677
  if (updated.autoRunEnabled) {
@@ -1691,6 +1703,7 @@ export function createRuntime(options) {
1691
1703
  role: z.enum(["user", "assistant"]),
1692
1704
  content: nonEmpty.max(200_000),
1693
1705
  citations: z.array(z.unknown()).max(100).optional(),
1706
+ requestId: identifier.optional(),
1694
1707
  metadata: z.object({
1695
1708
  modelDisplayName: z.string().max(200).optional(),
1696
1709
  outputTokens: z.number().int().min(0).max(10_000_000).optional(),
@@ -1768,6 +1781,7 @@ export function createRuntime(options) {
1768
1781
  data(response, pagination ? ai.listModelsPage(request.params.providerId, pagination) : ai.listModels(request.params.providerId));
1769
1782
  });
1770
1783
  app.post("/api/providers/:providerId/models", (request, response) => data(response, ai.createModel(request.params.providerId, parse(modelSchema, request.body)), 201));
1784
+ app.post("/api/models/:modelId/test", async (request, response) => data(response, await ai.testModel(request.params.modelId)));
1771
1785
  app.get("/api/models/:modelId", (request, response) => data(response, ai.getModel(request.params.modelId)));
1772
1786
  app.patch("/api/models/:modelId", (request, response) => data(response, ai.updateModel(request.params.modelId, parse(modelSchema.partial(), request.body))));
1773
1787
  app.delete("/api/models/:modelId", (request, response) => {
@@ -1856,6 +1870,7 @@ export function createRuntime(options) {
1856
1870
  onProcessStep: (step) => sendEvent("process_step", step),
1857
1871
  conversationId: input.conversationId,
1858
1872
  excludeConversationMessageId: input.currentMessageId,
1873
+ ...(input.currentMessageId ? { assistantMessageRequestId: `assistant:${input.currentMessageId}` } : {}),
1859
1874
  ...(input.modelId ? { modelId: input.modelId } : {}),
1860
1875
  ...(input.parameters ? { parameters: input.parameters } : {})
1861
1876
  }, (delta) => sendEvent("delta", { delta }));
@@ -1868,14 +1883,27 @@ export function createRuntime(options) {
1868
1883
  cacheHitPercent: suggestion.cacheHitPercent,
1869
1884
  chapterVersion: suggestion.chapterVersion,
1870
1885
  toolCalls: suggestion.toolCalls,
1871
- processSteps: suggestion.processSteps
1886
+ processSteps: suggestion.processSteps,
1887
+ conversationTitle: suggestion.conversationTitle,
1888
+ messageId: typeof suggestion.conversationMessage === "object" && suggestion.conversationMessage !== null
1889
+ ? suggestion.conversationMessage.id
1890
+ : undefined,
1891
+ messageCreatedAt: typeof suggestion.conversationMessage === "object" && suggestion.conversationMessage !== null
1892
+ ? suggestion.conversationMessage.createdAt
1893
+ : undefined
1872
1894
  });
1873
1895
  }
1874
1896
  catch (error) {
1875
1897
  if (!controller.signal.aborted) {
1898
+ const details = error instanceof AppError && error.details && typeof error.details === "object" && !Array.isArray(error.details)
1899
+ ? error.details
1900
+ : null;
1876
1901
  sendEvent("error", {
1877
1902
  code: error instanceof AppError ? error.code : "AI_STREAM_FAILED",
1878
- message: error instanceof Error ? error.message : "AI 流式调用失败"
1903
+ message: error instanceof Error ? error.message : "AI 流式调用失败",
1904
+ ...(error instanceof AppError ? { status: error.status } : {}),
1905
+ ...(typeof details?.failure === "string" ? { failure: details.failure } : {}),
1906
+ ...(typeof details?.callId === "string" ? { callId: details.callId } : {})
1879
1907
  });
1880
1908
  }
1881
1909
  }