@musnows/scriverse 0.7.7 → 0.7.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 CHANGED
@@ -3084,7 +3084,9 @@ export class AiManager {
3084
3084
  const effectiveInput = input.taskType === "continue"
3085
3085
  ? { ...input, scope: this.enrichContinuationScope(input.workId, input.scope, input.instruction) }
3086
3086
  : input;
3087
+ const processStartedAt = process.hrtime.bigint();
3087
3088
  const generated = await this.generate(effectiveInput);
3089
+ const processDurationMs = Math.min(86_400_000, Math.max(0, Math.round(Number(process.hrtime.bigint() - processStartedAt) / 1_000_000)));
3088
3090
  const chapter = effectiveInput.scope.chapterId ? this.store.getChapter(effectiveInput.scope.chapterId) : null;
3089
3091
  const suggestionId = id("suggestion");
3090
3092
  this.store.db.run(`INSERT INTO ai_suggestions (id, call_id, work_id, chapter_id, chapter_version, task_type, instruction,
@@ -3094,6 +3096,7 @@ export class AiManager {
3094
3096
  return {
3095
3097
  ...this.getSuggestion(suggestionId),
3096
3098
  outputTokens: generated.outputTokens,
3099
+ processDurationMs,
3097
3100
  ...(generated.cacheHitPercent === undefined ? {} : { cacheHitPercent: generated.cacheHitPercent }),
3098
3101
  toolCalls: generated.toolCalls,
3099
3102
  processSteps: generated.processSteps,
@@ -3115,7 +3118,9 @@ export class AiManager {
3115
3118
  && firstUserContent
3116
3119
  && titleModelId
3117
3120
  && (conversationBefore?.title === "新对话" || conversationBefore?.title === defaultTitle));
3121
+ const processStartedAt = process.hrtime.bigint();
3118
3122
  const generated = await this.generate({ ...input, taskType: "chat" }, onDelta);
3123
+ const processDurationMs = Math.min(86_400_000, Math.max(0, Math.round(Number(process.hrtime.bigint() - processStartedAt) / 1_000_000)));
3119
3124
  const chapter = input.scope.chapterId ? this.store.getChapter(input.scope.chapterId) : null;
3120
3125
  const suggestionId = id("suggestion");
3121
3126
  this.store.db.run(`INSERT INTO ai_suggestions (id, call_id, work_id, chapter_id, chapter_version, task_type, instruction,
@@ -3129,6 +3134,7 @@ export class AiManager {
3129
3134
  metadata: {
3130
3135
  ...(modelDisplayName ? { modelDisplayName } : {}),
3131
3136
  outputTokens: generated.outputTokens,
3137
+ processDurationMs,
3132
3138
  ...(generated.reasoningContent === undefined ? {} : { reasoningContent: generated.reasoningContent }),
3133
3139
  ...(generated.cacheHitPercent === undefined ? {} : { cacheHitPercent: generated.cacheHitPercent }),
3134
3140
  toolCalls: generated.toolCalls,
@@ -3145,6 +3151,7 @@ export class AiManager {
3145
3151
  return {
3146
3152
  ...this.getSuggestion(suggestionId),
3147
3153
  outputTokens: generated.outputTokens,
3154
+ processDurationMs,
3148
3155
  ...(generated.cacheHitPercent === undefined ? {} : { cacheHitPercent: generated.cacheHitPercent }),
3149
3156
  toolCalls: generated.toolCalls,
3150
3157
  processSteps: generated.processSteps,