@musnows/scriverse 1.0.3 → 1.0.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/dist/app.js CHANGED
@@ -1056,7 +1056,7 @@ function redactAiCallContext(record, permissions) {
1056
1056
  const redactedScope = { ...scope };
1057
1057
  let restricted = false;
1058
1058
  if (permissions.prose === "none") {
1059
- for (const field of ["selection", "selectionStart", "selectionEnd", "writingChapterVersion", "chapterId", "volumeId", "chapterIds", "includeBookSummary"]) {
1059
+ for (const field of ["selection", "selectionStart", "selectionEnd", "writingChapterVersion", "chapterId", "volumeId", "chapterIds", "volumeIds", "includeBookSummary"]) {
1060
1060
  if (field in redactedScope) {
1061
1061
  delete redactedScope[field];
1062
1062
  restricted = true;
@@ -1126,6 +1126,10 @@ function redactAiConversationMessage(item, permissions) {
1126
1126
  delete readableMetadata.mentionRaceIds;
1127
1127
  if (permissions.organizations === "none")
1128
1128
  delete readableMetadata.mentionOrganizationIds;
1129
+ if (permissions.settings === "none")
1130
+ delete readableMetadata.mentionSettingIds;
1131
+ if (permissions.settings === "none")
1132
+ delete readableMetadata.mentionContextSettingIds;
1129
1133
  if (Object.keys(readableMetadata).length === Object.keys(metadata).length)
1130
1134
  return item;
1131
1135
  return { ...message, metadata: readableMetadata };
@@ -1207,11 +1211,14 @@ export function publicAiStreamError(error) {
1207
1211
  "monthStartedAt"
1208
1212
  ].filter((key) => details[key] !== undefined).map((key) => [key, details[key]]))
1209
1213
  : undefined;
1214
+ const publicPendingQuestionDetails = error.code === "AI_QUESTION_PENDING" && typeof details?.questionId === "string"
1215
+ ? { questionId: details.questionId }
1216
+ : undefined;
1210
1217
  return {
1211
1218
  code: error.code,
1212
1219
  message: error.message,
1213
1220
  status: error.status,
1214
- ...(publicQuotaDetails ? { details: publicQuotaDetails } : {}),
1221
+ ...(publicQuotaDetails || publicPendingQuestionDetails ? { details: publicQuotaDetails ?? publicPendingQuestionDetails } : {}),
1215
1222
  ...((error.status < 500 || error.code === "AI_CALL_FAILED") && typeof details?.failure === "string" ? { failure: details.failure } : {}),
1216
1223
  ...(typeof details?.callId === "string" ? { callId: details.callId } : {}),
1217
1224
  ...(typeof details?.providerName === "string" ? { providerName: details.providerName } : {}),
@@ -3434,6 +3441,9 @@ export function createRuntime(options) {
3434
3441
  interrupted: z.boolean().optional(),
3435
3442
  interruptionCode: z.string().max(100).optional(),
3436
3443
  interruptionMessage: z.string().max(500).optional(),
3444
+ errorCode: z.string().max(100).optional(),
3445
+ errorStatus: z.number().int().min(100).max(599).optional(),
3446
+ pendingQuestionId: identifier.optional(),
3437
3447
  toolCalls: z.array(aiToolCallResultSchema).max(12).optional(),
3438
3448
  processSteps: z.array(aiProcessStepSchema).max(50).optional()
3439
3449
  }).optional()
@@ -3985,6 +3995,9 @@ export function createRuntime(options) {
3985
3995
  ])];
3986
3996
  const mentionRaceIds = [...new Set(resolvedScope.raceIds ?? [])];
3987
3997
  const mentionOrganizationIds = [...new Set(resolvedScope.organizationIds ?? [])];
3998
+ const mentionSettingIds = [...new Set(resolvedScope.settingIds ?? [])];
3999
+ const mentionChapterIds = [...new Set(resolvedScope.chapterIds ?? [])];
4000
+ const mentionContextSettingIds = resolvedScope.includeSettingInfo === true ? ["include-setting-info"] : [];
3988
4001
  const begun = store.beginAiConversationStreamRequest({
3989
4002
  workId: request.params.workId,
3990
4003
  conversationId,
@@ -3995,11 +4008,14 @@ export function createRuntime(options) {
3995
4008
  content: storedUserContent,
3996
4009
  citations,
3997
4010
  ...(input.currentMessageId ? { existingMessageId: input.currentMessageId } : {}),
3998
- ...((modelId || mentionCharacterIds.length || mentionRaceIds.length || mentionOrganizationIds.length || input.imageAttachmentIds?.length || input.scope.semanticSnapshotId) ? { metadata: {
4011
+ ...((modelId || mentionCharacterIds.length || mentionRaceIds.length || mentionOrganizationIds.length || mentionSettingIds.length || mentionChapterIds.length || mentionContextSettingIds.length || input.imageAttachmentIds?.length || input.scope.semanticSnapshotId) ? { metadata: {
3999
4012
  ...(modelId ? { modelId } : {}),
4000
4013
  ...(mentionCharacterIds.length ? { mentionCharacterIds } : {}),
4001
4014
  ...(mentionRaceIds.length ? { mentionRaceIds } : {}),
4002
4015
  ...(mentionOrganizationIds.length ? { mentionOrganizationIds } : {}),
4016
+ ...(mentionSettingIds.length ? { mentionSettingIds } : {}),
4017
+ ...(mentionChapterIds.length ? { mentionChapterIds } : {}),
4018
+ ...(mentionContextSettingIds.length ? { mentionContextSettingIds } : {}),
4003
4019
  ...(input.scope.semanticSnapshotId ? { semanticSnapshotId: input.scope.semanticSnapshotId } : {}),
4004
4020
  ...(input.imageAttachmentIds?.length ? { chatImageAttachmentIds: [...new Set(input.imageAttachmentIds)] } : {})
4005
4021
  } } : {})
@@ -4058,8 +4074,11 @@ export function createRuntime(options) {
4058
4074
  const currentMessageId = String(begun.userMessage?.id ?? input.currentMessageId ?? "");
4059
4075
  if (begun.userMessage)
4060
4076
  sendEvent("user_message", { message: redactAiConversationMessage(begun.userMessage, permissions) });
4061
- if (aiWritePlanManager.latestPendingQuestion(conversationId)) {
4062
- throw new AppError(409, "AI_QUESTION_PENDING", "当前对话仍有待回答问题,请先回答或拒绝后再继续");
4077
+ const pendingQuestion = aiWritePlanManager.latestPendingQuestion(conversationId);
4078
+ if (pendingQuestion) {
4079
+ throw new AppError(409, "AI_QUESTION_PENDING", "当前对话仍有待回答问题,请先回答或拒绝后再继续", {
4080
+ questionId: pendingQuestion.id
4081
+ });
4063
4082
  }
4064
4083
  const suggestion = await ai.createStreamingChat({
4065
4084
  workId: request.params.workId,