@musnows/scriverse 0.5.11 → 0.5.12

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
@@ -1888,7 +1888,29 @@ export class AiManager {
1888
1888
  const suggestionId = id("suggestion");
1889
1889
  this.store.db.run(`INSERT INTO ai_suggestions (id, call_id, work_id, chapter_id, chapter_version, task_type, instruction,
1890
1890
  source_text, content, action, status, created_at, created_by_user_id) VALUES (?, ?, ?, ?, ?, 'chat', ?, ?, ?, 'note', 'pending', ?, ?)`, suggestionId, generated.callId, input.workId, chapter ? String(chapter.id) : null, chapter ? Number(chapter.versionNo) : null, input.instruction, input.scope.selection ?? "", generated.content, now(), currentRequestActor()?.userId ?? null);
1891
- return { ...this.getSuggestion(suggestionId), outputTokens: generated.outputTokens, ...(generated.cacheHitPercent === undefined ? {} : { cacheHitPercent: generated.cacheHitPercent }), toolCalls: generated.toolCalls, processSteps: generated.processSteps };
1891
+ const modelDisplayName = typeof generated.model.displayName === "string" ? generated.model.displayName : undefined;
1892
+ const conversationMessage = input.conversationId && input.assistantMessageRequestId
1893
+ ? this.store.addAiConversationMessage(input.conversationId, {
1894
+ role: "assistant",
1895
+ content: generated.content,
1896
+ requestId: input.assistantMessageRequestId,
1897
+ metadata: {
1898
+ ...(modelDisplayName ? { modelDisplayName } : {}),
1899
+ outputTokens: generated.outputTokens,
1900
+ ...(generated.cacheHitPercent === undefined ? {} : { cacheHitPercent: generated.cacheHitPercent }),
1901
+ toolCalls: generated.toolCalls,
1902
+ processSteps: generated.processSteps
1903
+ }
1904
+ })
1905
+ : null;
1906
+ return {
1907
+ ...this.getSuggestion(suggestionId),
1908
+ outputTokens: generated.outputTokens,
1909
+ ...(generated.cacheHitPercent === undefined ? {} : { cacheHitPercent: generated.cacheHitPercent }),
1910
+ toolCalls: generated.toolCalls,
1911
+ processSteps: generated.processSteps,
1912
+ ...(conversationMessage ? { conversationMessage } : {})
1913
+ };
1892
1914
  }
1893
1915
  async runSuggestionGuard(suggestionId, candidateContent) {
1894
1916
  const suggestion = this.getSuggestion(suggestionId);